[gs-cvs] rev 8772 - trunk/gs/lib

alexcher at ghostscript.com alexcher at ghostscript.com
Thu May 22 22:05:20 PDT 2008


Author: alexcher
Date: 2008-05-22 22:05:20 -0700 (Thu, 22 May 2008)
New Revision: 8772

Modified:
   trunk/gs/lib/pdf_font.ps
   trunk/gs/lib/pdf_ops.ps
Log:
Use embedded PDF fonts directly. Don't define them as resources and look them
up later by the name. Leave findfont operator for fetching non-embedded fonts
only, which are now unaffected by embedded fonts. Bugs 689510, 689514 from
customer 700.

DETAILS:
CIDFont resources should be handled in a similar way but this part
is not yet implemented.

DIFFERENCES:
None.


Modified: trunk/gs/lib/pdf_font.ps
===================================================================
--- trunk/gs/lib/pdf_font.ps	2008-05-23 00:13:50 UTC (rev 8771)
+++ trunk/gs/lib/pdf_font.ps	2008-05-23 05:05:20 UTC (rev 8772)
@@ -16,6 +16,12 @@
 % $Id$
 % PDF font operations.
 
+% Since PDF font are not unique and can collide with external font resources
+% or each other, use font dictionaries obtained from PDF directly, never
+% register them as resources or look them up by name. Use findfont oparator
+% for non-embedded fonts only. CIDFont resources still use the old logic
+% described below.
+
 % Finding a font by name can't give a proper result when PDF font names aren't unique.
 % But it is only the way to obtain a font in Postscript after a font file is executed.
 % Therefore using a FontName (and findfont) is allowed only
@@ -126,7 +132,7 @@
 /adjustfont {		% <font-resource> <font> adjustfont <font'>
   getfontencoding
   3 copy .processToUnicode
-  getfontmetrics 5 -1 roll pop .updatefont { dup /FontName get exch definefont } if
+  getfontmetrics 5 -1 roll pop .updatefont { .completefont } if
 } bind def
 
 % Get the (possibly modified) encoding of a font.
@@ -672,7 +678,7 @@
         true .copyfontdict
         2 copy exch /FontName exch put
       } if
-      definefont
+      exch pop .completefont
     } {
 		% No descriptor available, use the default algorithm.
       pdffindcachedfont
@@ -706,11 +712,8 @@
 
 /readtype1dict 5 dict dup begin
   /definefont {
-    dup topFontDict eq topFontDict null eq or {
-      dup wcheck not { dup length dict copy } if
-      exch pop savedFontName exch
-    } if
-    //systemdict /definefont get exec
+    exch pop
+    .completefont
   } bdef
 
   /undef_proc_warning {
@@ -780,22 +783,17 @@
                 % Also restore dictstack depth.
                 % 
    //systemdict begin
-		% The PDF specification is somewhat muddy about whether
-		% an embedded font's name is supposed to be the BaseFont
-		% from the Font object or the FontName from the descriptor.
-		% Acrobat Distiller requires the former.  Save away the
-		% name so we can substitute it at definefont time.
    //readtype1dict dup length 3 add dict copy begin
    1 index /BaseFont oget /savedFontName exch def
    /topFontDict null def
    /readtype1dictcopy currentdict def
     { cvx exec } aload pop count 2 sub 3 packedarray cvx exec
     % clean up the dictstack
-    { currentdict /topFontDict known not { end } { end end exit } ifelse } loop
+    { currentdict /topFontDict known not { end } { exit } ifelse } loop
    count exch sub { pop } repeat
    PDFfile 3 -1 roll setfileposition
-   /BaseFont oget pdfaddcachedfont
-   exch pop
+   pop pop
+   currentdict end end /topFontDict get
  } bdef
 
 % ---------------- Type 3 fonts ---------------- %
@@ -857,7 +855,7 @@
       end end
     } bdef
     dup currentdict Encoding .processToUnicode
-    FontName currentdict end definefont exch pop
+    currentdict end .completefont exch pop
 } bdef
 /.adjustcharwidth {	% <wx> <wy> .adjustcharwidth <wx'> <wy'>
   % Enforce the metrics, in glyph space, to the values found in the PDF Font object
@@ -904,7 +902,7 @@
     exch 3 1 roll pdffindfont
     true .copyfontdict
     2 copy exch /FontName exch put
-    definefont
+    exch pop .completefont
   } {
     pdffindfont
   } ifelse
@@ -1001,10 +999,11 @@
   .composefontdict  % composefont must insert FontInfo dictionary - see gs_cmap.ps .
 		    % Stack: fontres name font
   3 copy exch pop null .processToUnicode
-  /Font defineresource   % Stack: fontres font
+  exch pop .completefont % Stack: fontres font
   1 index /FontMatrix knownoget {
     dup aload pop true {0 0 1 0 0 1} {3 -1 roll eq and} forall {
-      1 index exch makefont exch /FontName get exch definefont
+      1 index exch makefont exch /FontName get exch 
+      exch pop .completefont
     } {
       pop
     } ifelse
@@ -1383,11 +1382,13 @@
   dup true resolvestream dup readfontfilter
 		% Stack: pos resource streamdict stream filter
   3 index /FontDescriptor oget /FontName oget
-  1 index FRD
+  1 index 
+  /FontSetInit /ProcSet findresource begin //true //false ReadData
+  { exch pop exit } forall
+  7 1 roll
   closefile closefile pop
   PDFfile 3 -1 roll setfileposition
-  /FontDescriptor oget /FontName oget pdfaddcachedfont
-  exch pop
+  pop pop
 } bdef
 
 % Read an embedded CFF CIDFont.
@@ -1396,7 +1397,8 @@
   dup true resolvestream dup readfontfilter
 		% Stack: pos resource streamdict stream filter
   3 index /FontDescriptor oget /FontName oget
-  1 index FRD
+  1 index 
+  /FontSetInit /ProcSet findresource begin //true //false ReadData pop
   closefile closefile pop
   PDFfile 3 -1 roll setfileposition
 		% Some broken Adobe software produces PDF files in which

Modified: trunk/gs/lib/pdf_ops.ps
===================================================================
--- trunk/gs/lib/pdf_ops.ps	2008-05-23 00:13:50 UTC (rev 8771)
+++ trunk/gs/lib/pdf_ops.ps	2008-05-23 05:05:20 UTC (rev 8772)
@@ -542,11 +542,6 @@
   /TextFont gput settextstate
 } bdef
 
-% Read a CFF font.
-/FRD		% <resname> <file> FRD -
- { /FontSetInit /ProcSet findresource begin //true //false ReadData pop
- } bdef
-
 % Copy a font, removing its FID.  If changed is true, also remove
 % the UniqueID and XUID, if any.  If the original dictionary doesn't have
 % the keys being removed, don't copy it.



More information about the gs-cvs mailing list