From 11bac849bd4ac164c1873d36dd78ab37c8358aeb Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Tue, 13 Nov 2007 12:40:38 +0000 Subject: [PATCH] Improved PFM loading: - Fixed bug with Flags (resulted in bad PDFs for certain fonts) - Warn about possible charset problems. - Fixed bug for "last char" (probably a copy/paste mistake) git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@594512 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/fonts/type1/PFMFile.java | 28 +++++++++++++------ .../fop/fonts/type1/Type1FontLoader.java | 10 +++++-- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/java/org/apache/fop/fonts/type1/PFMFile.java b/src/java/org/apache/fop/fonts/type1/PFMFile.java index 490e9da90..c6dd3fb8d 100644 --- a/src/java/org/apache/fop/fonts/type1/PFMFile.java +++ b/src/java/org/apache/fop/fonts/type1/PFMFile.java @@ -402,6 +402,15 @@ public class PFMFile { return bbox; } + /** + * Indicates whether the font is non-symbolic (Font uses the Adobe standard Latin character + * set or a subset of it). + * @return true if the font is non-symbolic + */ + public boolean isNonSymbolic() { + return (dfCharSet != 2); //!= Symbol fonts + } + /** * Returns the characteristics flags for the font as * needed for a PDF font descriptor (See PDF specs). @@ -411,19 +420,22 @@ public class PFMFile { public int getFlags() { int flags = 0; if (!getIsProportional()) { - flags |= 1; + flags |= 1; //bit 1: FixedPitch } - if ((dfPitchAndFamily & 16) == 16) { - flags |= 2; + if (isNonSymbolic()) { + flags |= 32; //bit 6: Nonsymbolic + } else { + flags |= 4; //bit 3: Symbolic } - if ((dfPitchAndFamily & 64) == 64) { - flags |= 4; + //int serif = dfPitchAndFamily & 0xFFFE; + if ((dfPitchAndFamily & 16) != 0) { + flags |= 2; //bit 2: Serif } - if (dfCharSet == 0) { - flags |= 6; + if ((dfPitchAndFamily & 64) != 0) { + flags |= 8; //bit 4: Script } if (dfItalic != 0) { - flags |= 7; + flags |= 64; //bit 7: Italic } return flags; } diff --git a/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java b/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java index 336435b33..63962321c 100644 --- a/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java +++ b/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java @@ -56,7 +56,13 @@ public class Type1FontLoader extends FontLoader { pfm.load(in); singleFont = new SingleByteFont(); singleFont.setFontType(FontType.TYPE1); - singleFont.setEncoding(pfm.getCharSetName() + "Encoding"); + if (pfm.getCharSet() >= 0 && pfm.getCharSet() <= 2) { + singleFont.setEncoding(pfm.getCharSetName() + "Encoding"); + } else { + log.warn("The PFM reports an unsupported encoding (" + + pfm.getCharSetName() + "). The font may not work as expected."); + singleFont.setEncoding("WinAnsiEncoding"); //Try fallback, no guarantees! + } singleFont.setResolver(this.resolver); returnFont = singleFont; returnFont.setFontName(pfm.getPostscriptName()); @@ -73,7 +79,7 @@ public class Type1FontLoader extends FontLoader { returnFont.setDescender(pfm.getLowerCaseDescent()); returnFont.setFontBBox(pfm.getFontBBox()); returnFont.setFirstChar(pfm.getFirstChar()); - returnFont.setLastChar(pfm.getFirstChar()); + returnFont.setLastChar(pfm.getLastChar()); returnFont.setFlags(pfm.getFlags()); returnFont.setStemV(pfm.getStemV()); returnFont.setItalicAngle(pfm.getItalicAngle()); -- 2.39.5