]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Do not stop building the metrics file if the unicode index is not found for a kerning...
authorBertrand Delacretaz <bdelacretaz@apache.org>
Fri, 13 Oct 2006 07:45:19 +0000 (07:45 +0000)
committerBertrand Delacretaz <bdelacretaz@apache.org>
Fri, 13 Oct 2006 07:45:19 +0000 (07:45 +0000)
In my tests with OpenType fonts provided with Ubuntu, this happened quite often, probably
caused by extraneous kerning entries which do not point to valid glyphs.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@463581 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/fonts/truetype/TTFFile.java

index defe1e01bc6eb01ec48f46f7696270e3610f4dd5..8eb7ecf621300387d45eba34fc5d03d537564024 100644 (file)
@@ -1269,12 +1269,21 @@ public class TTFFile {
                     if (kpx != 0) {
                         // CID kerning table entry, using unicode indexes
                         final Integer iObj = glyphToUnicode(i);
-                        Map adjTab = (Map)kerningTab.get(iObj);
-                        if (adjTab == null) {
-                            adjTab = new java.util.HashMap();
+                        final Integer u2 = glyphToUnicode(j);
+                        if(iObj==null) {
+                            // happens for many fonts (Ubuntu font set),
+                            // stray entries in the kerning table?? 
+                            log.warn("Unicode index (1) not found for glyph " + i);
+                        } else if(u2==null) {
+                            log.warn("Unicode index (2) not found for glyph " + i);
+                        } else {
+                            Map adjTab = (Map)kerningTab.get(iObj);
+                            if (adjTab == null) {
+                                adjTab = new java.util.HashMap();
+                            }
+                            adjTab.put(u2,new Integer((int)convertTTFUnit2PDFUnit(kpx)));
+                            kerningTab.put(iObj, adjTab);
                         }
-                        adjTab.put(glyphToUnicode(j),new Integer((int)convertTTFUnit2PDFUnit(kpx)));
-                        kerningTab.put(iObj, adjTab);
                     }
                 }
             }
@@ -1442,13 +1451,7 @@ public class TTFFile {
      * @throws IOException if glyphIndex not found
      */
     private Integer glyphToUnicode(int glyphIndex) throws IOException {
-        final Integer result = 
-            (Integer) glyphToUnicodeMap.get(new Integer(glyphIndex));
-        if (result == null) {
-            throw new IOException(
-                    "Unicode index not found for glyph " + glyphIndex);
-        }
-        return result;
+        return (Integer) glyphToUnicodeMap.get(new Integer(glyphIndex));
     }
     
     /**