From 2b8664d398230b59634d16ecd77b8c78ecc4a1e2 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Thu, 17 Apr 2008 08:42:52 +0000 Subject: [PATCH] Fixed text extraction problem with ZapfDingbats and Symbol font in PDF output. These fonts are symbolic and must not use an Encoding value in PDF. Applies to the built-in base 14 variant and to the case where these fonts are explicitely embedded. 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 | 11 ++++++++--- src/java/org/apache/fop/fonts/FontDescriptor.java | 5 +++++ src/java/org/apache/fop/fonts/LazyFont.java | 10 +++++++--- src/java/org/apache/fop/pdf/PDFFactory.java | 7 +++++-- src/java/org/apache/fop/pdf/PDFFont.java | 2 -- src/java/org/apache/fop/pdf/PDFResources.java | 8 +++++++- status.xml | 3 +++ 7 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/java/org/apache/fop/fonts/CustomFont.java b/src/java/org/apache/fop/fonts/CustomFont.java index f6bb52cb3..c0b1ca236 100644 --- a/src/java/org/apache/fop/fonts/CustomFont.java +++ b/src/java/org/apache/fop/fonts/CustomFont.java @@ -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 diff --git a/src/java/org/apache/fop/fonts/FontDescriptor.java b/src/java/org/apache/fop/fonts/FontDescriptor.java index ffc3ea3f2..8b3c6e013 100644 --- a/src/java/org/apache/fop/fonts/FontDescriptor.java +++ b/src/java/org/apache/fop/fonts/FontDescriptor.java @@ -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. diff --git a/src/java/org/apache/fop/fonts/LazyFont.java b/src/java/org/apache/fop/fonts/LazyFont.java index e6ed7e881..7c0565bee 100644 --- a/src/java/org/apache/fop/fonts/LazyFont.java +++ b/src/java/org/apache/fop/fonts/LazyFont.java @@ -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} */ diff --git a/src/java/org/apache/fop/pdf/PDFFactory.java b/src/java/org/apache/fop/pdf/PDFFactory.java index 687b32016..68f50520b 100644 --- a/src/java/org/apache/fop/pdf/PDFFactory.java +++ b/src/java/org/apache/fop/pdf/PDFFactory.java @@ -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( diff --git a/src/java/org/apache/fop/pdf/PDFFont.java b/src/java/org/apache/fop/pdf/PDFFont.java index 14f1a657c..1f76f1e11 100644 --- a/src/java/org/apache/fop/pdf/PDFFont.java +++ b/src/java/org/apache/fop/pdf/PDFFont.java @@ -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"); } } diff --git a/src/java/org/apache/fop/pdf/PDFResources.java b/src/java/org/apache/fop/pdf/PDFResources.java index 66ccdc78b..ec371054f 100644 --- a/src/java/org/apache/fop/pdf/PDFResources.java +++ b/src/java/org/apache/fop/pdf/PDFResources.java @@ -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)); } } } diff --git a/status.xml b/status.xml index 48ef3b2d3..4eec2b2e1 100644 --- a/status.xml +++ b/status.xml @@ -60,6 +60,9 @@ --> + + Fixed text extraction problem with ZapfDingbats and Symbol font in PDF output. + Fixed NullPointerException when loading a TrueType font using XML font metric files. -- 2.39.5