pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1798363 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/TrueTypeEmbedder.java
Date Sun, 11 Jun 2017 13:05:03 GMT
Author: tilman
Date: Sun Jun 11 13:05:03 2017
New Revision: 1798363

URL: http://svn.apache.org/viewvc?rev=1798363&view=rev
Log:
PDFBOX-3824: get the length of a ttf datastream without decoding it; use JDK7 syntax

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/TrueTypeEmbedder.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/TrueTypeEmbedder.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/TrueTypeEmbedder.java?rev=1798363&r1=1798362&r2=1798363&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/TrueTypeEmbedder.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/TrueTypeEmbedder.java
Sun Jun 11 13:05:03 2017
@@ -37,7 +37,6 @@ import org.apache.fontbox.ttf.TTFSubsett
 import org.apache.fontbox.ttf.TrueTypeFont;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.common.PDStream;
@@ -110,16 +109,13 @@ abstract class TrueTypeEmbedder implemen
     public final void buildFontFile2(InputStream ttfStream) throws IOException
     {
         PDStream stream = new PDStream(document, ttfStream, COSName.FLATE_DECODE);
-        stream.getCOSObject().setInt(COSName.LENGTH1, stream.toByteArray().length);
 
         // as the stream was closed within the PDStream constructor, we have to recreate
it
-        InputStream input = null;
-        try
+        try (InputStream input = stream.createInputStream())
         {
-            input = stream.createInputStream();
             if (ttf != null)
             {
-                // close the replaced true type font
+                // close the replaced TrueType font
                 ttf.close();
             }
             ttf = new TTFParser().parseEmbedded(input);
@@ -132,11 +128,7 @@ abstract class TrueTypeEmbedder implemen
                 fontDescriptor = createFontDescriptor(ttf);
             }
         }
-        finally
-        {
-            IOUtils.closeQuietly(input);
-        }
-
+        stream.getCOSObject().setLong(COSName.LENGTH1, ttf.getOriginalDataSize());
         fontDescriptor.setFontFile2(stream);
     }
 



Mime
View raw message