Commit 3d3ba0563e4519a0321f12cdfc2220f88bd45295

Bram Tassyns 2009-07-05T14:54:59

Improve compatibility to Acroread. This fixes Savannah bug #26944. * src/cff/cffload.c (cff_charset_compute_cids): For multiple GID to single CID mappings, make the lowest value win.

diff --git a/ChangeLog b/ChangeLog
index 1592136..dbd2680 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-07-05  Bram Tassyns  <bramt@enfocus.be>
+
+	Improve compatibility to Acroread.
+	This fixes Savannah bug #26944.
+
+	* src/cff/cffload.c (cff_charset_compute_cids): For multiple GID to
+	single CID mappings, make the lowest value win.
+
 2009-06-28  suzuki toshiya  <mpsuzuki@hiroshima-u.ac.jp>
 
 	ftpatent: Fix a bug by wrong usage of service->table_info().
diff --git a/src/cff/cffload.c b/src/cff/cffload.c
index 1675ee4..14d3db7 100644
--- a/src/cff/cffload.c
+++ b/src/cff/cffload.c
@@ -736,6 +736,7 @@
   {
     FT_Error   error   = FT_Err_Ok;
     FT_UInt    i;
+    FT_Long    j;
     FT_UShort  max_cid = 0;
 
 
@@ -750,8 +751,11 @@
     if ( FT_NEW_ARRAY( charset->cids, max_cid ) )
       goto Exit;
 
-    for ( i = 0; i < num_glyphs; i++ )
-      charset->cids[charset->sids[i]] = (FT_UShort)i;
+    /* When multiple GIDs map to the same CID, we choose the lowest */
+    /* GID.  This is not described in any spec, but it matches the  */
+    /* behaviour of recent Acroread versions.                       */
+    for ( j = num_glyphs - 1; j >= 0 ; j-- )
+      charset->cids[charset->sids[j]] = (FT_UShort)j;
 
     charset->max_cid    = max_cid;
     charset->num_glyphs = num_glyphs;