You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2008/01/30 09:53:48 UTC

svn commit: r616691 - in /xmlgraphics/fop/trunk: src/java/org/apache/fop/fonts/truetype/TTFSubSetFile.java status.xml

Author: jeremias
Date: Wed Jan 30 00:53:48 2008
New Revision: 616691

URL: http://svn.apache.org/viewvc?rev=616691&view=rev
Log:
"cvt ", "fpgm" and "prep" are all optional tables in TrueType. Some PDF viewers fail because FOP didn't handle those correctly.

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/truetype/TTFSubSetFile.java
    xmlgraphics/fop/trunk/status.xml

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/truetype/TTFSubSetFile.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/truetype/TTFSubSetFile.java?rev=616691&r1=616690&r2=616691&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/truetype/TTFSubSetFile.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/truetype/TTFSubSetFile.java Wed Jan 30 00:53:48 2008
@@ -67,14 +67,31 @@
         // 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 @@
         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 @@
         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 @@
             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 @@
             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 @@
     /**
      * 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 @@
             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 @@
         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());
-        }
-
-        try {
-            createPrep(in);    // copy prep table
-        } catch (IOException ex) {
-            // Prep is optional (only required for OpenType (MS) fonts)
-            //log.error("TrueType warning: " + ex.getMessage());
-        }
-
-        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());
-        }
-
-        try {
-            createGlyf(in, glyphs);
-        } catch (IOException ex) {
-            // Glyf 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.");
+        }
+
+        optionalTableFound = createFpgm(in);    // copy fpgm table
+        if (!optionalTableFound) {
+            // fpgm is optional (used in TrueType fonts only)
+            log.debug("TrueType: fpgm table not present. Skipped.");
         }
+
+        optionalTableFound = createPrep(in);    // copy prep table
+        if (!optionalTableFound) {
+            // prep is optional (used in TrueType fonts only)
+            log.debug("TrueType: prep table not present. Skipped.");
+        }
+
+        createLoca(glyphs.size());    // create empty loca table
+        createGlyf(in, glyphs);       //create glyf table and update loca table
 
         pad4();
         createCheckSumAdjustment();

Modified: xmlgraphics/fop/trunk/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=616691&r1=616690&r2=616691&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Wed Jan 30 00:53:48 2008
@@ -29,6 +29,10 @@
   <changes>
     <release version="FOP Trunk">
       <action context="Fonts" dev="JM" type="fix">
+        Bugfix for handling of optional tables in subset TrueType fonts. This bug caused errors
+        in various PDF viewers.
+      </action>
+      <action context="Fonts" dev="JM" type="fix">
         Bugfix for invalid numTables entry in subset TrueType fonts if there was no "fpgm" table.
       </action>
       <action context="Renderers" dev="JM" type="add">



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org