You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2016/06/29 19:20:14 UTC
svn commit: r1750696 - in /pdfbox/branches/2.0/fontbox/src:
main/java/org/apache/fontbox/ttf/TTFSubsetter.java
test/java/org/apache/fontbox/ttf/TTFSubsetterTest.java
Author: tilman
Date: Wed Jun 29 19:20:14 2016
New Revision: 1750696
URL: http://svn.apache.org/viewvc?rev=1750696&view=rev
Log:
PDFBOX-2854: skip os2 and cmap tables if subset is empty
Modified:
pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/TTFSubsetter.java
pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/ttf/TTFSubsetterTest.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=1750696&r1=1750695&r2=1750696&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 Wed Jun 29 19:20:14 2016
@@ -35,6 +35,8 @@ import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
* Subsetter for TrueType (TTF) fonts.
@@ -46,6 +48,8 @@ import java.util.TreeSet;
*/
public final class TTFSubsetter
{
+ private static final Log LOG = LogFactory.getLog(TTFSubsetter.class);
+
private static final byte[] PAD_BUF = new byte[] { 0, 0, 0 };
private final TrueTypeFont ttf;
@@ -396,7 +400,7 @@ public final class TTFSubsetter
private byte[] buildOS2Table() throws IOException
{
OS2WindowsMetricsTable os2 = ttf.getOS2Windows();
- if (os2 == null || keepTables != null && !keepTables.contains("OS/2"))
+ if (os2 == null || uniToGID.isEmpty() || keepTables != null && !keepTables.contains("OS/2"))
{
return null;
}
@@ -682,7 +686,7 @@ public final class TTFSubsetter
private byte[] buildCmapTable() throws IOException
{
- if (ttf.getCmap() == null || keepTables != null && !keepTables.contains("cmap"))
+ if (ttf.getCmap() == null || uniToGID.isEmpty() || keepTables != null && !keepTables.contains("cmap"))
{
return null;
}
@@ -947,7 +951,7 @@ public final class TTFSubsetter
{
if (glyphIds.isEmpty() || uniToGID.isEmpty())
{
- throw new IllegalStateException("subset is empty");
+ LOG.info("font subset is empty");
}
addCompoundReferences();
Modified: pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/ttf/TTFSubsetterTest.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/ttf/TTFSubsetterTest.java?rev=1750696&r1=1750695&r2=1750696&view=diff
==============================================================================
--- pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/ttf/TTFSubsetterTest.java (original)
+++ pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/ttf/TTFSubsetterTest.java Wed Jun 29 19:20:14 2016
@@ -29,7 +29,6 @@ import org.apache.fontbox.util.autodetec
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
import org.junit.Test;
/**
@@ -40,7 +39,7 @@ public class TTFSubsetterTest
{
/**
- * Test of PDFBOX-2854: empty subset.
+ * Test of PDFBOX-2854: empty subset with all tables.
*
* @throws java.io.IOException
*/
@@ -50,15 +49,47 @@ public class TTFSubsetterTest
final File testFile = new File("src/test/resources/ttf/LiberationSans-Regular.ttf");
TrueTypeFont x = new TTFParser().parse(testFile);
TTFSubsetter ttfSubsetter = new TTFSubsetter(x);
- try
- {
- ttfSubsetter.writeToStream(new ByteArrayOutputStream());
- fail("IllegalStateException should be thrown");
- }
- catch (IllegalStateException e)
- {
- // ok
- }
+
+ 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();
+ }
+
+ /**
+ * Test of PDFBOX-2854: empty subset with selected tables.
+ *
+ * @throws java.io.IOException
+ */
+ @Test
+ public void testEmptySubset2() throws IOException
+ {
+ final File testFile = new File("src/test/resources/ttf/LiberationSans-Regular.ttf");
+ TrueTypeFont x = new TTFParser().parse(testFile);
+ // List copied from TrueTypeEmbedder.java
+ List<String> tables = new ArrayList<String>();
+ tables.add("head");
+ tables.add("hhea");
+ tables.add("loca");
+ tables.add("maxp");
+ tables.add("cvt ");
+ tables.add("prep");
+ tables.add("glyf");
+ tables.add("hmtx");
+ tables.add("fpgm");
+ tables.add("gasp");
+ TTFSubsetter ttfSubsetter = new TTFSubsetter(x, tables);
+
+ 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();
}
/**