pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1791812 - in /pdfbox/trunk/fontbox/src: main/java/org/apache/fontbox/ttf/TTFSubsetter.java test/java/org/apache/fontbox/ttf/TTFSubsetterTest.java
Date Tue, 18 Apr 2017 16:36:07 GMT
Author: tilman
Date: Tue Apr 18 16:36:07 2017
New Revision: 1791812

URL: http://svn.apache.org/viewvc?rev=1791812&view=rev
Log:
PDFBOX-2852: use JDK7 syntax

Modified:
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TTFSubsetter.java
    pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/TTFSubsetterTest.java

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TTFSubsetter.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TTFSubsetter.java?rev=1791812&r1=1791811&r2=1791812&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TTFSubsetter.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TTFSubsetter.java Tue Apr 18
16:36:07 2017
@@ -95,6 +95,8 @@ public final class TTFSubsetter
 
     /**
      * Sets the prefix to add to the font's PostScript name.
+     *
+     * @param prefix
      */
     public void setPrefix(String prefix)
     {
@@ -562,8 +564,7 @@ public final class TTFSubsetter
 
         GlyphTable g = ttf.getGlyph();
         long[] offsets = ttf.getIndexToLocation().getOffsets();
-        InputStream is = ttf.getOriginalData();
-        try
+        try (InputStream is = ttf.getOriginalData())
         {
             is.skip(g.getOffset());
 
@@ -672,10 +673,6 @@ public final class TTFSubsetter
             }
             newOffsets[newGid++] = newOffset;
         }
-        finally
-        {
-            is.close();
-        }
 
         return bos.toByteArray();
     }
@@ -957,8 +954,7 @@ public final class TTFSubsetter
         
         addCompoundReferences();
 
-        DataOutputStream out = new DataOutputStream(os);
-        try 
+        try (DataOutputStream out = new DataOutputStream(os))
         {
             long[] newLoca = new long[glyphIds.size() + 1];
 
@@ -1037,10 +1033,6 @@ public final class TTFSubsetter
                 writeTableBody(out, bytes);
             }
         }
-        finally 
-        {
-            out.close();
-        }
     }
 
     private void writeFixed(DataOutputStream out, double f) throws IOException

Modified: pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/TTFSubsetterTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/TTFSubsetterTest.java?rev=1791812&r1=1791811&r2=1791812&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/TTFSubsetterTest.java (original)
+++ pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/TTFSubsetterTest.java Tue Apr
18 16:36:07 2017
@@ -23,7 +23,6 @@ import java.io.InputStream;
 import java.net.URI;
 import java.net.URL;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 import java.util.Map.Entry;
 import org.apache.fontbox.util.autodetect.FontFileFinder;
@@ -55,11 +54,12 @@ public class TTFSubsetterTest
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ttfSubsetter.writeToStream(baos);
-        TrueTypeFont subset = new TTFParser(true).parse(new ByteArrayInputStream(baos.toByteArray()));
-        assertEquals(1, subset.getNumberOfGlyphs());
-        assertEquals(0, subset.nameToGID(".notdef"));
-        assertNotNull(subset.getGlyph().getGlyph(0));
-        subset.close();
+        try (TrueTypeFont subset = new TTFParser(true).parse(new ByteArrayInputStream(baos.toByteArray())))
+        {
+            assertEquals(1, subset.getNumberOfGlyphs());
+            assertEquals(0, subset.nameToGID(".notdef"));
+            assertNotNull(subset.getGlyph().getGlyph(0));
+        }
     }
 
     /**
@@ -88,11 +88,12 @@ public class TTFSubsetterTest
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ttfSubsetter.writeToStream(baos);
-        TrueTypeFont subset = new TTFParser(true).parse(new ByteArrayInputStream(baos.toByteArray()));
-        assertEquals(1, subset.getNumberOfGlyphs());
-        assertEquals(0, subset.nameToGID(".notdef"));
-        assertNotNull(subset.getGlyph().getGlyph(0));
-        subset.close();
+        try (TrueTypeFont subset = new TTFParser(true).parse(new ByteArrayInputStream(baos.toByteArray())))
+        {
+            assertEquals(1, subset.getNumberOfGlyphs());
+            assertEquals(0, subset.nameToGID(".notdef"));
+            assertNotNull(subset.getGlyph().getGlyph(0));
+        }
     }
 
     /**
@@ -109,18 +110,19 @@ public class TTFSubsetterTest
         ttfSubsetter.add('a');
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ttfSubsetter.writeToStream(baos);
-        TrueTypeFont subset = new TTFParser(true).parse(new ByteArrayInputStream(baos.toByteArray()));
-        assertEquals(2, subset.getNumberOfGlyphs());
-        assertEquals(0, subset.nameToGID(".notdef"));
-        assertEquals(1, subset.nameToGID("a"));
-        assertNotNull(subset.getGlyph().getGlyph(0));
-        assertNotNull(subset.getGlyph().getGlyph(1));
-        assertNull(subset.getGlyph().getGlyph(2));
-        assertEquals(full.getAdvanceWidth(full.nameToGID("a")), 
-                   subset.getAdvanceWidth(subset.nameToGID("a")));
-        assertEquals(full.getHorizontalMetrics().getLeftSideBearing(full.nameToGID("a")),

-                   subset.getHorizontalMetrics().getLeftSideBearing(subset.nameToGID("a")));
-        subset.close();
+        try (TrueTypeFont subset = new TTFParser(true).parse(new ByteArrayInputStream(baos.toByteArray())))
+        {
+            assertEquals(2, subset.getNumberOfGlyphs());
+            assertEquals(0, subset.nameToGID(".notdef"));
+            assertEquals(1, subset.nameToGID("a"));
+            assertNotNull(subset.getGlyph().getGlyph(0));
+            assertNotNull(subset.getGlyph().getGlyph(1));
+            assertNull(subset.getGlyph().getGlyph(2));
+            assertEquals(full.getAdvanceWidth(full.nameToGID("a")),
+                    subset.getAdvanceWidth(subset.nameToGID("a")));
+            assertEquals(full.getHorizontalMetrics().getLeftSideBearing(full.nameToGID("a")),
+                    subset.getHorizontalMetrics().getLeftSideBearing(subset.nameToGID("a")));
+        }
     }
 
     /**
@@ -177,18 +179,19 @@ public class TTFSubsetterTest
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ttfSubsetter.writeToStream(baos);
-        TrueTypeFont subset = new TTFParser(true).parse(new ByteArrayInputStream(baos.toByteArray()));
-        assertEquals(6, subset.getNumberOfGlyphs());
-
-        for (Entry<Integer, Integer> entry : ttfSubsetter.getGIDMap().entrySet())
+        try (TrueTypeFont subset = new TTFParser(true).parse(new ByteArrayInputStream(baos.toByteArray())))
         {
-            Integer newGID = entry.getKey();
-            Integer oldGID = entry.getValue();
-            assertEquals(full.getAdvanceWidth(oldGID), subset.getAdvanceWidth(newGID));
-            assertEquals(full.getHorizontalMetrics().getLeftSideBearing(oldGID), 
-                       subset.getHorizontalMetrics().getLeftSideBearing(newGID));
+            assertEquals(6, subset.getNumberOfGlyphs());
+
+            for (Entry<Integer, Integer> entry : ttfSubsetter.getGIDMap().entrySet())
+            {
+                Integer newGID = entry.getKey();
+                Integer oldGID = entry.getValue();
+                assertEquals(full.getAdvanceWidth(oldGID), subset.getAdvanceWidth(newGID));
+                assertEquals(full.getHorizontalMetrics().getLeftSideBearing(oldGID),
+                        subset.getHorizontalMetrics().getLeftSideBearing(newGID));
+            }
         }
-        subset.close();
     }
 
     /**
@@ -219,21 +222,22 @@ public class TTFSubsetterTest
         ttfSubsetter.add('B');
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ttfSubsetter.writeToStream(baos);
-        TrueTypeFont subset = new TTFParser().parse(new ByteArrayInputStream(baos.toByteArray()));
-        assertEquals(4, subset.getNumberOfGlyphs());
-        assertEquals(0, subset.nameToGID(".notdef"));
-        assertEquals(1, subset.nameToGID("space"));
-        assertEquals(2, subset.nameToGID("A"));
-        assertEquals(3, subset.nameToGID("B"));
-        String [] names = new String[]{"A","B","space"};
-        for (String name : names)
-        {
-            assertEquals(full.getAdvanceWidth(full.nameToGID(name)), 
-                       subset.getAdvanceWidth(subset.nameToGID(name)));
-            assertEquals(full.getHorizontalMetrics().getLeftSideBearing(full.nameToGID(name)),

-                       subset.getHorizontalMetrics().getLeftSideBearing(subset.nameToGID(name)));
-        }        
-        subset.close();
+        try (TrueTypeFont subset = new TTFParser().parse(new ByteArrayInputStream(baos.toByteArray())))
+        {
+            assertEquals(4, subset.getNumberOfGlyphs());
+            assertEquals(0, subset.nameToGID(".notdef"));
+            assertEquals(1, subset.nameToGID("space"));
+            assertEquals(2, subset.nameToGID("A"));
+            assertEquals(3, subset.nameToGID("B"));
+            String [] names = new String[]{"A","B","space"};
+            for (String name : names)
+            {
+                assertEquals(full.getAdvanceWidth(full.nameToGID(name)),
+                        subset.getAdvanceWidth(subset.nameToGID(name)));
+                assertEquals(full.getHorizontalMetrics().getLeftSideBearing(full.nameToGID(name)),
+                        subset.getHorizontalMetrics().getLeftSideBearing(subset.nameToGID(name)));
+            }
+        }
     }
     
     /**



Mime
View raw message