]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Fixed text extraction problem with ZapfDingbats and Symbol font in PDF output. These...
authorJeremias Maerki <jeremias@apache.org>
Thu, 17 Apr 2008 08:42:52 +0000 (08:42 +0000)
committerJeremias Maerki <jeremias@apache.org>
Thu, 17 Apr 2008 08:42:52 +0000 (08:42 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_95@649006 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/fonts/CustomFont.java
src/java/org/apache/fop/fonts/FontDescriptor.java
src/java/org/apache/fop/fonts/LazyFont.java
src/java/org/apache/fop/pdf/PDFFactory.java
src/java/org/apache/fop/pdf/PDFFont.java
src/java/org/apache/fop/pdf/PDFResources.java
status.xml

index f6bb52cb3a27274e45bc2585efb12debabf689c1..c0b1ca236cf4a3cd634bc71abbeddede86403165 100644 (file)
@@ -190,12 +190,17 @@ public abstract class CustomFont extends Typeface
         return fontBBox;
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     public int getFlags() {
         return flags;
     }
+    
+    /** {@inheritDoc} */
+    public boolean isSymbolicFont() {
+        return ((getFlags() & 4) != 0) || "ZapfDingbatsEncoding".equals(getEncoding());
+        //Note: The check for ZapfDingbats is necessary as the PFM does not reliably indicate
+        //if a font is symbolic.
+    }
 
     /**
      * Returns the font weight (100, 200...800, 900). This value may be different from the
index ffc3ea3f2e171c32f6168a912db8e4b6f267e588..8b3c6e013a06ab8a985303dadd77b9d5ebbd926f 100644 (file)
@@ -53,6 +53,11 @@ public interface FontDescriptor extends FontMetrics {
      */
     int getFlags();
     
+    /**
+     * Indicates whether the font is a symbolic font.
+     * @return true if the font is a symbolic font (i.e. Symbol or ZapfDingbats)
+     */
+    boolean isSymbolicFont();
     
     /**
      * Returns the font's bounding box.
index e6ed7e88107c7d3a09047a515e39c8a532bc16fa..7c0565beeb1d55a518411559d3ab9367137128fe 100644 (file)
@@ -315,14 +315,18 @@ public class LazyFont extends Typeface implements FontDescriptor {
         return realFontDescriptor.getAscender();
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     public int getFlags() {
         load(true);
         return realFontDescriptor.getFlags();
     }
 
+    /** {@inheritDoc} */
+    public boolean isSymbolicFont() {
+        load(true);
+        return realFontDescriptor.isSymbolicFont();
+    }
+
     /**
      * {@inheritDoc}
      */
index 687b320168c8b6c6db7b07fc964bcc8fdbf81172..68f50520bd381a931bcfaca77e67476441647e02 100644 (file)
@@ -1195,10 +1195,11 @@ public class PDFFactory {
 
             PDFFont font = null;
             font = (PDFFont)PDFFont.createFont(fontname, fonttype,
-                                                        basefont, encoding);
+                                                        basefont, null);
             getDocument().registerObject(font);
 
             if (fonttype == FontType.TYPE0) {
+                font.setEncoding(encoding);
                 CIDFont cidMetrics;
                 if (metrics instanceof LazyFont) {
                     cidMetrics = (CIDFont)((LazyFont) metrics).getRealFont();
@@ -1242,7 +1243,9 @@ public class PDFFactory {
                 
                 //Handle encoding
                 CodePointMapping mapping = singleByteFont.getCodePointMapping();
-                if (PDFEncoding.isPredefinedEncoding(mapping.getName())) {
+                if (singleByteFont.isSymbolicFont()) {
+                    //no encoding, use the font's encoding
+                } else if (PDFEncoding.isPredefinedEncoding(mapping.getName())) {
                     font.setEncoding(mapping.getName());
                 } else {
                     CodePointMapping winansi = CodePointMapping.getMapping(
index 14f1a657c902a1be034f81404df058c81dc26b20..1f76f1e1180cf927fcd710b788100997d279dee2 100644 (file)
@@ -62,8 +62,6 @@ public class PDFFont extends PDFDictionary {
             setEncoding((PDFEncoding)encoding);
         } else if (encoding instanceof String) {
             setEncoding((String)encoding);
-        } else {
-            throw new IllegalArgumentException("Illegal value for encoding");
         }
     }
 
index 66ccdc78b72e36764d2f2ba8397494c8da230284..ec371054feec077f8be1729b02d0b56c2e46af17 100644 (file)
@@ -28,6 +28,8 @@ import java.util.Set;
 import org.apache.fop.fonts.FontDescriptor;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.Typeface;
+import org.apache.fop.fonts.base14.Symbol;
+import org.apache.fop.fonts.base14.ZapfDingbats;
 import org.apache.fop.util.ColorProfileUtil;
 
 /**
@@ -109,8 +111,12 @@ public class PDFResources extends PDFObject {
                 if (font instanceof FontDescriptor) {
                     desc = (FontDescriptor)font;
                 }
+                String encoding = font.getEncoding();
+                if (font instanceof Symbol || font instanceof ZapfDingbats) {
+                    encoding = null; //Symbolic fonts shouldn't specify an encoding value in PDF
+                }
                 addFont(doc.getFactory().makeFont(
-                    f, font.getEmbedFontName(), font.getEncoding(), font, desc));
+                    f, font.getEmbedFontName(), encoding, font, desc));
             }
         }
     }
index 48ef3b2d3562041734353a54e0c1d5558bb9f095..4eec2b2e117d4a90285ff3f4a1c3a54aa1e71f28 100644 (file)
@@ -60,6 +60,9 @@
       -->
     <!--/release-->
     <release version="0.95" date="TBD">
+      <action context="Fonts" dev="JM" type="fix">
+        Fixed text extraction problem with ZapfDingbats and Symbol font in PDF output.
+      </action>
       <action context="Fonts" dev="JM" type="fix">
         Fixed NullPointerException when loading a TrueType font using XML font metric files.
       </action>