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

alexcher at ghostscript.com alexcher at ghostscript.com
Fri Apr 18 20:43:22 PDT 2008


Author: alexcher
Date: 2008-04-18 20:43:21 -0700 (Fri, 18 Apr 2008)
New Revision: 8646

Modified:
   trunk/gs/lib/gs_cff.ps
   trunk/gs/lib/pdf_font.ps
   trunk/gs/lib/pdf_ops.ps
Log:
Implement loading of OpenType CFF font as a CIDFont resource in PDF reader.
Bug 689763, customers 531, 850.

DETAILS:
PDF can use OpenType font with ordinary CFF data as a CIDFont. Such a font is
referenced by /CIDFontType2 and may have /CIDToGIDMap table. The following
changes have been done to support this usage.

- A flag that forces CIDFont generation was added to CFF font loader.
- When the flag is on, CFF font is converted to a Type 9 CIDFont.
- The FontSet resource is returned by the value from the font loader
  because it can be of either Font or CIDFont type,
- Since CIDMap has no effect on CIDFont Type 9, CIDToGIDMap is interpreted
  by PDF reader to modify GlyphDirectory to the same effect.
- Unused CIDMap is no longer generated for CIDFontType2 objects that are not
  TrueType CIDFont resources.

DIFFERENCES:
None


Modified: trunk/gs/lib/gs_cff.ps
===================================================================
--- trunk/gs/lib/gs_cff.ps	2008-04-17 17:40:05 UTC (rev 8645)
+++ trunk/gs/lib/gs_cff.ps	2008-04-19 03:43:21 UTC (rev 8646)
@@ -41,8 +41,8 @@
 		% If this is a font at all, it's an OpenType CFF font set.
     .init_otto_font_file
 	% Use a random FontSet resource name.  ****** WRONG ******
-    realtime rand xor =string cvs exch false
-    ReadData
+    realtime rand xor =string cvs exch //false //false
+    ReadData pop
   } {
 		% Not a TrueType font.
     .loadnonottofontfile
@@ -663,19 +663,56 @@
   currentdict /FDSelect undef
   cleanupFont
 } bind def
+
+% PDF may load OpenType font containing ordinary CFF data as a CIDFont.
+% Convert the ordinary font to a CIDFont.
+/makeCIDFont {        % (currentdict) finishCIDFont -
+  /CIDFontType 0 def
+  /FDBytes 0 def
+  /GDBytes 0 def
+  /CIDMapOffset 0 def
+
+  /CIDSystemInfo 3 dict begin  % bogus
+    /Registry   (Adobe) def
+    /Ordering   (Identity) def
+    /Supplement 0 def
+  currentdict end def
+
+  /FDArray 4 dict begin
+    /FontMatrix dup load { 1000 0 0 1000 0 0 } matrix concatmatrix def
+    /Private    dup load def
+    /FontType   dup load def
+    /PaintType  dup load def
+  currentdict end 1 array astore def
+
+  /FontType 9 def
+
+  /GlyphDirectory CharStringArray def
+  /CIDCount GlyphDirectory length def
+
+  Private /GlobalSubrs undef
+  currentdict /Encoding undef
+  currentdict /CharStrings undef
+  currentdict /UniqueID undef
+  currentdict /XUID undef
+  cleanupFont
+} bind def
+
 % We need to pass the file as a parameter for the sake of the PDF
 % interpreter. Also for the sake of PDF, a flag forces the font
 % to be defined as <resname> instead of the name embedded in the data.
 % This is needed for subsetted fonts; it is valid if the CFF
 % contains only a single font.
+% Finally, PDF interpreter may request creation of CIDFont out of an
+% ordinary CFF font.
 /StartData {          % <resname> <nbytes> StartData -
-  currentfile exch subfilefilter false ReadData
+  currentfile exch subfilefilter //false //false ReadData pop
 } bind def
-/ReadData {           % <resname> <file> <forceresname> ReadData -
-
+/ReadData {           % <resname> <file> <forceresname> <forcecid> ReadData <fontset>
 	% Initialize.
 
   30 dict begin
+  /forcecidfont exch def
   /forceresname exch def
   /cff exch def
   /pos 0 def
@@ -759,7 +796,11 @@
 
   fonts {
     begin
-    currentdict /CIDFontType known { finishCIDFont } { finishFont } ifelse
+    currentdict /CIDFontType known {
+      finishCIDFont
+    } {
+      forcecidfont //makeCIDFont //finishFont ifelse
+    } ifelse
     end
   } forall
 
@@ -783,7 +824,7 @@
   } for .dicttomark
   end		% temporary dict
   end		% FontSetInit ProcSet
-  /FontSet defineresource pop
+  /FontSet defineresource
 
 } bind def
 

Modified: trunk/gs/lib/pdf_font.ps
===================================================================
--- trunk/gs/lib/pdf_font.ps	2008-04-17 17:40:05 UTC (rev 8645)
+++ trunk/gs/lib/pdf_font.ps	2008-04-19 03:43:21 UTC (rev 8646)
@@ -1354,7 +1354,9 @@
 % Adjust a CIDFontType2 DW[2] and CIDToGIDMap in the font resource.
 /adjustCIDType2 {		% <font-resource> <font> adjustfont <font'>
   addCIDmetrics
-  processCIDToGIDMap
+  dup /CIDFontType get 2 eq {   % OpenType CFF font converts to CIDFontType 0
+    processCIDToGIDMap          %  that ignores CIDMap.
+  } if
   dup /CIDFontName get exch /CIDFont defineresource
 } bind def
 
@@ -1398,17 +1400,60 @@
 
 % Read an embedded OpenType font.
 /readOTTOfont {		% <font-resource> <stream-dict> readOTTOfont <font>
-  1 index exch
-  PDFfile fileposition 3 1 roll
-  dup true resolvestream dup readfontfilter
-		% Stack: pos resource streamdict stream filter
-  3 index /FontDescriptor oget /FontName oget
-  1 index
-  .init_otto_font_file //true ReadData
-  closefile closefile pop
-  PDFfile 3 -1 roll setfileposition
-  /FontDescriptor oget /FontName oget pdfaddcachedfont
-  exch pop
+  1 index exch                    % res res strdict
+  PDFfile fileposition 3 1 roll   % res pos res strdict
+  dup //true resolvestream        % res pos res strdict stream
+  dup readfontfilter              % res pos res strdict stream filter
+  3 index /FontDescriptor oget
+  /FontName oget                  % res pos res strdict stream filter /name
+  1 index .init_otto_font_file    % res pos res strdict stream filter /name filter'
+  //true
+  6 index /CIDSystemInfo known    % res pos res strdict stream filter /name filter' bool bool
+  ReadData                        % res pos res strdict stream filter fontset
+  { exch pop exit } forall        % res pos res strdict stream filter font
+  dup /FontType get 9 eq  {
+    % OpenType may contain simple CFF font, which is accesed as a CIDFont by PDF.
+    % The font is converted to Type 9 CIDFont resource, which ignores CIDMap attribute.
+    % The following code just shuffles GlyphDirectory to the same effect.
+    4 index /CIDToGIDMap knownoget {
+      dup type /dicttype eq {
+        1 index /GlyphDirectory get exch       % res pos res strdict stream filter font dir c2g
+        //true resolvestream                   % res pos res strdict stream filter font dir c2g_file
+        256 dict begin
+        0 2 index 0 get def  % copy .notdef
+        0 1 16#7fffffff {
+          1 index read not { pop exit } if     % res pos res strdict stream filter font dir c2g_file cid hi
+          256 mul                              % res pos res strdict stream filter font dir c2g_file cid hi
+          2 index read not { pop pop exit } if % res pos res strdict stream filter font dir c2g_file cid hi lo
+          add                                  % res pos res strdict stream filter font dir c2g_file cid gid
+          dup 0 ne {
+            dup 4 index length lt {
+              3 index exch get                 % res pos res strdict stream filter font dir c2g_file cid charstr
+              def                              % res pos res strdict stream filter font dir c2g_file
+            } {
+              pop pop
+            } ifelse
+          } {
+            pop pop
+          } ifelse
+        } for
+        closefile pop                          % res pos res strdict stream filter font
+        dup length dict copy                   % res pos res strdict stream filter font'
+        dup /GlyphDirectory currentdict put    % res pos res strdict stream filter font'
+        end
+        dup /GlyphDirectory get 0 exch {
+          pop .max
+        } forall
+        1 index exch /CIDCount exch 1 add put
+      } {
+      pop
+      } ifelse
+    } if
+  } if
+  7 1 roll                        % font res pos res strdict stream filter
+  closefile closefile pop pop     % font res pos
+  PDFfile exch setfileposition    % font res
+  pop                             % font
 } bdef
 
 % ---------------- Font lookup ---------------- %

Modified: trunk/gs/lib/pdf_ops.ps
===================================================================
--- trunk/gs/lib/pdf_ops.ps	2008-04-17 17:40:05 UTC (rev 8645)
+++ trunk/gs/lib/pdf_ops.ps	2008-04-19 03:43:21 UTC (rev 8646)
@@ -543,7 +543,7 @@
 
 % Read a CFF font.
 /FRD		% <resname> <file> FRD -
- { /FontSetInit /ProcSet findresource begin //true ReadData
+ { /FontSetInit /ProcSet findresource begin //true //false ReadData pop
  } bdef
 
 % Copy a font, removing its FID.  If changed is true, also remove



More information about the gs-cvs mailing list