pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1802051 - in /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font: PDType0Font.java TrueTypeEmbedder.java
Date Sun, 16 Jul 2017 12:44:56 GMT
Author: lehmi
Date: Sun Jul 16 12:44:56 2017
New Revision: 1802051

URL: http://svn.apache.org/viewvc?rev=1802051&view=rev
Log:
PDFBOX-3826: don't close the given ttf but the self generated one, move the relevant code
to PDType0Font

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/TrueTypeEmbedder.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java?rev=1802051&r1=1802050&r2=1802051&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java
Sun Jul 16 12:44:56 2017
@@ -51,6 +51,7 @@ public class PDType0Font extends PDFont
     private boolean isDescendantCJK;
     private PDCIDFontType2Embedder embedder;
     private final Set<Integer> noUnicode = new HashSet<Integer>(); 
+    private TrueTypeFont ttf;
     
     /**
     * Loads a TTF to be embedded into a document as a Type 0 font.
@@ -62,7 +63,7 @@ public class PDType0Font extends PDFont
     */
     public static PDType0Font load(PDDocument doc, File file) throws IOException
     {
-        return new PDType0Font(doc, new TTFParser().parse(file), true);
+        return new PDType0Font(doc, new TTFParser().parse(file), true, true);
     }
 
     /**
@@ -75,7 +76,7 @@ public class PDType0Font extends PDFont
     */
     public static PDType0Font load(PDDocument doc, InputStream input) throws IOException
     {
-        return new PDType0Font(doc, new TTFParser().parse(input), true);
+        return new PDType0Font(doc, new TTFParser().parse(input), true, true);
     }
 
     /**
@@ -90,7 +91,7 @@ public class PDType0Font extends PDFont
     public static PDType0Font load(PDDocument doc, InputStream input, boolean embedSubset)
             throws IOException
     {
-        return new PDType0Font(doc, new TTFParser().parse(input), embedSubset);
+        return new PDType0Font(doc, new TTFParser().parse(input), embedSubset, true);
     }
 
     /**
@@ -105,7 +106,7 @@ public class PDType0Font extends PDFont
     public static PDType0Font load(PDDocument doc, TrueTypeFont ttf, boolean embedSubset)
             throws IOException
     {
-        return new PDType0Font(doc, ttf, embedSubset);
+        return new PDType0Font(doc, ttf, embedSubset, false);
     }
 
     /**
@@ -133,13 +134,18 @@ public class PDType0Font extends PDFont
     /**
     * Private. Creates a new TrueType font for embedding.
     */
-    private PDType0Font(PDDocument document, TrueTypeFont ttf, boolean embedSubset)
+    private PDType0Font(PDDocument document, TrueTypeFont ttf, boolean embedSubset,
+            boolean closeOnSubset)
             throws IOException
     {
         embedder = new PDCIDFontType2Embedder(document, dict, ttf, embedSubset, this);
         descendantFont = embedder.getCIDFont();
         readEncoding();
         fetchCMapUCS2();
+        if (closeOnSubset)
+        {
+            this.ttf = ttf;
+        }
     }
 
     @Override
@@ -160,6 +166,11 @@ public class PDType0Font extends PDFont
             throw new IllegalStateException("This font was created with subsetting disabled");
         }
         embedder.subset();
+        if (ttf != null)
+        {
+            ttf.close();
+            ttf = null;
+        }
     }
     
     @Override

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/TrueTypeEmbedder.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/TrueTypeEmbedder.java?rev=1802051&r1=1802050&r2=1802051&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/TrueTypeEmbedder.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/TrueTypeEmbedder.java
Sun Jul 16 12:44:56 2017
@@ -116,11 +116,6 @@ abstract class TrueTypeEmbedder implemen
         try
         {
             input = stream.createInputStream();
-            if (ttf != null)
-            {
-                // close the replaced true type font
-                ttf.close();
-            }
             ttf = new TTFParser().parseEmbedded(input);
             if (!isEmbeddingPermitted(ttf))
             {



Mime
View raw message