freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Devel] FT2 bug when accessing TrueType font Format 2 CMap


From: Yao Zhang
Subject: [Devel] FT2 bug when accessing TrueType font Format 2 CMap
Date: Fri, 07 Sep 2001 17:00:47 -0400

While using FT2 to access TrueType font with
Format 2 CMap, the glyph index is always off
for characters which hi-bytes are 0s (ASCII
characters).  I don't know if the bug has been
reported before or not.  To reproduce the problem,
you need to have a ttf with Format 2 CMap.  Lots
of Chinese fonts are in that format.

It turns out that

freetype2/src/sfnt/ttcmap.c:code_to_index2()

has a bug.  According to Apple's TTF spec,
even for ASCII code (hi-byte 0), it still need
to go through subHeader 0 to retrieve the
glyph index.

The patch is attached.


Index: ttcmap.c
===================================================================
RCS file: /cvs/freetype/freetype2/src/sfnt/ttcmap.c,v
retrieving revision 1.36
diff -u -r1.36 ttcmap.c
--- ttcmap.c    2001/08/13 11:44:29     1.36
+++ ttcmap.c    2001/09/07 20:00:25
@@ -503,29 +503,29 @@
     {
       /* an 8-bit character code -- we use the subHeader 0 in this case */
       /* to test whether the character code is in the charmap           */
-      if ( cmap2->subHeaderKeys[char_lo] == 0 )
-        result = cmap2->glyphIdArray[char_lo];
+      index1 = cmap2->subHeaderKeys[char_lo];
+      if ( index1 != 0 )
+        return 0;
     }
     else
     {
       /* a 16-bit character code */
       index1 = cmap2->subHeaderKeys[char_hi & 0xFF];
-      if ( index1 )
-      {
-        sh2      = cmap2->subHeaders + index1;
-        char_lo -= sh2->firstCode;
+      if ( index1 == 0 )
+        return 0;
+    }
+
+    sh2      = cmap2->subHeaders + index1;
+    char_lo -= sh2->firstCode;
 
-        if ( char_lo < (FT_UInt)sh2->entryCount )
-        {
-          offset = sh2->idRangeOffset / 2 + char_lo;
-          if ( offset < (FT_UInt)cmap2->numGlyphId )
-          {
-            result = cmap2->glyphIdArray[offset];
-            if ( result )
-              result = ( result + sh2->idDelta ) & 0xFFFF;
-          }
-        }
-      }
+    if ( char_lo < (FT_UInt)sh2->entryCount )
+    {
+      offset = sh2->idRangeOffset / 2 + char_lo;
+      if ( offset < (FT_UInt)cmap2->numGlyphId )
+      {
+        result = cmap2->glyphIdArray[offset];
+        if ( result )
+          result = ( result + sh2->idDelta ) & 0xFFFF;
     }
 
     return result;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]