From: Jeremias Maerki Date: Wed, 30 Jan 2008 08:53:48 +0000 (+0000) Subject: "cvt ", "fpgm" and "prep" are all optional tables in TrueType. Some PDF viewers fail... X-Git-Tag: fop-0_95beta~122 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b9c4bae4480968732c0a2b02556771031eacdf17;p=xmlgraphics-fop.git "cvt ", "fpgm" and "prep" are all optional tables in TrueType. Some PDF viewers fail because FOP didn't handle those correctly. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@616691 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/fonts/truetype/TTFSubSetFile.java b/src/java/org/apache/fop/fonts/truetype/TTFSubSetFile.java index c12a7900f..99fd10315 100644 --- a/src/java/org/apache/fop/fonts/truetype/TTFSubSetFile.java +++ b/src/java/org/apache/fop/fonts/truetype/TTFSubSetFile.java @@ -67,14 +67,31 @@ public class TTFSubSetFile extends TTFFile { // createDirectory() } + private int determineTableCount() { + int numTables = 4; //4 req'd tables: head,hhea,hmtx,maxp + if (isCFF()) { + throw new UnsupportedOperationException( + "OpenType fonts with CFF glyphs are not supported"); + } else { + numTables += 2; //1 req'd table: glyf,loca + if (hasCvt()) { + numTables++; + } + if (hasFpgm()) { + numTables++; + } + if (hasPrep()) { + numTables++; + } + } + return numTables; + } + /** * Create the directory table */ private void createDirectory() { - int numTables = 8; - if (hasFpgm()) { - numTables++; - } + int numTables = determineTableCount(); // Create the TrueType header writeByte((byte)0); writeByte((byte)1); @@ -98,10 +115,12 @@ public class TTFSubSetFile extends TTFFile { realSize += 2; // Create space for the table entries - writeString("cvt "); - cvtDirOffset = currentPos; - currentPos += 12; - realSize += 16; + if (hasCvt()) { + writeString("cvt "); + cvtDirOffset = currentPos; + currentPos += 12; + realSize += 16; + } if (hasFpgm()) { writeString("fpgm"); @@ -140,17 +159,19 @@ public class TTFSubSetFile extends TTFFile { currentPos += 12; realSize += 16; - writeString("prep"); - prepDirOffset = currentPos; - currentPos += 12; - realSize += 16; + if (hasPrep()) { + writeString("prep"); + prepDirOffset = currentPos; + currentPos += 12; + realSize += 16; + } } /** * Copy the cvt table as is from original font to subset font */ - private void createCvt(FontFileReader in) throws IOException { + private boolean createCvt(FontFileReader in) throws IOException { TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("cvt "); if (entry != null) { pad4(); @@ -164,21 +185,29 @@ public class TTFSubSetFile extends TTFFile { writeULong(cvtDirOffset + 8, (int)entry.getLength()); currentPos += (int)entry.getLength(); realSize += (int)entry.getLength(); + return true; } else { - throw new IOException("Can't find cvt table"); + return false; + //throw new IOException("Can't find cvt table"); } } + private boolean hasCvt() { + return dirTabs.containsKey("cvt "); + } private boolean hasFpgm() { - return (dirTabs.get("fpgm") != null); + return dirTabs.containsKey("fpgm"); } + private boolean hasPrep() { + return dirTabs.containsKey("prep"); + } /** * Copy the fpgm table as is from original font to subset font */ - private void createFpgm(FontFileReader in) throws IOException { + private boolean createFpgm(FontFileReader in) throws IOException { TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("fpgm"); if (entry != null) { pad4(); @@ -191,9 +220,9 @@ public class TTFSubSetFile extends TTFFile { writeULong(fpgmDirOffset + 8, (int)entry.getLength()); currentPos += (int)entry.getLength(); realSize += (int)entry.getLength(); + return true; } else { - //fpgm table is optional - //throw new IOException("Can't find fpgm table"); + return false; } } @@ -240,7 +269,7 @@ public class TTFSubSetFile extends TTFFile { /** * Copy the prep table as is from original font to subset font */ - private void createPrep(FontFileReader in) throws IOException { + private boolean createPrep(FontFileReader in) throws IOException { TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("prep"); if (entry != null) { pad4(); @@ -254,8 +283,9 @@ public class TTFSubSetFile extends TTFFile { writeULong(prepDirOffset + 8, (int)entry.getLength()); currentPos += (int)entry.getLength(); realSize += (int)entry.getLength(); + return true; } else { - throw new IOException("Can't find prep table"); + return false; } } @@ -640,40 +670,27 @@ public class TTFSubSetFile extends TTFFile { createHmtx(in, glyphs); // Create hmtx table createMaxp(in, glyphs.size()); // copy the maxp table - try { - createCvt(in); // copy the cvt table - } catch (IOException ex) { - // Cvt is optional (only required for OpenType (MS) fonts) - //log.error("TrueType warning: " + ex.getMessage()); - } - - try { - createFpgm(in); // copy fpgm table - } catch (IOException ex) { - // Fpgm is optional (only required for OpenType (MS) fonts) - //log.error("TrueType warning: " + ex.getMessage()); + boolean optionalTableFound; + optionalTableFound = createCvt(in); // copy the cvt table + if (!optionalTableFound) { + // cvt is optional (used in TrueType fonts only) + log.debug("TrueType: ctv table not present. Skipped."); } - try { - createPrep(in); // copy prep table - } catch (IOException ex) { - // Prep is optional (only required for OpenType (MS) fonts) - //log.error("TrueType warning: " + ex.getMessage()); + optionalTableFound = createFpgm(in); // copy fpgm table + if (!optionalTableFound) { + // fpgm is optional (used in TrueType fonts only) + log.debug("TrueType: fpgm table not present. Skipped."); } - try { - createLoca(glyphs.size()); // create empty loca table - } catch (IOException ex) { - // Loca is optional (only required for OpenType (MS) fonts) - //log.error("TrueType warning: " + ex.getMessage()); + optionalTableFound = createPrep(in); // copy prep table + if (!optionalTableFound) { + // prep is optional (used in TrueType fonts only) + log.debug("TrueType: prep table not present. Skipped."); } - try { - createGlyf(in, glyphs); - } catch (IOException ex) { - // Glyf is optional (only required for OpenType (MS) fonts) - //log.error("TrueType warning: " + ex.getMessage()); - } + createLoca(glyphs.size()); // create empty loca table + createGlyf(in, glyphs); //create glyf table and update loca table pad4(); createCheckSumAdjustment(); diff --git a/status.xml b/status.xml index 60f0819c2..63a8a1d89 100644 --- a/status.xml +++ b/status.xml @@ -28,6 +28,10 @@ + + Bugfix for handling of optional tables in subset TrueType fonts. This bug caused errors + in various PDF viewers. + Bugfix for invalid numTables entry in subset TrueType fonts if there was no "fpgm" table.