You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2010/05/02 17:02:22 UTC

svn commit: r940242 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java

Author: lehmi
Date: Sun May  2 15:02:22 2010
New Revision: 940242

URL: http://svn.apache.org/viewvc?rev=940242&view=rev
Log:
PDFBOX-683: improve parser to read the d0 and d1 operator correctly. Patch by Eric Leleu (eric dot leleu at atosorigin dot com)

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java?rev=940242&r1=940241&r2=940242&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java Sun May  2 15:02:22 2010
@@ -369,18 +369,26 @@ public class PDFStreamParser extends Bas
         //average string size is around 2 and the normal string buffer size is
         //about 16 so lets save some space.
         StringBuffer buffer = new StringBuffer(4);
+        int nextChar = (int)pdfSource.peek();
         while(
-            !isWhitespace() &&
-            !isClosing() &&
-            !pdfSource.isEOF() &&
-            pdfSource.peek() != (int)'[' &&
-            pdfSource.peek() != (int)'<' &&
-            pdfSource.peek() != (int)'(' &&
-            pdfSource.peek() != (int)'/' &&
-            (pdfSource.peek() < (int)'0' ||
-             pdfSource.peek() > (int)'9' ) )
+            nextChar != -1 && // EOF
+            !isWhitespace(nextChar) &&
+            !isClosing(nextChar) &&
+            nextChar != (int)'[' &&
+            nextChar != (int)'<' &&
+            nextChar != (int)'(' &&
+            nextChar != (int)'/' &&
+            (nextChar < (int)'0' ||
+             nextChar > (int)'9' ) )
         {
-            buffer.append( (char)pdfSource.read() );
+            char currentChar = (char)pdfSource.read();
+            nextChar = (int)pdfSource.peek();
+            buffer.append( currentChar );
+            // Type3 Glyph description has operators with a number in the name 
+            if (currentChar == 'd' && (nextChar == '0' || nextChar == '1') ) {
+                buffer.append( (char)pdfSource.read() );
+                nextChar = (int)pdfSource.peek();
+            }
         }
         return buffer.toString();
     }