pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1620179 - /pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java
Date Sun, 24 Aug 2014 19:49:46 GMT
Author: jahewson
Date: Sun Aug 24 19:49:46 2014
New Revision: 1620179

URL: http://svn.apache.org/r1620179
Log:
PDFBOX-2262: Cache duplicate fonts in page resources

Modified:
    pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java

Modified: pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java?rev=1620179&r1=1620178&r2=1620179&view=diff
==============================================================================
--- pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java
(original)
+++ pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java
Sun Aug 24 19:49:46 2014
@@ -196,15 +196,26 @@ public class PDResources implements COSO
             }
             else
             {
+                Map<COSDictionary, PDFont> seenFonts = new HashMap<COSDictionary,
PDFont>();
                 for (COSName fontName : fontsDictionary.keySet())
                 {
                     COSBase font = fontsDictionary.getDictionaryObject(fontName);
+
                     // data-000174.pdf contains a font that is a COSArray, looks to be an
error in the
                     // PDF, we will just ignore entries that are not dictionaries.
                     if (font instanceof COSDictionary)
                     {
-                        PDFont newFont = PDFontFactory.createFont((COSDictionary) font);
-                        fonts.put(fontName.getName(), newFont);
+                        // some fonts may appear many times (see test_1fd9a_test.pdf)
+                        if (seenFonts.containsKey(font))
+                        {
+                            fonts.put(fontName.getName(), seenFonts.get(font));
+                        }
+                        else
+                        {
+                            PDFont newFont = PDFontFactory.createFont((COSDictionary) font);
+                            fonts.put(fontName.getName(), newFont);
+                            seenFonts.put((COSDictionary) font, newFont);
+                        }
                     }
                 }
             }



Mime
View raw message