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 2006/04/12 09:55:19 UTC

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

Author: jeremias
Date: Wed Apr 12 00:55:17 2006
New Revision: 393410

URL: http://svn.apache.org/viewcvs?rev=393410&view=rev
Log:
Bugfix: Fixed a division by zero problem in TTFReader popping up with arialuni.ttf.
Improved the detection of the capHeight and xHeight font metric values for TrueType fonts. Fonts that contain a version 3.0 PostScript table don't contain unicode glyph names. Without an xHeight value, super- and subscript does not work in FOP.

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

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/truetype/TTFFile.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/truetype/TTFFile.java?rev=393410&r1=393409&r2=393410&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/truetype/TTFFile.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/truetype/TTFFile.java Wed Apr 12 00:55:17 2006
@@ -130,7 +130,7 @@
         if (n < 0) {
             long rest1 = n % upem;
             long storrest = 1000 * rest1;
-            long ledd2 = rest1 / storrest;
+            long ledd2 = (storrest != 0 ? rest1 / storrest : 0);  
             ret = -((-1000 * n) / upem - (int)ledd2);
         } else {
             ret = (n / upem) * 1000 + ((n % upem) * 1000) / upem;
@@ -427,7 +427,7 @@
         readIndexToLocation(in);
         readGlyf(in);
         readName(in);
-        readPCLT(in);
+        boolean pcltFound = readPCLT(in);
         // Read cmap table and fill in ansiwidths
         boolean valid = readCMAP(in);
         if (!valid) {
@@ -438,6 +438,9 @@
         // print_max_min();
 
         readKerning(in);
+        if (!pcltFound) {
+            guessPCLTValuesFromBBox();
+        }
         return true;
     }
 
@@ -1020,7 +1023,7 @@
      * @param in FontFileReader to read from
      * @throws IOException In case of a I/O problem
      */
-    private final void readPCLT(FontFileReader in) throws IOException {
+    private final boolean readPCLT(FontFileReader in) throws IOException {
         TTFDirTabEntry dirTab = (TTFDirTabEntry)dirTabs.get("PCLT");
         if (dirTab != null) {
             in.seekSet(dirTab.getOffset() + 4 + 4 + 2);
@@ -1037,21 +1040,50 @@
             } else {
                 hasSerifs = true;
             }
+            return true;
         } else {
-            // Approximate capHeight from height of "H"
-            // It's most unlikly that a font misses the PCLT table
-            // This also assumes that psocriptnames exists ("H")
-            // Should look it up int the cmap (that wouldn't help
-            // for charsets without H anyway...)
-            // Same for xHeight with the letter "x"
-            for (int i = 0; i < mtxTab.length; i++) {
-                if ("H".equals(mtxTab[i].getName())) {
-                    capHeight = mtxTab[i].getBoundingBox()[3] - mtxTab[i].getBoundingBox()[1];
-                }
-                if ("x".equals(mtxTab[i].getName())) {
-                    xHeight = mtxTab[i].getBoundingBox()[3] - mtxTab[i].getBoundingBox()[1];
+            return false;
+        }
+    }
+
+    private void guessPCLTValuesFromBBox() {
+        // Approximate capHeight from height of "H"
+        // It's most unlikly that a font misses the PCLT table
+        // This also assumes that postscriptnames exists ("H")
+        // Should look it up int the cmap (that wouldn't help
+        // for charsets without H anyway...)
+        // Same for xHeight with the letter "x"
+        boolean capHeightFound = false;
+        boolean xHeightFound = false;
+        for (int i = 0; i < mtxTab.length; i++) {
+            if ("H".equals(mtxTab[i].getName())) {
+                capHeight = mtxTab[i].getBoundingBox()[3] - mtxTab[i].getBoundingBox()[1];
+                capHeightFound = true;
+            } else if ("x".equals(mtxTab[i].getName())) {
+                xHeight = mtxTab[i].getBoundingBox()[3] - mtxTab[i].getBoundingBox()[1];
+                xHeightFound = true;
+            } else {
+                // OpenType Fonts with a version 3.0 "post" table don't have glyph names.
+                // Use Unicode indices instead.
+                List unicodeIndex = mtxTab[i].getUnicodeIndex();
+                if (unicodeIndex.size() > 0) {
+                    //Only the first index is used
+                    char ch = (char)((Integer)unicodeIndex.get(0)).intValue();
+                    if (ch == 'H') {
+                        capHeight = mtxTab[i].getBoundingBox()[3] - mtxTab[i].getBoundingBox()[1];
+                        capHeightFound = true;
+                    } else if (ch == 'x') {
+                        xHeight = mtxTab[i].getBoundingBox()[3] - mtxTab[i].getBoundingBox()[1];
+                        xHeightFound = true;
+                    }
                 }
             }
+        }
+        if (!capHeightFound) {
+            log.warn("capHeight value could not be determined. The font may not work as expected.");
+        }
+        if (!xHeightFound) {
+            log.warn("xHeight value could not be determined. The font may not work as expected.");
         }
     }
 

Modified: xmlgraphics/fop/trunk/status.xml
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/status.xml?rev=393410&r1=393409&r2=393410&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Wed Apr 12 00:55:17 2006
@@ -28,6 +28,10 @@
   <changes>
     <release version="FOP Trunk">
       <action context="Code" dev="JM" type="fix">
+        Bugfix: Fixed a division by zero problem in TTFReader and improved the detection
+        of the capHeight and xHeight font metric values for TrueType fonts.
+      </action>
+      <action context="Code" dev="JM" type="fix">
         Bugfix: Allow URLs in basic-link's external-destination to be wrapped in "url()".
       </action>
       <action context="Code" dev="MM" type="fix">



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