[gs-cvs] rev 8509 - in trunk/gs: lib src

mpsuzuki at ghostscript.com mpsuzuki at ghostscript.com
Mon Jan 28 02:31:45 PST 2008


Author: mpsuzuki
Date: 2008-01-28 02:31:45 -0800 (Mon, 28 Jan 2008)
New Revision: 8509

Modified:
   trunk/gs/lib/pdf_font.ps
   trunk/gs/src/zfont.c
Log:
Fix: ignore the embedded font resource when PDF interpreter resolves
     the unembedded font resource.

DETAILS:

Some PDF generators (e.g. Microsoft Office 2007 add-on to export the
documents to PDF format) emits incompatible font objects with same
resource name. The sample PDF in bug 689637 includes 2 "Times New
Roman" font objects: one is embedded CID-keyed TrueType for Cyrillic
glyphs, another is unembedded WinAnsiEncoding TrueType (possibly for
empty page header or footer). When PDF interpreter resolves latter
unembedded "Times New Roman", external font resource should be used
(Adobe Reader does so). But current Ghostscript uses former embedded
"Times New Roman", because the sample PDF includes "Times New Roman"
without randomization prefix.

To avoid the confusion between embedded and unembedded fonts with
same name, pfont->is_resource flag (=0 embedded, =1 unembedded)
is checked during font object resolution. Even if a cached font
object with same name is found, it is ignored if it is embedded
font. To execute this check in PostScript space (pdf_font.ps),
new operator ".isregisteredfont" is introduced. This patch assumes
that embedded font object in PDF is resolvable by tracking the
indirect object references. If a PDF assumes name-based resolution
of embedded font object (without indirect object), it may be
rendered by external font resource. At present, we don't have
such sample.

By this patch, bug 689637 is fixed.

EXPECTED DIFFERENCES:

None.


Modified: trunk/gs/lib/pdf_font.ps
===================================================================
--- trunk/gs/lib/pdf_font.ps	2008-01-28 09:58:54 UTC (rev 8508)
+++ trunk/gs/lib/pdf_font.ps	2008-01-28 10:31:45 UTC (rev 8509)
@@ -586,8 +586,17 @@
 		% If the font isn't available, synthesize one based on
 		% its descriptor.
   dup /Font resourcestatus {
-    pop pop pdffindcachedfont
+    pop pop dup pdffindcachedfont
+    dup .isregisteredfont
+    % <font-resource> <fontname> <font> true	% font preloaded from disk
+    % <font-resource> <fontname> <font> false	% font preloaded from document
+    { exch pop false } { pop true } ifelse
   } {
+    true
+  } ifelse
+  % <font-resource> <font> false	% font preloaded from disk
+  % <font-resource> <fontname> true	% font not loaded yet or embedded
+  {
     1 index /FontDescriptor knownoget {
 		% Stack: font-res fontname fontdesc
       dup /Flags oget
@@ -659,7 +668,7 @@
 		% No descriptor available, use the default algorithm.
       pdffindcachedfont
     } ifelse
-  } ifelse
+  } if
   exch pop
 } bdef
 

Modified: trunk/gs/src/zfont.c
===================================================================
--- trunk/gs/src/zfont.c	2008-01-28 09:58:54 UTC (rev 8508)
+++ trunk/gs/src/zfont.c	2008-01-28 10:31:45 UTC (rev 8509)
@@ -208,7 +208,21 @@
     return 0;
 }
 
+/* <font> .isregisteredfont <bool> */
+static int
+zisregisteredfont(i_ctx_t *i_ctx_p)
+{
+    os_ptr op = osp;
+    gs_font *pfont;
+    int code = font_param(op, &pfont);
 
+    if (code < 0)
+	return code;
+    make_bool(op, pfont->is_resource);
+    return 0;
+}
+
+
 /* <Decoding> .setupUnicodeDecoder - */
 static int
 zsetupUnicodeDecoder(i_ctx_t *i_ctx_p)
@@ -237,6 +251,7 @@
     {"1setcacheparams", zsetcacheparams},
     {"0currentcacheparams", zcurrentcacheparams},
     {"1.registerfont", zregisterfont},
+    {"1.isregisteredfont", zisregisteredfont},
     {"1.setupUnicodeDecoder", zsetupUnicodeDecoder},
     op_def_end(zfont_init)
 };



More information about the gs-cvs mailing list