Commit 2ded2c1d30f8294b1b8215013fee4112d182ebf3

David Turner 2002-03-22T22:37:40

* src/base/ftobjs.c, src/sfnt/ttcmap0.c, src/type1/t1objs.c: various fixes to make the FT_CMaps support work correctly (more tests are still needed)

diff --git a/ChangeLog b/ChangeLog
index 5433ef3..cd1816e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2002-03-22  David Turner    <david@freetype.org>
 
+        * src/base/ftobjs.c, src/sfnt/ttcmap0.c, src/type1/t1objs.c:
+        
+          various fixes to make the FT_CMaps support work correctly
+          (more tests are still needed)
+
         * include/freetype/internal/ftobjs.h,
           src/sfnt/Jamfile, src/sfnt/rules.mk,
           src/sfnt/sfnt.c, src/sfnt/sfobjs.c,
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index 780b9be..2b341b0 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -612,6 +612,28 @@
     if ( face->generic.finalizer )
       face->generic.finalizer( face );
 
+#ifdef FT_CONFIG_OPTION_USE_CMAPS
+
+    /* discard charmaps */
+    {
+      FT_Int  n;
+      
+      for ( n = 0; n < face->num_charmaps; n++ )
+      {
+        FT_CMap  cmap = FT_CMAP( face->charmaps[n] );
+        
+        FT_CMap_Done( cmap );
+        
+        face->charmaps[n] = NULL;
+      }
+      
+      FT_FREE( face->charmaps );
+      face->num_charmaps = 0;
+    }
+
+#endif /* FT_CONFIG_OPTION_USE_CMAPS */
+
+
     /* finalize format-specific stuff */
     if ( clazz->done_face )
       clazz->done_face( face );
diff --git a/src/sfnt/ttcmap0.c b/src/sfnt/ttcmap0.c
index f0aa965..7932db2 100644
--- a/src/sfnt/ttcmap0.c
+++ b/src/sfnt/ttcmap0.c
@@ -642,7 +642,7 @@
         p = deltas  + n*2;  delta  = TT_PEEK_SHORT(p);
         p = offsets + n*2;  offset = TT_PEEK_USHORT(p);
 
-        if ( end > start )
+        if ( start > end )
           FT_INVALID_DATA;
 
         if ( n > 0 && start <= last )
@@ -713,14 +713,14 @@
 
         if ( code <= end )
         {
-          index = (FT_UInt)( char_code - start );
+          index = code;
 
           p  = q + num_segs2 - 2; delta  = TT_PEEK_SHORT(p);
           p += num_segs2;         offset = TT_PEEK_USHORT(p);
 
           if ( offset != 0 )
           {
-            p    += offset + 2*index;
+            p    += offset + 2*(index - start);
             index = TT_PEEK_USHORT(p);
           }
 
@@ -1575,6 +1575,8 @@
 
       charmap.platform_id = TT_NEXT_USHORT(p);
       charmap.encoding_id = TT_NEXT_USHORT(p);
+      charmap.face        = FT_FACE(face);
+      charmap.encoding    = 0;  /* will be filled later */
       offset              = TT_NEXT_ULONG(p);
 
       if ( offset && table + offset + 2 < limit )
diff --git a/src/type1/t1objs.c b/src/type1/t1objs.c
index 68087f5..32346af 100644
--- a/src/type1/t1objs.c
+++ b/src/type1/t1objs.c
@@ -324,9 +324,7 @@
       FT_Face  root = (FT_Face)&face->root;
 
 
-      root->num_glyphs   = face->type1.num_glyphs;
-      root->num_charmaps = 1;
-
+      root->num_glyphs = face->type1.num_glyphs;
       root->face_index = face_index;
       root->face_flags = FT_FACE_FLAG_SCALABLE;