pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1611912 - /pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/type1/Type1Lexer.java
Date Sat, 19 Jul 2014 13:26:30 GMT
Author: tilman
Date: Sat Jul 19 13:26:30 2014
New Revision: 1611912

URL: http://svn.apache.org/r1611912
Log:
PDFBOX-2216: skip NUL bytes
PDFBOX-2227: handle radix numbers

Modified:
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/type1/Type1Lexer.java

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/type1/Type1Lexer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/type1/Type1Lexer.java?rev=1611912&r1=1611911&r2=1611912&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/type1/Type1Lexer.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/type1/Type1Lexer.java Sat Jul 19
13:26:30 2014
@@ -21,6 +21,8 @@ package org.apache.fontbox.type1;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * Lexer for the ASCII portions of an Adobe Type 1 font.
@@ -42,7 +44,12 @@ import java.nio.ByteBuffer;
  */
 class Type1Lexer
 {
-    private ByteBuffer buffer;
+    /**
+     * Log instance.
+     */
+    private static final Log LOG = LogFactory.getLog(Type1Lexer.class);
+    
+    private final ByteBuffer buffer;
     private Token aheadToken;
     private int openParens = 0;
 
@@ -53,7 +60,7 @@ class Type1Lexer
      */
     public Type1Lexer(byte[] bytes) throws IOException
     {
-        this.buffer = ByteBuffer.wrap(bytes);
+        buffer = ByteBuffer.wrap(bytes);
         aheadToken = readToken(null);
     }
 
@@ -139,6 +146,11 @@ class Type1Lexer
                 {
                     skip = true;
                 }
+                else if (c == 0)
+                {
+                    LOG.warn("NULL byte in font, skipped");
+                    skip = true;
+                }
                 else
                 {
                     buffer.position(buffer.position() -1);
@@ -185,6 +197,7 @@ class Type1Lexer
         buffer.mark();
 
         StringBuilder sb = new StringBuilder();
+        StringBuilder radix = null;
         char c = getChar();
         boolean hasDigit = false;
 
@@ -209,6 +222,13 @@ class Type1Lexer
             sb.append(c);
             c = getChar();
         }
+        else if (c == '#')
+        {
+            // PostScript radix number takes the form base#number
+            radix = sb;
+            sb = new StringBuilder();
+            c = getChar();
+        }
         else if (sb.length() == 0 || !hasDigit)
         {
             // failure
@@ -268,9 +288,13 @@ class Type1Lexer
                 c = getChar();
             }
         }
-
-        // real
-        buffer.position(buffer.position() -1);
+        
+        buffer.position(buffer.position() - 1);
+        if (radix != null)
+        {
+            Integer val = Integer.parseInt(sb.toString(), Integer.parseInt(radix.toString()));
+            return new Token(val.toString(), Token.INTEGER);
+        }
         return new Token(sb.toString(), Token.REAL);
     }
 



Mime
View raw message