[gs-cvs] rev 8216 - trunk/gs/src

leonardo at ghostscript.com leonardo at ghostscript.com
Wed Aug 29 10:36:37 PDT 2007


Author: leonardo
Date: 2007-08-29 10:36:36 -0700 (Wed, 29 Aug 2007)
New Revision: 8216

Modified:
   trunk/gs/src/gdevpdtc.c
   trunk/gs/src/gdevpdtf.c
   trunk/gs/src/gdevpdtf.h
   trunk/gs/src/gdevpdtt.c
   trunk/gs/src/gdevpdtt.h
   trunk/gs/src/zbfont.c
   trunk/gs/src/zfcid0.c
   trunk/gs/src/zfcid1.c
Log:
Fix (TT font handling) : pdfwrite recieved meanless font names.

DETAILS :

Bug 688006 "Font names used with pdfwrite are strange with GS, OK with Adobe Distiller".

This is a continuation for the Revision 5862 change 
made on Wed Apr 20 20:05:41 2005 UTC (2 years, 4 months ago) by ray.

Thanks to Edward for a code sample for accounting font style string.

1. (zbfont.c) When a Postscript file is generated with Adobe printer driver for Windows,
the old code (sinse Revision 5862) extracts OrigFintName 
for building a meanful FontName.
This patch adds an use of OrigFontStyle as suggested by Edward,
so the FontName is created in the form "Arial,Bold".

2. (zfcid1.c) The old code sometimes dropped the good FontName in zbuildfont11 
due to an extra call to get_font_name. Few lines above
the function build_gs_TrueType_font creates the good font name
during an indirect call to sub_font_params, so the call to  
get_font_name is not necesary when OrigFontName presents.
However it is still necessary with regular FontType 11
because they have no FontName and sub_font_params
doesn't use CIDFontName.

3. (zfcid0.c) Applying the (2) change to FontType 9 as for symmetry.
We're tested it a few, but we have no untrivial examples
when a FontType 9 is embedded with OrigFontName.
Maybe (just guessing) ones could be obtained with installing
Adobe Type Library and printing with Adobe printer driver.

4. After doing all above, we unexpectedly detected a regression 
with comparefiles/korea.ps : all Korean glyphs were replaced with
hollow boxes. Analyzing it we found that the document defines a 
composite font with to CIDFontType 2 descendent,
which both appears to be same font. In same time,
the CMap supplies different CIDs for those 2
descendents for a half of code space. While the old code
used meanless unique font names, those 2 descendents
were converted to 2 PDF fonts. When we switched to the meanful name,
which of course is same for both descendents,
pdfwrite tries to merge the descendents.
However doing so it assumed same character mapping
for both descendents.

To fix this problem more changes are done to pdfwrite :

4.1. (gdevpdtf.h) The font descriptor of a type 0 font now stores font_index,
which is the index of its descendent font in the DescendentFonts array
of the source Type 0 font. This happens because in PDF type 0 fonts
always have a single descendent.

4.2. (gdevpdtf.c) Added an initialization for the new field.

4.2. (gdevpdtt.c, gdevpdtt.h) pdf_obtain_parent_type0_font_resource creates
unique type 0 fonts for each descendent in spite of same font name.

4.3 (gdevpdtc.c) pdf_obtain_parent_type0_font_resource needs 
font index as a new argument.

4.4. (gdevpdtt.c) pdf_find_type0_font_resource also takes the new parameter.

With Korea.ps we create 2 font subsets where a single font
would be enough. An optimization may be done with a dynamic
check for encoding conflicts rather than creating another font
for each font index of the CMap. Delaying it for better times.

EXPECTED DIFFERENCES :

None.


Modified: trunk/gs/src/gdevpdtc.c
===================================================================
--- trunk/gs/src/gdevpdtc.c	2007-08-29 09:42:15 UTC (rev 8215)
+++ trunk/gs/src/gdevpdtc.c	2007-08-29 17:36:36 UTC (rev 8216)
@@ -465,7 +465,7 @@
 		code = pdf_obtain_cidfont_widths_arrays(pdev, pdsubf, wmode, &w, &w0, &v);
 		if (code < 0)
 		    return code;
-		code = pdf_obtain_parent_type0_font_resource(pdev, pdsubf, 
+		code = pdf_obtain_parent_type0_font_resource(pdev, pdsubf, font_index,
 				&font->data.CMap->CMapName, &pdfont);
 		if (code < 0)
 		    return code;
@@ -570,7 +570,7 @@
 	    if (pdsubf0->FontType == ft_user_defined)
 		pdfont = pdsubf0;
 	    else {
-		code = pdf_obtain_parent_type0_font_resource(pdev, pdsubf0, 
+		code = pdf_obtain_parent_type0_font_resource(pdev, pdsubf0, font_index0, 
 			    &font->data.CMap->CMapName, &pdfont);
 		if (code < 0)
 		    return code;

Modified: trunk/gs/src/gdevpdtf.c
===================================================================
--- trunk/gs/src/gdevpdtf.c	2007-08-29 09:42:15 UTC (rev 8215)
+++ trunk/gs/src/gdevpdtf.c	2007-08-29 17:36:36 UTC (rev 8216)
@@ -816,6 +816,7 @@
     if (code >= 0) {
 	(*ppfres)->u.type0.DescendantFont = DescendantFont;
 	(*ppfres)->u.type0.CMapName = *CMapName;
+	(*ppfres)->u.type0.font_index = 0;
 	code = pdf_compute_BaseFont(pdev, *ppfres, false);
     }
     return code;    

Modified: trunk/gs/src/gdevpdtf.h
===================================================================
--- trunk/gs/src/gdevpdtf.h	2007-08-29 09:42:15 UTC (rev 8215)
+++ trunk/gs/src/gdevpdtf.h	2007-08-29 17:36:36 UTC (rev 8216)
@@ -237,6 +237,7 @@
 	    ];
 	    gs_const_string CMapName; /* copied from the original CMap, */
 				/* or references the table of standard names */
+	    uint font_index;	/* The index of the descendent font in the source CMap. */
 	    bool cmap_is_standard;
 	    int WMode;		/* of CMap */
 

Modified: trunk/gs/src/gdevpdtt.c
===================================================================
--- trunk/gs/src/gdevpdtt.c	2007-08-29 09:42:15 UTC (rev 8215)
+++ trunk/gs/src/gdevpdtt.c	2007-08-29 17:36:36 UTC (rev 8216)
@@ -902,7 +902,7 @@
  */
 private int
 pdf_find_type0_font_resource(gx_device_pdf *pdev, const pdf_font_resource_t *pdsubf, 
-	    const gs_const_string *CMapName, pdf_font_resource_t **ppdfont)
+	    const gs_const_string *CMapName, uint font_index, pdf_font_resource_t **ppdfont)
 {
     pdf_resource_t **pchain = pdev->resources[resourceFont].chains;
     pdf_resource_t *pres;
@@ -916,6 +916,8 @@
 		continue;
 	    if (pdfont->u.type0.DescendantFont != pdsubf)
 		continue;
+	    if (pdfont->u.type0.font_index != font_index)
+		continue;
 	    if (pdfont->BaseFont.size != pdsubf->BaseFont.size + CMapName->size + 1)
 		continue;
 	    if (memcmp(pdfont->BaseFont.data + pdsubf->BaseFont.size + 1, 
@@ -1819,9 +1821,10 @@
  */
 int
 pdf_obtain_parent_type0_font_resource(gx_device_pdf *pdev, pdf_font_resource_t *pdsubf, 
-		const gs_const_string *CMapName, pdf_font_resource_t **pdfont)
+		uint font_index, const gs_const_string *CMapName, pdf_font_resource_t **pdfont)
 {
-    if (pdsubf->u.cidfont.parent != 0 && 
+    if (pdsubf->u.cidfont.parent != 0 &&
+	    font_index == pdsubf->u.cidfont.parent->u.type0.font_index &&
 	    strings_equal(CMapName, &pdsubf->u.cidfont.parent->u.type0.CMapName))
 	*pdfont = pdsubf->u.cidfont.parent;
     else {
@@ -1836,11 +1839,12 @@
 	 */
 
 	if (pdsubf->u.cidfont.parent == NULL || 
-		pdf_find_type0_font_resource(pdev, pdsubf, CMapName, pdfont) <= 0) {
+		pdf_find_type0_font_resource(pdev, pdsubf, CMapName, font_index, pdfont) <= 0) {
 	    int code = pdf_font_type0_alloc(pdev, pdfont, gs_no_id, pdsubf, CMapName);
 
 	    if (code < 0)
 		return code;
+	    (*pdfont)->u.type0.font_index = font_index;
 	}
 	pdsubf->u.cidfont.parent = *pdfont;
     }

Modified: trunk/gs/src/gdevpdtt.h
===================================================================
--- trunk/gs/src/gdevpdtt.h	2007-08-29 09:42:15 UTC (rev 8215)
+++ trunk/gs/src/gdevpdtt.h	2007-08-29 17:36:36 UTC (rev 8216)
@@ -193,7 +193,7 @@
  * Create or find a parent Type 0 font resource object for a CID font resource.
  */
 int pdf_obtain_parent_type0_font_resource(gx_device_pdf *pdev, pdf_font_resource_t *pdsubf, 
-		const gs_const_string *CMapName, pdf_font_resource_t **pdfont);
+		uint font_index, const gs_const_string *CMapName, pdf_font_resource_t **pdfont);
 
 /*
  * Retrive font resource attached to a font.

Modified: trunk/gs/src/zbfont.c
===================================================================
--- trunk/gs/src/zbfont.c	2007-08-29 09:42:15 UTC (rev 8215)
+++ trunk/gs/src/zbfont.c	2007-08-29 17:36:36 UTC (rev 8216)
@@ -583,11 +583,9 @@
 
 /* Get FontMatrix and FontName parameters. */
 private int
-sub_font_params(const gs_memory_t *mem, const ref *op, gs_matrix *pmat, gs_matrix *pomat, ref *pfname)
+sub_font_params(gs_memory_t *mem, const ref *op, gs_matrix *pmat, gs_matrix *pomat, ref *pfname)
 {
-    ref *pmatrix;
-    ref *pfontname;
-    ref *porigfont;
+    ref *pmatrix, *pfontname, *pfontstyle, *porigfont, *pfontinfo;
 
     if (dict_find_string(op, "FontMatrix", &pmatrix) <= 0 ||
 	read_matrix(mem, pmatrix, pmat) < 0
@@ -603,10 +601,24 @@
 	    memset(pomat, 0, sizeof(*pomat));
     }
     /* Use the FontInfo/OrigFontName key preferrentially (created by MS PSCRIPT driver) */
-    if ((dict_find_string((porigfont != NULL ? porigfont : op), "FontInfo", &pfontname) > 0) &&
-	r_has_type(pfontname, t_dictionary) &&
-        (dict_find_string(pfontname, "OrigFontName", &pfontname) > 0)) {
-	get_font_name(mem, pfname, pfontname);
+    if ((dict_find_string((porigfont != NULL ? porigfont : op), "FontInfo", &pfontinfo) > 0) &&
+	r_has_type(pfontinfo, t_dictionary) &&
+        (dict_find_string(pfontinfo, "OrigFontName", &pfontname) > 0)) {
+	if ((dict_find_string(pfontinfo, "OrigFontStyle", &pfontstyle) > 0) &&
+		r_size(pfontstyle) > 0) {
+	    const byte *tmpStr1 = pfontname->value.const_bytes;
+	    const byte *tmpStr2 = pfontstyle->value.const_bytes;
+	    int fssize1 = r_size(pfontname), fssize2 = r_size(pfontstyle), fssize = fssize1 + fssize2 + 1;
+	    byte *sfname = gs_alloc_string(mem, fssize, "sub_font_params");
+
+	    if (sfname == NULL)
+		return_error(e_VMerror);
+	    memcpy(sfname, tmpStr1, fssize1);
+	    sfname[fssize1]=',' ;
+	    memcpy(sfname + fssize1 + 1, tmpStr2, fssize2);
+	    make_string(pfname, a_readonly, fssize, sfname);
+	} else 
+	    get_font_name(mem, pfname, pfontname);
     } else if (dict_find_string((porigfont != NULL ? porigfont : op), ".Alias", &pfontname) > 0) {
         /* If we emulate the font, we want the requested name rather than a substitute. */
 	get_font_name(mem, pfname, pfontname);

Modified: trunk/gs/src/zfcid0.c
===================================================================
--- trunk/gs/src/zfcid0.c	2007-08-29 09:42:15 UTC (rev 8215)
+++ trunk/gs/src/zfcid0.c	2007-08-29 17:36:36 UTC (rev 8216)
@@ -494,8 +494,10 @@
     pfcid->cidata.FDBytes = FDBytes;
     pfcid->cidata.glyph_data = z9_glyph_data;
     pfcid->cidata.proc_data = 0;	/* for GC */
-    get_font_name(imemory, &cfnstr, &CIDFontName);
-    copy_font_name(&pfcid->font_name, &cfnstr);
+    if (pfcid->font_name.size == 0) {
+	get_font_name(imemory, &cfnstr, &CIDFontName);
+	copy_font_name(&pfcid->font_name, &cfnstr);
+    }
     ref_assign(&pfont_data(pfont)->u.cid0.GlyphDirectory, &GlyphDirectory);
     ref_assign(&pfont_data(pfont)->u.cid0.GlyphData, &GlyphData);
     ref_assign(&pfont_data(pfont)->u.cid0.DataSource, &DataSource);

Modified: trunk/gs/src/zfcid1.c
===================================================================
--- trunk/gs/src/zfcid1.c	2007-08-29 09:42:15 UTC (rev 8215)
+++ trunk/gs/src/zfcid1.c	2007-08-29 17:36:36 UTC (rev 8216)
@@ -347,8 +347,10 @@
     pfont->procs.glyph_info = z11_glyph_info;
     pfont->procs.glyph_outline = z11_glyph_outline;
     pfont->data.get_glyph_index = z11_get_glyph_index;
-    get_font_name(imemory, &cfnstr, &CIDFontName);
-    copy_font_name(&pfcid->font_name, &cfnstr);
+    if (pfcid->font_name.size == 0) {
+	get_font_name(imemory, &cfnstr, &CIDFontName);
+	copy_font_name(&pfcid->font_name, &cfnstr);
+    }
     if (MetricsCount) {
 	/* "Wrap" the glyph accessor procedures. */
 	pfcid->cidata.orig_procs.get_outline = pfont->data.get_outline;



More information about the gs-cvs mailing list