pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1554779 - in /pdfbox/trunk: fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/font/CFFGlyph2D.java
Date Thu, 02 Jan 2014 10:07:11 GMT
Author: lehmi
Date: Thu Jan  2 10:07:10 2014
New Revision: 1554779

URL: http://svn.apache.org/r1554779
Log:
PDFBOX-1824: fixed some glyph mapping issues as proposed by John Hewson

Modified:
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/font/CFFGlyph2D.java

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java?rev=1554779&r1=1554778&r2=1554779&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java Thu Jan  2 10:07:10
2014
@@ -584,7 +584,8 @@ public class CFFParser
         }
         else
         {
-            return CFFStandardString.getName(0);
+        	// technically this maps to .notdef, but we need a unique glyph name
+        	return "SID" + index;
         }
     }
 

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/font/CFFGlyph2D.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/font/CFFGlyph2D.java?rev=1554779&r1=1554778&r2=1554779&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/font/CFFGlyph2D.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/font/CFFGlyph2D.java Thu
Jan  2 10:07:10 2014
@@ -28,6 +28,7 @@ import java.util.Map;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.fontbox.cff.CFFFont;
+import org.apache.fontbox.cff.CFFFontROS;
 import org.apache.fontbox.cff.CharStringRenderer;
 import org.apache.pdfbox.encoding.Encoding;
 
@@ -54,14 +55,30 @@ public class CFFGlyph2D implements Glyph
     public CFFGlyph2D(CFFFont cffFont, Encoding encoding)
     {
         fontname = cffFont.getName();
-        Map<String, Integer> nameToCode = encoding != null ? encoding.getNameToCodeMap()
: null;
         Collection<CFFFont.Mapping> mappings = cffFont.getMappings();
-        Map<Integer, String> codeToNameMap = new LinkedHashMap<Integer, String>();
+        Map<String, Integer> nameToCode = new LinkedHashMap<String, Integer>();
+        // start with CFF built-in encoding        
         for (CFFFont.Mapping mapping : mappings)
         {
-            codeToNameMap.put(mapping.getCode(), mapping.getName());
+        	int code;
+        	if (cffFont instanceof CFFFontROS) 
+        	{
+        		code = mapping.getSID();
+        	}
+        	else 
+        	{
+        		code = mapping.getCode();
+        	}
+        	nameToCode.put(mapping.getName(), code);        
+        }
+        // override with PDF Encoding
+        if (encoding != null) 
+        {
+        	for (Map.Entry<Integer, String> entry : encoding.getCodeToNameMap().entrySet())

+        	{
+        		nameToCode.put(entry.getValue(), entry.getKey());
+        	}
         }
-
         CharStringRenderer renderer = cffFont.createRenderer();
         int glyphId = 0;
         for (CFFFont.Mapping mapping : mappings)
@@ -78,13 +95,7 @@ public class CFFGlyph2D implements Glyph
             if (glyph != null)
             {
                 glyphs.put(glyphId, glyph);
-                int code = mapping.getSID();
-                String name = mapping.getName();
-                if (nameToCode != null && nameToCode.containsKey(name))
-                {
-                    code = nameToCode.get(name);
-                }
-                codeToGlyph.put(code, glyphId);
+                codeToGlyph.put(nameToCode.get(mapping.getName()), glyphId);
                 glyphId++;
             }
         }



Mime
View raw message