pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1653104 - in /pdfbox/trunk: fontbox/src/main/java/org/apache/fontbox/pfb/PfbParser.java fontbox/src/main/java/org/apache/fontbox/type1/Type1Font.java pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java
Date Mon, 19 Jan 2015 20:18:46 GMT
Author: jahewson
Date: Mon Jan 19 20:18:46 2015
New Revision: 1653104

URL: http://svn.apache.org/r1653104
Log:
PDFBOX-2607: Handle Type1 fonts which embed the entire PFB file.

Modified:
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/pfb/PfbParser.java
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/type1/Type1Font.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/pfb/PfbParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/pfb/PfbParser.java?rev=1653104&r1=1653103&r2=1653104&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/pfb/PfbParser.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/pfb/PfbParser.java Mon Jan 19 20:18:46
2015
@@ -104,6 +104,16 @@ public class PfbParser
     }
 
     /**
+     * Create a new object.
+     * @param bytes   The input.
+     * @throws IOException if an IO-error occurs.
+     */
+    public PfbParser(final byte[] bytes) throws IOException
+    {
+        parsePfb(bytes);
+    }
+
+    /**
      * Parse the pfb-array.
      * @param pfb   The pfb-Array
      * @throws IOException in an IO-error occurs.

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/type1/Type1Font.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/type1/Type1Font.java?rev=1653104&r1=1653103&r2=1653104&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/type1/Type1Font.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/type1/Type1Font.java Mon Jan 19
20:18:46 2015
@@ -57,6 +57,21 @@ public final class Type1Font implements
     }
 
     /**
+     * Constructs a new Type1Font object from a .pfb stream.
+     *
+     * @param pfbBytes .pfb data, including headers
+     * @return a type1 font
+     *
+     * @throws IOException if something went wrong
+     */
+    public static Type1Font createWithPFB(byte[] pfbBytes) throws IOException
+    {
+        PfbParser pfb = new PfbParser(pfbBytes);
+        Type1Parser parser = new Type1Parser();
+        return parser.parse(pfb.getSegment1(), pfb.getSegment2());
+    }
+
+    /**
      * Constructs a new Type1Font object from two header-less .pfb segments.
      *
      * @param segment1 The first segment, without header

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java?rev=1653104&r1=1653103&r2=1653104&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java Mon
Jan 19 20:18:46 2015
@@ -65,6 +65,7 @@ public class PDType1Font extends PDSimpl
         ALT_NAMES.put("ij", "i_j");
         ALT_NAMES.put("ellipsis", "elipsis"); // misspelled in ArialMT
     }
+    private static final int PFB_START_MARKER = 0x80;
 
     // todo: replace with enum? or getters?
     public static final PDType1Font TIMES_ROMAN = new PDType1Font("Times-Roman");
@@ -163,15 +164,23 @@ public class PDType1Font extends PDSimpl
                     // repair Length1 if necessary
                     byte[] bytes = fontFile.getByteArray();
                     length1 = repairLength1(bytes, length1);
-
-                    // the PFB embedded as two segments back-to-back
-                    byte[] segment1 = Arrays.copyOfRange(bytes, 0, length1);
-                    byte[] segment2 = Arrays.copyOfRange(bytes, length1, length1 + length2);
-
-                    // empty streams are simply ignored
-                    if (length1 > 0 && length2 > 0)
+                    
+                    if ((bytes[0] & 0xff) == PFB_START_MARKER)
+                    {
+                        // some bad files embed the entire PFB, see PDFBOX-2607
+                        t1 = Type1Font.createWithPFB(bytes);
+                    }
+                    else
                     {
-                        t1 =  Type1Font.createWithSegments(segment1, segment2);
+                        // the PFB embedded as two segments back-to-back
+                        byte[] segment1 = Arrays.copyOfRange(bytes, 0, length1);
+                        byte[] segment2 = Arrays.copyOfRange(bytes, length1, length1 + length2);
+
+                        // empty streams are simply ignored
+                        if (length1 > 0 && length2 > 0)
+                        {
+                            t1 = Type1Font.createWithSegments(segment1, segment2);
+                        }
                     }
                 }
                 catch (DamagedFontException e)



Mime
View raw message