pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1802055 - in /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font: PDTrueTypeFont.java PDType0Font.java
Date Sun, 16 Jul 2017 13:01:49 GMT
Author: lehmi
Date: Sun Jul 16 13:01:49 2017
New Revision: 1802055

URL: http://svn.apache.org/viewvc?rev=1802055&view=rev
Log:
PDFBOX-3826: close the ttf if the underlying resource is no longer needed, added another load
method using a TrueTypeFont as input

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

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java?rev=1802055&r1=1802054&r2=1802055&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
Sun Jul 16 13:01:49 2017
@@ -90,7 +90,7 @@ public class PDTrueTypeFont extends PDSi
     public static PDTrueTypeFont load(PDDocument doc, File file, Encoding encoding)
             throws IOException
     {
-        return new PDTrueTypeFont(doc, new TTFParser().parse(file), encoding);
+        return new PDTrueTypeFont(doc, new TTFParser().parse(file), encoding, true);
     }
 
     /**
@@ -108,9 +108,29 @@ public class PDTrueTypeFont extends PDSi
     public static PDTrueTypeFont load(PDDocument doc, InputStream input, Encoding encoding)
             throws IOException
     {
-        return new PDTrueTypeFont(doc, new TTFParser().parse(input), encoding);
+        return new PDTrueTypeFont(doc, new TTFParser().parse(input), encoding, true);
     }
-    
+
+    /**
+     * Loads a TTF to be embedded into a document as a simple font.
+     *
+     * <p>
+     * <b>Note:</b> Simple fonts only support 256 characters. For Unicode support,
use
+     * {@link PDType0Font#load(PDDocument, InputStream)} instead.
+     * </p>
+     * 
+     * @param doc The PDF document that will hold the embedded font.
+     * @param ttf A true type font
+     * @param encoding The PostScript encoding vector to be used for embedding.
+     * @return a PDTrueTypeFont instance.
+     * @throws IOException If there is an error loading the data.
+     */
+    public static PDTrueTypeFont load(PDDocument doc, TrueTypeFont ttf, Encoding encoding)
+            throws IOException
+    {
+        return new PDTrueTypeFont(doc, ttf, encoding, false);
+    }
+
     /**
      * Loads a TTF to be embedded into a document as a simple font. Only supports WinAnsiEncoding.
      *
@@ -124,7 +144,7 @@ public class PDTrueTypeFont extends PDSi
     @Deprecated
     public static PDTrueTypeFont loadTTF(PDDocument doc, File file) throws IOException
     {
-        return new PDTrueTypeFont(doc, new TTFParser().parse(file), WinAnsiEncoding.INSTANCE);
+        return new PDTrueTypeFont(doc, new TTFParser().parse(file), WinAnsiEncoding.INSTANCE,
true);
     }
 
     /**
@@ -140,7 +160,8 @@ public class PDTrueTypeFont extends PDSi
     @Deprecated
     public static PDTrueTypeFont loadTTF(PDDocument doc, InputStream input) throws IOException
     {
-        return new PDTrueTypeFont(doc, new TTFParser().parse(input), WinAnsiEncoding.INSTANCE);
+        return new PDTrueTypeFont(doc, new TTFParser().parse(input), WinAnsiEncoding.INSTANCE,
+                true);
     }
 
     private CmapSubtable cmapWinUnicode = null;
@@ -274,7 +295,8 @@ public class PDTrueTypeFont extends PDSi
     /**
      * Creates a new TrueType font for embedding.
      */
-    private PDTrueTypeFont(PDDocument document, TrueTypeFont ttf, Encoding encoding)
+    private PDTrueTypeFont(PDDocument document, TrueTypeFont ttf, Encoding encoding,
+            boolean closeTTF)
             throws IOException
     {
         PDTrueTypeFontEmbedder embedder = new PDTrueTypeFontEmbedder(document, dict, ttf,
@@ -285,6 +307,11 @@ public class PDTrueTypeFont extends PDSi
         isEmbedded = true;
         isDamaged = false;
         glyphList = GlyphList.getAdobeGlyphList();
+        if (closeTTF)
+        {
+            // the TTF is fully loaded and it is save to close the underlying data source
+            ttf.close();
+        }
     }
 
     @Override

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=1802055&r1=1802054&r2=1802055&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 13:01:49 2017
@@ -144,7 +144,15 @@ public class PDType0Font extends PDFont
         fetchCMapUCS2();
         if (closeOnSubset)
         {
-            this.ttf = ttf;
+            if (embedSubset)
+            {
+                this.ttf = ttf;
+            }
+            else
+            {
+                // the TTF is fully loaded and it is save to close the underlying data source
+                ttf.close();
+            }
         }
     }
 



Mime
View raw message