pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1739952 - /pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/TTFSubsetter.java
Date Tue, 19 Apr 2016 16:02:02 GMT
Author: tilman
Date: Tue Apr 19 16:02:02 2016
New Revision: 1739952

URL: http://svn.apache.org/viewvc?rev=1739952&view=rev
Log:
PDFBOX-3319: correct handling of partially monospaced fonts

Modified:
    pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/TTFSubsetter.java

Modified: pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/TTFSubsetter.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/TTFSubsetter.java?rev=1739952&r1=1739951&r2=1739952&view=diff
==============================================================================
--- pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/TTFSubsetter.java (original)
+++ pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/TTFSubsetter.java Tue
Apr 19 16:02:02 2016
@@ -249,7 +249,14 @@ public final class TTFSubsetter
         writeSInt16(out, h.getReserved4());
         writeSInt16(out, h.getReserved5());
         writeSInt16(out, h.getMetricDataFormat());
-        writeUint16(out, glyphIds.subSet(0, h.getNumberOfHMetrics()).size());
+
+        // is there a GID >= numberOfHMetrics ? Then keep the last entry of original hmtx
table
+        int hmetrics = glyphIds.subSet(0, h.getNumberOfHMetrics()).size();
+        if (glyphIds.last() >= h.getNumberOfHMetrics())
+        {
+            ++hmetrics;
+        }
+        writeUint16(out, hmetrics);
 
         out.flush();
         return bos.toByteArray();
@@ -864,11 +871,21 @@ public final class TTFSubsetter
         HorizontalMetricsTable hm = ttf.getHorizontalMetrics();
         byte [] buf = new byte[4];
         InputStream is = ttf.getOriginalData();
+        
+        // is there a GID >= numberOfHMetrics ? Then keep the last entry of original hmtx
table
+        SortedSet<Integer> gidSet = glyphIds;
+        if (glyphIds.last() >= h.getNumberOfHMetrics())
+        {
+            // Create a deep copy of the glyph set that has the last entry
+            gidSet = new TreeSet<Integer>(glyphIds);
+            gidSet.add(ttf.getHorizontalHeader().getNumberOfHMetrics() - 1);
+        }
+        
         try
         {
             is.skip(hm.getOffset());
             long lastOff = 0;
-            for (Integer glyphId : glyphIds)
+            for (Integer glyphId : gidSet)
             {
                 // offset in original file
                 long off;



Mime
View raw message