pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1515178 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/font/TTFGlyph2D.java
Date Sun, 18 Aug 2013 17:34:07 GMT
Author: lehmi
Date: Sun Aug 18 17:34:07 2013
New Revision: 1515178

URL: http://svn.apache.org/r1515178
Log:
PDFBOX-1678: apply a toUnicode mapping if present

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/font/TTFGlyph2D.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/font/TTFGlyph2D.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/font/TTFGlyph2D.java?rev=1515178&r1=1515177&r2=1515178&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/font/TTFGlyph2D.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/font/TTFGlyph2D.java Sun
Aug 18 17:34:07 2013
@@ -58,6 +58,7 @@ public class TTFGlyph2D implements Glyph
     private boolean isSymbol = false;
     private HashMap<Integer, GeneralPath> glyphs = new HashMap<Integer, GeneralPath>();
     private CMap toUnicode = null;
+    private int unicodeByteMapping = 1;
     private int[] cid2gid = null;
 
     /**
@@ -104,6 +105,10 @@ public class TTFGlyph2D implements Glyph
         isSymbol = symbolFont;
         name = fontname;
         toUnicode = toUnicodeCMap;
+        if (toUnicode != null && toUnicode.hasTwoByteMappings())
+        {
+            unicodeByteMapping = 2;
+        }
         cid2gid = cid2gidMapping;
         // get units per em, which is used as scaling factor
         HeaderTable header = font.getHeader();
@@ -235,32 +240,32 @@ public class TTFGlyph2D implements Glyph
         }
         else
         {
+            int unicode = code;
+            // map the given code to a valid unicode value, if necessary
+            if (toUnicode != null)
+            {
+                String unicodeStr = toUnicode.lookup(code, unicodeByteMapping);
+                if (unicodeStr != null)
+                {
+                    unicode = unicodeStr.codePointAt(0);
+                }
+            }
             // non symbol fonts
             // Unicode mapping
             if (cmapWinUnicode != null)
             {
-                return getPathForGlyphId(cmapWinUnicode.getGlyphId(code));
+                return getPathForGlyphId(cmapWinUnicode.getGlyphId(unicode));
             }
             // some fonts provide a custom CMap
             if (cmapMiscUnicode != null)
             {
-                int unicode = code;
-                // map the given code to a valid unicode value, if necessary
-                if (toUnicode != null)
-                {
-                    String unicodeStr = toUnicode.lookup(code, 1);
-                    if (unicodeStr != null)
-                    {
-                        unicode = unicodeStr.codePointAt(0);
-                    }
-                }
                 return getPathForGlyphId(cmapMiscUnicode.getGlyphId(unicode));
             }
             // use a mac related mapping
             // Is this possible for non symbol fonts?
             if (cmapMacintoshSymbol != null)
             {
-                return getPathForGlyphId(cmapMacintoshSymbol.getGlyphId(code));
+                return getPathForGlyphId(cmapMacintoshSymbol.getGlyphId(unicode));
             }
         }
         // there isn't any mapping, but probably an optional CID2GID mapping



Mime
View raw message