You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2009/02/09 10:21:11 UTC

svn commit: r742346 - in /xmlgraphics/fop/trunk/src/java/org/apache/fop: fonts/SingleByteFont.java render/ps/PSFontUtils.java

Author: jeremias
Date: Mon Feb  9 09:21:09 2009
New Revision: 742346

URL: http://svn.apache.org/viewvc?rev=742346&view=rev
Log:
Bugfix: restored support for characters not in a font's standard encoding when PostScript is generated with resource optimization turned off.

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/SingleByteFont.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSFontUtils.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/SingleByteFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/SingleByteFont.java?rev=742346&r1=742345&r2=742346&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/SingleByteFont.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/SingleByteFont.java Mon Feb  9 09:21:09 2009
@@ -19,8 +19,10 @@
 
 package org.apache.fop.fonts;
 
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -219,6 +221,24 @@
     }
 
     /**
+     * Makes all unencoded characters available through additional encodings. This method
+     * is used in cases where the fonts need to be encoded in the target format before
+     * all text of the document is processed (for example in PostScript when resource optimization
+     * is disabled).
+     */
+    public void encodeAllUnencodedCharacters() {
+        if (this.unencodedCharacters != null) {
+            Set sortedKeys = new java.util.TreeSet(this.unencodedCharacters.keySet());
+            Iterator iter = sortedKeys.iterator();
+            while (iter.hasNext()) {
+                Character ch = (Character)iter.next();
+                char mapped = mapChar(ch.charValue());
+                assert mapped != Typeface.NOT_FOUND;
+            }
+        }
+    }
+
+    /**
      * Indicates whether the encoding has additional encodings besides the primary encoding.
      * @return true if there are additional encodings.
      */

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSFontUtils.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSFontUtils.java?rev=742346&r1=742345&r2=742346&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSFontUtils.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSFontUtils.java Mon Feb  9 09:21:09 2009
@@ -57,7 +57,9 @@
     protected static Log log = LogFactory.getLog(PSFontUtils.class);
 
     /**
-     * Generates the PostScript code for the font dictionary.
+     * Generates the PostScript code for the font dictionary. This method should only be
+     * used if no "resource optimization" is performed, i.e. when the fonts are not embedded
+     * in a second pass.
      * @param gen PostScript generator to use for output
      * @param fontInfo available fonts
      * @return a Map of PSResource instances representing all defined fonts (key: font key)
@@ -65,11 +67,13 @@
      */
     public static Map writeFontDict(PSGenerator gen, FontInfo fontInfo)
                 throws IOException {
-        return writeFontDict(gen, fontInfo, fontInfo.getFonts());
+        return writeFontDict(gen, fontInfo, fontInfo.getFonts(), true);
     }
 
     /**
-     * Generates the PostScript code for the font dictionary.
+     * Generates the PostScript code for the font dictionary. This method assumes all used
+     * fonts and characters are known, i.e. when PostScript is generated with resource
+     * optimization turned on.
      * @param gen PostScript generator to use for output
      * @param fontInfo available fonts
      * @param fonts the set of fonts to work with
@@ -78,6 +82,21 @@
      */
     public static Map writeFontDict(PSGenerator gen, FontInfo fontInfo, Map fonts)
                 throws IOException {
+        return writeFontDict(gen, fontInfo, fonts, false);
+    }
+
+    /**
+     * Generates the PostScript code for the font dictionary.
+     * @param gen PostScript generator to use for output
+     * @param fontInfo available fonts
+     * @param fonts the set of fonts to work with
+     * @param encodeAllCharacters true if all characters shall be encoded using additional,
+     *           generated encodings.
+     * @return a Map of PSResource instances representing all defined fonts (key: font key)
+     * @throws IOException in case of an I/O problem
+     */
+    private static Map writeFontDict(PSGenerator gen, FontInfo fontInfo, Map fonts,
+            boolean encodeAllCharacters) throws IOException {
         gen.commentln("%FOPBeginFontDict");
 
         Map fontResources = new java.util.HashMap();
@@ -91,6 +110,11 @@
 
             if (tf instanceof SingleByteFont) {
                 SingleByteFont sbf = (SingleByteFont)tf;
+
+                if (encodeAllCharacters) {
+                    sbf.encodeAllUnencodedCharacters();
+                }
+
                 for (int i = 0, c = sbf.getAdditionalEncodingCount(); i < c; i++) {
                     SingleByteEncoding encoding = sbf.getAdditionalEncoding(i);
                     defineEncoding(gen, encoding);
@@ -110,6 +134,7 @@
         ResourceTracker tracker = gen.getResourceTracker();
 
         if (!tracker.isResourceSupplied(WINANSI_ENCODING_RESOURCE)) {
+            //Only out Base 14 fonts still use that
             defineWinAnsiEncoding(gen);
         }
         gen.commentln("%FOPBeginFontReencode");



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org