[gs-commits] ghostpdl branch, master, updated. ghostpdl-9.02-674-g3122552

Ken Sharp ken at ghostscript.com
Fri Oct 21 09:53:23 UTC 2011


The ghostpdl branch, master has been updated
       via  312255297353a9f62b5090e9137586a8ecfc8601 (commit)
      from  41faddadc03e389f4f1b3c3d9a4f6bdf36ebbfb1 (commit)

----------------------------------------------------------------------
commit 312255297353a9f62b5090e9137586a8ecfc8601
Author: Ken Sharp <ken.sharp at artifex.com>
Date:   Fri Oct 21 10:52:26 2011 +0100

    Font copying does not work with CIDFonts using dictioanry form of GlyphDirectory
    
    Bug #692573, the font copying code uses 'slots' to record glyph data, which
    are entries in an array. The index into the array can be a name or a CID.
    
    This assumes that CIDCount (the number of glyphs in the font) is the same as
    the maximum CID (ie the range is continuous), which is generally true.
    However, the dictionary form of GlyphDirectory allows for discontinuous CIDs.
    This meant that the array was too small to use the CID as an index.
    
    Fixing this efficeintly would mean completely rewriting the code in gxfcopy.c
    so that it uses some kind of dictionary structure instead of an array. Instead
    I've chosen to find the highest CID in the font (by enumerating the GlyphDirectory)
    and use that to create he array with enough entries. Inefficient use of memory
    but it saves having to re-architect the code.
    
    The text that was previously missing is now present, and this reveals a new
    problem, some of the text is incorrectly spaced after conversion with pdfwrite.
    I'll open this as a new bug.
    
    No differences expected

diff --git a/gs/base/gxfcid.h b/gs/base/gxfcid.h
index 37df4e8..4924a0a 100644
--- a/gs/base/gxfcid.h
+++ b/gs/base/gxfcid.h
@@ -32,6 +32,7 @@
 typedef struct gs_font_cid_data_s {
     gs_cid_system_info_t CIDSystemInfo;
     int CIDCount;
+    int MaxCID;                 /* For font with GlyphDirectory highest CID != CIDCount. */
     int GDBytes;		/* optional, for standard glyph_data */
     /*int PaintType;*/
     /*float StrokeWidth;*/
diff --git a/gs/base/gxfcopy.c b/gs/base/gxfcopy.c
index bca34b0..4cc8164 100644
--- a/gs/base/gxfcopy.c
+++ b/gs/base/gxfcopy.c
@@ -2004,7 +2004,13 @@ gs_copy_font(gs_font *font, const gs_matrix *orig_matrix, gs_memory_t *mem, gs_f
         break;
     case ft_CID_encrypted:
         procs = &copied_procs_cid0;
-        glyphs_size = ((gs_font_cid0 *)font)->cidata.common.CIDCount;
+        /* We used to use the CIDCount here, but for CIDFonts with a GlyphDirectory
+         * (dictionary form) the number of CIDs is not the same as the highest CID.
+         * Because we use the CID as the slot, we need to assign the highest possible
+         * CID, not the number of CIDs. Don't forget to add one because CIDs
+         * count from 0.
+         */
+        glyphs_size = ((gs_font_cid0 *)font)->cidata.common.MaxCID + 1;
         break;
     case ft_CID_TrueType:
         procs = &copied_procs_cid2;
diff --git a/gs/psi/zfcid.c b/gs/psi/zfcid.c
index fbd31cb..d66cef9 100644
--- a/gs/psi/zfcid.c
+++ b/gs/psi/zfcid.c
@@ -48,6 +48,8 @@ cid_font_data_param(os_ptr op, gs_font_cid_data *pdata, ref *pGlyphDirectory)
                                &pdata->CIDCount)) < 0
         )
         return code;
+    /* Start by assigning the highest CID to be the count of CIDs. */
+    pdata->MaxCID = pdata->CIDCount + 1;
     /*
      * If the font doesn't have a GlyphDirectory, GDBytes is required.
      * If it does have a GlyphDirectory, GDBytes may still be needed for
@@ -60,10 +62,27 @@ cid_font_data_param(os_ptr op, gs_font_cid_data *pdata, ref *pGlyphDirectory)
                               &pdata->GDBytes);
     }
     if (r_has_type(pgdir, t_dictionary) || r_is_array(pgdir)) {
+        int index;
+        ref element[2];
+
         /* GlyphDirectory, GDBytes is optional. */
         *pGlyphDirectory = *pgdir;
         code = dict_int_param(op, "GDBytes", 0, MAX_GDBytes, 0,
                               &pdata->GDBytes);
+
+        /* If we have a GlyphDirectory then the maximum CID is *not* given by
+         * the number of CIDs in the font. We need to know the maximum CID
+         * when copying fonts, so calculate and store it now.
+         */
+        index = dict_first(pgdir);
+        while (index >= 0) {
+            index = dict_next(pgdir, index, (ref *)&element);
+            if (index >= 0) {
+                if (element[0].value.intval > pdata->MaxCID)
+                    pdata->MaxCID = element[0].value.intval;
+            }
+        }
+
         return code;
     } else {
         return_error(e_typecheck);


Summary of changes:
 gs/base/gxfcid.h  |    1 +
 gs/base/gxfcopy.c |    8 +++++++-
 gs/psi/zfcid.c    |   19 +++++++++++++++++++
 3 files changed, 27 insertions(+), 1 deletions(-)



More information about the gs-commits mailing list