Bug 689956

Summary: Regression: substituting a TrueType font for a CID font is broken
Product: Ghostscript Reporter: Marcos H. Woehrmann <marcos.woehrmann>
Component: TextAssignee: Marcos H. Woehrmann <marcos.woehrmann>
Status: NOTIFIED FIXED    
Severity: normal    
Priority: P1    
Version: master   
Hardware: PC   
OS: Linux   
Customer: Word Size: ---

Description Marcos H. Woehrmann 2008-07-09 08:23:37 UTC
Starting with r8776 it is no longer possible to use a truetype font as a CIF
font as documented in cidfmap.

With the following entries in cidfmap

/Arial << /FileType /TrueType /Path (/home/marcos/artifex/fonts/arial.ttf)
/SubfontID 0 /CSI [(Unicode) 0] >> ;

/CenturyGothic << /FileType /TrueType /Path
(/home/marcos/artifex/fonts/arial.ttf) /SubfontID 0 /CSI [(Unicode) 0] >> ;

Ghostscript r8776 produces the following error:

Loading a TT font from /home/marcos/Desktop/artifex/leadtools/arial.ttf to
emulate a CID font CenturyGothic ... Done.
Error: /invalidfont in --.buildcidfont--
Operand stack:
   --nostringval--   --dict:8/17(L)--   C2_0   1   --dict:5/5(L)--  
--dict:5/5(L)--   CenturyGothic   --dict:11/12(ro)(G)--   --nostringval--  
CIDFontObject   --dict:7/7(L)--   --dict:7/7(L)--   CenturyGothic   CIDFont   -1
  true   CenturyGothic   CenturyGothic   CenturyGothic   --dict:26/26(G)--
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--  
--nostringval--   2   %stopped_push   --nostringval--   --nostringval--  
--nostringval--   false   1   %stopped_push   1905   1   3   %oparray_pop   1904
  1   3   %oparray_pop   1888   1   3   %oparray_pop   --nostringval--  
--nostringval--   3   1   2   --nostringval--   %for_pos_int_continue  
--nostringval--   --nostringval--   --nostringval--   --nostringval--  
%array_continue   --nostringval--   false   1   %stopped_push   --nostringval--
  %loop_continue   --nostringval--   --nostringval--   --nostringval--  
--nostringval--   --nostringval--   --nostringval--   %array_continue  
--nostringval--   --nostringval--   --nostringval--   --nostringval--  
--nostringval--   %loop_continue   --nostringval--   --nostringval--   1856   14
  9   %oparray_pop   findresource   %errorexec_pop   --nostringval--  
--nostringval--   --nostringval--   --nostringval--   --nostringval--   1864  
19   10   %oparray_pop   --nostringval--
Dictionary stack:
   --dict:1148/1684(ro)(G)--   --dict:1/20(G)--   --dict:75/200(L)--  
--dict:75/200(L)--   --dict:106/127(ro)(G)--   --dict:274/300(ro)(G)--  
--dict:24/25(L)--   --dict:4/6(L)--   --dict:28/40(L)--   --dict:20/26(ro)(G)--
Current allocation mode is local
Last OS error: 2
GPL Ghostscript SVN PRE-RELEASE 8.63: Unrecoverable error, exit code 1

The command line I'm using for testing:

bin/gs -I. -sDEVICE=ppmraw -sOutputFile=test.ppm -dBATCH -dNOPAUSE
./64_384_6_180_5a_682822_361223.pdf
Comment 1 Marcos H. Woehrmann 2008-07-09 08:24:20 UTC
Created attachment 4197 [details]
64_384_6_180_5a_682822_361223.pdf
Comment 2 Marcos H. Woehrmann 2008-07-09 08:26:35 UTC
This bug is related to bug 689623 (and the test file is the same).
Comment 3 Alex Cherepanov 2008-07-11 21:49:29 UTC
Current version can load TrueType font using cidfmap without PostScript
errors but the text is shown is incorrect. Rev. 8775 shows the same incorrect
text. So there's no regression now.

PDF interpreter can already load TrueType fonts as CIDFont resources.
This hack shows correct text in the sample file on my box.
So we need to scan FONTPATH and load a matching TrueType font the
same way as the embedded font stream.

--- E:\gs_svn\gs\lib\pdf_font.ps	2008-07-04 16:32:09.000000000 -0400
+++ pdf_font.ps	2008-07-12 00:29:38.000000000 -0400
@@ -1569,6 +1569,14 @@
             } if
           } if
         } if
+
+
+        dup //null eq {
+          pop
+          dup /FontFile2 << /F (c:/winnt/fonts/arial.ttf) >> put
+          dup /FontFile2 get
+        } if
+
                                           % /key res res desc stream
         dup //null ne {
           PDFfile fileposition 
Comment 4 Marcos H. Woehrmann 2008-07-21 13:15:28 UTC
Comment #3 is not correct; Ghostscript head (r8853) cannot load a TrueType font via cidfmap.  
Ghostscript 8.62 and earlier can.  If my comment #0 cidfmap file is incorrect please post a copy of one 
that works with gshead.
Comment 5 leonardo 2008-07-27 10:16:40 UTC
Returning to the author. Please check whether rev 8881 closes this one. If 
not, please attach the font file and assign to Leonardo.
Comment 6 Marcos H. Woehrmann 2008-07-28 12:54:55 UTC
Confirmed fixed in r8881.