pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1604679 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel: common/PDMemoryStream.java font/PDFont.java font/PDTrueTypeFont.java
Date Mon, 23 Jun 2014 02:14:41 GMT
Author: jahewson
Date: Mon Jun 23 02:14:41 2014
New Revision: 1604679

URL: http://svn.apache.org/r1604679
Log:
PDFBOX-2149: Prevent NPE in system TTF getFontDescriptor()

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDMemoryStream.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDMemoryStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDMemoryStream.java?rev=1604679&r1=1604678&r2=1604679&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDMemoryStream.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDMemoryStream.java
Mon Jun 23 02:14:41 2014
@@ -91,7 +91,7 @@ public class PDMemoryStream extends PDSt
      *
      * @throws IOException If an IO error occurs during reading.
      */
-    public InputStream createInputStream() throws IOException
+    public InputStream createInputStream()
     {
         return new ByteArrayInputStream( data );
     }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java?rev=1604679&r1=1604678&r2=1604679&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java Mon Jun 23
02:14:41 2014
@@ -129,7 +129,7 @@ public abstract class PDFont implements 
 
     private List<Integer> widths = null;
 
-    private PDFontDescriptor fontDescriptor = null;
+    protected PDFontDescriptor fontDescriptor = null;
     private boolean widthsAreMissing = false;
 
     // formerly in PDSimpleFont
@@ -196,7 +196,6 @@ public abstract class PDFont implements 
                 {
                     fontDescriptor = new PDFontDescriptorAFM(afm);
                 }
-                // it shouldn't be possible to reach this point...
             }
         }
         return fontDescriptor;
@@ -692,6 +691,10 @@ public abstract class PDFont implements 
      */
     public boolean isSymbolicFont()
     {
+        if (getFontDescriptor() == null)
+        {
+            return false;
+        }
         return getFontDescriptor().isSymbolic();
     }
 

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java?rev=1604679&r1=1604678&r2=1604679&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java Mon
Jun 23 02:14:41 2014
@@ -93,19 +93,20 @@ public class PDTrueTypeFont extends PDFo
      *
      * @param fontDictionary The font dictionary according to the PDF specification.
      */
-    public PDTrueTypeFont(COSDictionary fontDictionary)
+    public PDTrueTypeFont(COSDictionary fontDictionary)  throws IOException
     {
         super(fontDictionary);
+        getTTFFont(); // load the font file
     }
 
     /**
      * Creates a new TrueType font for embedding.
      */
-    private PDTrueTypeFont(PDDocument document, InputStream ttf) throws IOException
+    private PDTrueTypeFont(PDDocument document, InputStream ttfStream) throws IOException
     {
         dict.setItem(COSName.SUBTYPE, COSName.TRUE_TYPE);
 
-        PDStream stream = new PDStream(document, ttf, false);
+        PDStream stream = new PDStream(document, ttfStream, false);
         stream.getStream().setInt(COSName.LENGTH1, stream.getByteArray().length); // todo:
wrong?
         stream.addCompression();
 
@@ -122,7 +123,8 @@ public class PDTrueTypeFont extends PDFo
         try
         {
             stream2 = stream.createInputStream();
-            fd = getFontDescriptor(new TTFParser().parseTTF(stream2));
+            ttf = new TTFParser().parseTTF(stream2);
+            fd = makeFontDescriptor(ttf);
         }
         finally
         {
@@ -133,8 +135,26 @@ public class PDTrueTypeFont extends PDFo
         dict.setItem(COSName.FONT_DESC, fd);
     }
 
+    @Override
+    public PDFontDescriptor getFontDescriptor()
+    {
+        if (fontDescriptor == null)
+        {
+            COSDictionary fd = (COSDictionary) dict.getDictionaryObject(COSName.FONT_DESC);
+            if (fd != null)
+            {
+                fontDescriptor = new PDFontDescriptorDictionary(fd);
+            }
+            else
+            {
+                fontDescriptor = makeFontDescriptor(ttf);
+            }
+        }
+        return fontDescriptor;
+    }
+
     // creates a new font descriptor dictionary for the given TTF
-    private PDFontDescriptorDictionary getFontDescriptor(TrueTypeFont ttf) throws IOException
+    private PDFontDescriptorDictionary makeFontDescriptor(TrueTypeFont ttf)
     {
         PDFontDescriptorDictionary fd = new PDFontDescriptorDictionary();
 
@@ -334,7 +354,7 @@ public class PDTrueTypeFont extends PDFo
     {
         if (ttf == null)
         {
-            PDFontDescriptorDictionary fd = (PDFontDescriptorDictionary) getFontDescriptor();
+            PDFontDescriptorDictionary fd = (PDFontDescriptorDictionary) super.getFontDescriptor();
             if (fd != null)
             {
                 PDStream ff2Stream = fd.getFontFile2();



Mime
View raw message