]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Improved PFM loading:
authorJeremias Maerki <jeremias@apache.org>
Tue, 13 Nov 2007 12:40:38 +0000 (12:40 +0000)
committerJeremias Maerki <jeremias@apache.org>
Tue, 13 Nov 2007 12:40:38 +0000 (12:40 +0000)
- 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

src/java/org/apache/fop/fonts/type1/PFMFile.java
src/java/org/apache/fop/fonts/type1/Type1FontLoader.java

index 490e9da90cfe3673df51de47b0388be618db6e50..c6dd3fb8d40ff01749af4e3b549e9e7ce1c437ee 100644 (file)
@@ -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;
     }
index 336435b33a636aeab60453f10feb10ea8dd67659..63962321c2821e60d8fe28837fa2b34718c30a41 100644 (file)
@@ -56,7 +56,13 @@ public class Type1FontLoader extends FontLoader {
         pfm.load(in);\r
         singleFont = new SingleByteFont();\r
         singleFont.setFontType(FontType.TYPE1);\r
-        singleFont.setEncoding(pfm.getCharSetName() + "Encoding");\r
+        if (pfm.getCharSet() >= 0 && pfm.getCharSet() <= 2) {\r
+            singleFont.setEncoding(pfm.getCharSetName() + "Encoding");\r
+        } else {\r
+            log.warn("The PFM reports an unsupported encoding (" \r
+                    + pfm.getCharSetName() + "). The font may not work as expected.");\r
+            singleFont.setEncoding("WinAnsiEncoding"); //Try fallback, no guarantees!\r
+        }\r
         singleFont.setResolver(this.resolver);\r
         returnFont = singleFont;\r
         returnFont.setFontName(pfm.getPostscriptName());\r
@@ -73,7 +79,7 @@ public class Type1FontLoader extends FontLoader {
         returnFont.setDescender(pfm.getLowerCaseDescent());\r
         returnFont.setFontBBox(pfm.getFontBBox());\r
         returnFont.setFirstChar(pfm.getFirstChar());\r
-        returnFont.setLastChar(pfm.getFirstChar());\r
+        returnFont.setLastChar(pfm.getLastChar());\r
         returnFont.setFlags(pfm.getFlags());\r
         returnFont.setStemV(pfm.getStemV());\r
         returnFont.setItalicAngle(pfm.getItalicAngle());\r