diff --git a/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/FontDescriptor.java b/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/FontDescriptor.java index 08046b34d..e18252644 100644 --- a/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/FontDescriptor.java +++ b/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/FontDescriptor.java @@ -66,6 +66,8 @@ public class FontDescriptor extends Dictionary { public static final Name FONT_FILE_3_CID_FONT_TYPE_0C = new Name("CIDFontType0C"); public static final Name FONT_FILE_3_OPEN_TYPE = new Name("OpenType"); + private boolean embeddedFontDamaged; + /** * Creates a new instance of a FontDescriptor. * @@ -215,6 +217,10 @@ public FontFile getEmbeddedFont() { return font; } + public boolean isEmbeddedFontDamaged() { + return embeddedFontDamaged; + } + /** * Gets the fonts bounding box. * @@ -311,6 +317,7 @@ public synchronized void init(Name subtype) { // occurs. catch (Throwable e) { logger.log(Level.FINE, "Error Reading Embedded Font ", e); + embeddedFontDamaged = true; } inited = true; diff --git a/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/FontFile.java b/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/FontFile.java index 9c1bfa139..9d35cffbc 100644 --- a/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/FontFile.java +++ b/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/FontFile.java @@ -40,6 +40,8 @@ enum ByteEncoding { long LAYOUT_NONE = 0; + // todo do some refacotring of method name 'e' awlays seemed strange to me. + Point2D echarAdvance(char ech); FontFile deriveFont(AffineTransform at); diff --git a/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/Type3Font.java b/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/Type3Font.java index e6d495be5..1f9739acb 100644 --- a/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/Type3Font.java +++ b/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/Type3Font.java @@ -25,6 +25,6 @@ public void init() { font = new ZFontType3(library, entries); ((ZFontType3) font).setParentResource(parentResource); super.init(); - inited = inited; + inited = true; } } diff --git a/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/TypeCidType2Font.java b/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/TypeCidType2Font.java index 6b4370eab..2d9d4b46a 100644 --- a/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/TypeCidType2Font.java +++ b/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/TypeCidType2Font.java @@ -44,7 +44,7 @@ protected void parseCidToGidMap() { Object gidMap = library.getObject(entries, CID_TO_GID_MAP_KEY); // ordering != null && ordering.startsWith("Identity")) || ((gidMap != null || !isFontSubstitution) - if (true) { + if (!isFontSubstitution) { // CMap subfontToUnicodeCMap = toUnicodeCMap != null ? toUnicodeCMap : CMap.IDENTITY; if (gidMap == null) { // throw new Exception("null CID_TO_GID_MAP_KEY " + gidMap); diff --git a/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontOpenType.java b/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontOpenType.java index f81fe97f8..9eb6fbe27 100644 --- a/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontOpenType.java +++ b/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontOpenType.java @@ -31,17 +31,14 @@ public ZFontOpenType(byte[] fontBytes) throws Exception { OpenTypeFont openTypeFont = otfParser.parse(new ByteArrayInputStream(fontBytes)); trueTypeFont = openTypeFont; fontBoxFont = trueTypeFont; - if (openTypeFont.isPostScript()) { -// fontIsDamaged = true; -// logger.warning("Found CFF/OTF but expected embedded TTF font " + fd.getFontName()); + isDamaged = true; + logger.warning("Found CFF/OTF but expected embedded TTF font " + trueTypeFont.getName()); } - extractCmapTable(); } } catch (Throwable e) { logger.log(Level.WARNING, "Error reading font file with ", e); -// fontIsDamaged = true; throw new Exception(e); } } @@ -57,11 +54,9 @@ public void drawEstring(Graphics2D g, String estr, float x, float y, long layout if (glyphData == null) { outline = new GeneralPath(); } else { - // must scaled by caller using FontMatrix outline = glyphData.getPath(); } - // clean up, not very efficient g.translate(x, y); g.transform(this.fontTransform); diff --git a/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontTrueType.java b/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontTrueType.java index 7e230188c..fe9ba1523 100644 --- a/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontTrueType.java +++ b/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontTrueType.java @@ -21,7 +21,7 @@ import java.util.logging.Level; import java.util.logging.Logger; -public class ZFontTrueType extends ZSimpleFont { +public class ZFontTrueType extends ZSimpleFont implements Cloneable { private static final Logger logger = Logger.getLogger(ZFontTrueType.class.toString()); @@ -60,7 +60,6 @@ public ZFontTrueType(byte[] fontBytes) throws Exception { } } catch (Throwable e) { logger.log(Level.WARNING, "Error reading font file with ", e); -// fontIsDamaged = true; throw new Exception(e); } } @@ -77,7 +76,6 @@ protected ZFontTrueType(ZFontTrueType font) { @Override public Point2D echarAdvance(char ech) { - // todo need to work with the gid..... if (encoding != null) { return super.echarAdvance(ech); } else if (widths != null) { @@ -111,9 +109,6 @@ public void drawEstring(Graphics2D g, String estr, float x, float y, long layout outline = glyphData.getPath(); } } - - - // clean up, not very efficient g.translate(x, y); g.transform(this.fontTransform); diff --git a/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontType0.java b/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontType0.java index 1f85a51ad..e0aa1b309 100644 --- a/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontType0.java +++ b/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontType0.java @@ -22,27 +22,22 @@ public class ZFontType0 extends ZSimpleFont { private static final Logger logger = Logger.getLogger(ZFontType0.class.toString()); - // todo shout out to PDFbox. private CFFCIDFont cidFont; // Top DICT that uses CIDFont operators private FontBoxFont t1Font; // Top DICT that does not use CIDFont operators - // todo credit pdfbox for stream correction code public ZFontType0(Stream fontStream) throws Exception { byte[] fontBytes = fontStream.getDecodedStreamBytes(); CFFFont cffFont = null; if (fontBytes != null && fontBytes.length > 0 && (fontBytes[0] & 0xff) == '%') { - // todo throw exception so substitution kicks in? still not too sure what to do here for fallback logger.warning("Found PFB but expected embedded CFF font"); -// fontIsDamaged = true; + isDamaged = true; } else if (fontBytes != null) { CFFParser cffParser = new CFFParser(); try { cffFont = cffParser.parse(fontBytes, new FF3ByteSource(fontStream)).get(0); } catch (IOException e) { - // todo throw exception so substitution kicks in. logger.log(Level.WARNING, "Can't read the embedded CFF font ", e); -// fontIsDamaged = true; throw new Exception(e); } } diff --git a/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontType1.java b/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontType1.java index c45380682..f6f45a1bc 100644 --- a/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontType1.java +++ b/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontType1.java @@ -62,7 +62,6 @@ public ZFontType1(Stream fontStream) throws Exception { public ZFontType1(URL url) throws IOException { byte[] fontBytes = url.openStream().readAllBytes(); source = url; - // todo clean up error handling type1Font = Type1Font.createWithPFB(fontBytes); } diff --git a/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontType1C.java b/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontType1C.java index 0472c2dda..8ea802268 100644 --- a/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontType1C.java +++ b/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontType1C.java @@ -24,21 +24,15 @@ public class ZFontType1C extends ZSimpleFont { private CFFType1Font cffType1Font; public ZFontType1C(Stream fontStream) throws Exception { + byte[] fontBytes = fontStream.getDecodedStreamBytes(); try { - byte[] fontBytes = fontStream.getDecodedStreamBytes(); - try { - if (fontBytes != null) { - // note: this could be an OpenType file, fortunately CFFParser can handle that - CFFParser cffParser = new CFFParser(); - cffType1Font = (CFFType1Font) cffParser.parse(fontBytes, new FontFileByteSource(fontStream)).get(0); - } - fontBoxFont = cffType1Font; - } catch (IOException e) { - logger.log(Level.FINE, "Error reading font file with ", e); -// fontIsDamaged = true; + if (fontBytes != null) { + // note: this could be an OpenType file, fortunately CFFParser can handle that + CFFParser cffParser = new CFFParser(); + cffType1Font = (CFFType1Font) cffParser.parse(fontBytes, new FontFileByteSource(fontStream)).get(0); } - - } catch (Throwable e) { + fontBoxFont = cffType1Font; + } catch (IOException e) { logger.log(Level.FINE, "Error reading font file with ", e); throw new Exception(e); } diff --git a/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontType2.java b/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontType2.java index d6a35e567..91674bb76 100644 --- a/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontType2.java +++ b/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontType2.java @@ -30,26 +30,19 @@ public class ZFontType2 extends ZSimpleFont { //extends ZFontTrueType { private CMap cid2gid; - // todo credit pdfbox public ZFontType2(Stream fontStream) throws Exception { try { byte[] fontBytes = fontStream.getDecodedStreamBytes(); // embedded OTF or TTF OTFParser otfParser = new OTFParser(true); - OpenTypeFont otf = otfParser.parse(new ByteArrayInputStream(fontBytes)); - trueTypeFont = otf; - + OpenTypeFont openTypeFont = otfParser.parse(new ByteArrayInputStream(fontBytes)); + trueTypeFont = openTypeFont; + if (openTypeFont.isPostScript()) { + isDamaged = true; + logger.warning("Found CFF/OTF but expected embedded TTF font " + trueTypeFont.getName()); + } // extractCmapTable(); - -// if (otf.isPostScript()) -// { -// // PDFBOX-3344 contains PostScript outlines instead of TrueType -// fontIsDamaged = true; -// LOG.warn("Found CFF/OTF but expected embedded TTF font " + fd.getFontName()); -// } } catch (Throwable e) { -// // NPE due to TTF parser being buggy -// fontIsDamaged = true; logger.log(Level.SEVERE, "Could not initialize type2 font", e); throw new Exception(e); } diff --git a/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontType3.java b/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontType3.java index db0ffe443..c47d0ca4f 100644 --- a/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontType3.java +++ b/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZFontType3.java @@ -85,8 +85,7 @@ public ZFontType3(Library library, HashMap properties) { fontMatrix = new AffineTransform(0.001f, 0.0f, 0.0f, 0.001f, 0.0f, 0.0f); } - // todo fix up all simple font unicode assignments - toUnicode = null;//CMap.IDENTITY; + toUnicode = org.icepdf.core.pobjects.fonts.ofont.CMap.IDENTITY; // CharProcs resources, contains glyph name/stream pairs. o = library.getObject(properties, CHAR_PROCS_KEY); diff --git a/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZSimpleFont.java b/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZSimpleFont.java index ff65aab6c..c95490535 100644 --- a/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZSimpleFont.java +++ b/core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/zfont/fontFiles/ZSimpleFont.java @@ -58,7 +58,7 @@ public abstract class ZSimpleFont implements FontFile { protected AffineTransform fontTransform = new AffineTransform(); protected AffineTransform gsTransform = new AffineTransform(); - // todo fontDamaged flags + protected boolean isDamaged; protected ZSimpleFont() { @@ -249,6 +249,10 @@ public void setIsCid() { } + public boolean isDamaged() { + return isDamaged; + } + protected void setFontTransform(AffineTransform at) { gsTransform = new AffineTransform(at); fontTransform = new AffineTransform(fontMatrix);