You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ja...@apache.org on 2014/07/01 05:54:51 UTC

svn commit: r1606973 - /pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/Type1CharStringParser.java

Author: jahewson
Date: Tue Jul  1 03:54:51 2014
New Revision: 1606973

URL: http://svn.apache.org/r1606973
Log:
PDFBOX-2170: handle div operator in callothersubr

Modified:
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/Type1CharStringParser.java

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/Type1CharStringParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/Type1CharStringParser.java?rev=1606973&r1=1606972&r2=1606973&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/Type1CharStringParser.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/Type1CharStringParser.java Tue Jul  1 03:54:51 2014
@@ -105,10 +105,11 @@ public class Type1CharStringParser
 
                 // othersubrs 0-3 have their own semantics
                 Stack<Integer> results = new Stack<Integer>();
-                if (othersubrNum == 0) {
-                    results.push((Integer)sequence.remove(sequence.size()-1));
-                    results.push((Integer)sequence.remove(sequence.size()-1));
-                    sequence.remove(sequence.size()-1);
+                if (othersubrNum == 0)
+                {
+                    results.push(removeInteger(sequence));
+                    results.push(removeInteger(sequence));
+                    sequence.remove(sequence.size() - 1);
                     // end flex
                     sequence.add(0);
                     sequence.add(new CharStringCommand(TWO_BYTE, CALLOTHERSUBR));
@@ -122,13 +123,13 @@ public class Type1CharStringParser
                 else if (othersubrNum == 3)
                 {
                     // allows hint replacement
-                    results.push((Integer)sequence.remove(sequence.size()-1));
+                    results.push(removeInteger(sequence));
                 }
                 else
                 {
                     // all remaining othersubrs use this fallback mechanism
                     for (int i = 0; i < numArgs; i++) {
-                        Integer arg = (Integer)sequence.remove(sequence.size()-1);
+                        Integer arg = removeInteger(sequence);
                         results.push(arg);
                     }
                 }
@@ -163,6 +164,33 @@ public class Type1CharStringParser
         return sequence;
     }
 
+    // this method is a workaround for the fact that Type1CharStringParser assumes that subrs and
+    // othersubrs can be unrolled without executing the 'div' operator, which isn't true
+    private Integer removeInteger(List<Object> sequence) throws IOException
+    {
+        Object item = sequence.remove(sequence.size() - 1);
+        if (item instanceof Integer)
+        {
+            return (Integer)item;
+        }
+        else
+        {
+            CharStringCommand command = (CharStringCommand)item;
+
+            // div
+            if (command.getKey().getValue()[0] == 12 && command.getKey().getValue()[0] == 12)
+            {
+                int a = (Integer)sequence.remove(sequence.size() - 1);
+                int b = (Integer)sequence.remove(sequence.size() - 1);
+                return b / a;
+            }
+            else
+            {
+                throw new IOException("Unexpected char string command: " + command.getKey());
+            }
+        }
+    }
+
     private CharStringCommand readCommand(DataInput input, int b0) throws IOException
     {
         if (b0 == 12)