pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1763344 - /pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/CmapSubtable.java
Date Wed, 05 Oct 2016 06:54:45 GMT
Author: lehmi
Date: Wed Oct  5 06:54:44 2016
New Revision: 1763344

URL: http://svn.apache.org/viewvc?rev=1763344&view=rev
Log:
PDFBOX-3300: avoid NPE

Modified:
    pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/CmapSubtable.java

Modified: pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/CmapSubtable.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/CmapSubtable.java?rev=1763344&r1=1763343&r2=1763344&view=diff
==============================================================================
--- pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/CmapSubtable.java (original)
+++ pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/CmapSubtable.java Wed
Oct  5 06:54:44 2016
@@ -611,6 +611,10 @@ public class CmapSubtable
     public Integer getCharacterCode(int gid)
     {
         int code = getCharCode(gid);
+        if (code == -1)
+        {
+            return null;
+        }
         // ambiguous mapping, use the first mapping
         if (code == Integer.MIN_VALUE)
         {
@@ -623,21 +627,13 @@ public class CmapSubtable
         return code;
     }
 
-    private Integer getCharCode(int gid)
+    private int getCharCode(int gid)
     {
         if (gid < 0 || gid >= glyphIdToCharacterCode.length)
         {
-            return null;
+            return -1;
         }
-
-        // workaround for the fact that glyphIdToCharacterCode doesn't distinguish between
-        // missing character codes and code 0.
-        int code = glyphIdToCharacterCode[gid];
-        if (code == -1)
-        {
-            return null;
-        }
-        return code;
+        return glyphIdToCharacterCode[gid];
     }
 
     /**
@@ -651,23 +647,24 @@ public class CmapSubtable
     {
         for (int gid = 1; gid <= maxGid; gid++)
         {
+            int codePoint = getCharCode(gid);
             // skip composite glyph components that have no code point
-            Integer codePoint = getCharCode(gid);
-            if (codePoint != null)
+            if (codePoint == -1)
             {
-                if (codePoint > 0)
-                {
-                    gidToUni.put(gid, codePoint); // CID = GID
-                }
-                else if (codePoint == Integer.MIN_VALUE)
+                continue;
+            }
+            if (codePoint == Integer.MIN_VALUE)
+            {
+                List<Integer> mappedValues = glyphIdToCharacterCodeMultiple.get(gid);
+                for (Integer mappedValue : mappedValues)
                 {
-                    List<Integer> mappedValues = glyphIdToCharacterCodeMultiple.get(gid);
-                    for (Integer mappedValue : mappedValues)
-                    {
-                        gidToUni.put(gid, mappedValue); // CID = GID
-                    }
+                    gidToUni.put(gid, mappedValue); // CID = GID
                 }
             }
+            else
+            {
+                gidToUni.put(gid, codePoint); // CID = GID
+            }
         }
     }
 



Mime
View raw message