Bug 689404

Summary: Regression: differences in 055-01.ps, 215-01.ps, 313-01.ps, 401-01.ps, 415-01.ps
Product: Ghostscript Reporter: Marcos H. Woehrmann <marcos.woehrmann>
Component: PS InterpreterAssignee: mpsuzuki <mpsuzuki>
Status: NOTIFIED FIXED    
Severity: normal CC: till.kamppeter
Priority: P4    
Version: master   
Hardware: PC   
OS: Linux   
Customer: Word Size: ---
Bug Depends on:    
Bug Blocks: 689304    
Attachments: patch for SVN revision 8185: fix bugs in gs8-cjk resource handler
patch for SVN revision 8185: patch to import cidfmap content
patch for SVN revision 8185: disable gs8-cjk resource handler

Description Marcos H. Woehrmann 2007-08-14 11:47:52 UTC
Starting with r8185 several of the FTS regression files are reporting "TEST
FAILED - undefined: resourceforall" or similar errors.
Comment 1 Till Kamppeter 2007-08-14 14:07:20 UTC
The bug is a regression caused by the CJK patches applied to fix bug 689304. In
rev 8190 I have removed the patches again.
Comment 2 mpsuzuki 2007-08-24 06:05:47 UTC
This bug may be rooted to PostScript resource handler of gs-cjk
in gs-7.07 (which is the base of Koji Otani's patch), the current
dictionary is unwritable in the procedure passed to resourceforall
operator. On the other hand, the original resource handler of
gs-7.07 (e.g. for /Font resource) didn't have such bug.

In current ghostscript:

$ gs -c "(*) { /tmp exch def } 100 string /CIDFont resourceforall"

is successfully finished.
But in gs-7.07, invalid access error occurs (/CIDFont only) aslike:

$ gs -c "(*) { /tmp exch def } 100 string /CIDFont resourceforall"

GNU Ghostscript 7.07 (2003-05-17)
Copyright (C) 2003 artofcode LLC, Benicia, CA.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
(IPA-Mincho)
Error: /invalidaccess in def
Operand stack:
   tmp   (IPA-Mincho)
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--  
--nostringval--   2   %stopped_push   --nostringval--   --nostringval--  
--nostringval--   false   1   %stopped_push   .runexec2   --nostringval--  
--nostringval--   --nostringval--   2   %stopped_push   --nostringval--   4   3
  %oparray_pop   --nostringval--   6   --nostringval--   false   1  
%stopped_push   --nostringval--   --nostringval--   %array_continue  
--nostringval--   --nostringval--
Dictionary stack:
   --dict:1057/1123(ro)(G)--   --dict:0/20(G)--   --dict:68/200(L)--  
--dict:16/24(ro)(G)--
Current allocation mode is local
Last OS error: 2
GNU Ghostscript 7.07: Unrecoverable error, exit code 1

--

However, gs8-cjk patch in ESP ghostscript has small typo that
makes resourceforall operator for /CIDFont category always
aborted (even if no writing access). Apply following fix:

--- lib/cjkv/cjkfnmap.ps.orig   2007-08-24 22:04:13.000000000 +0900
+++ lib/cjkv/cjkfnmap.ps        2007-08-24 22:04:59.000000000 +0900
@@ -279,7 +279,7 @@
 
   /.cjkv_CIDFontmapForAllKey {
     CJKV_DEBUG_FNMAP { (*** .cjkv_CIDFontmapForAllKey\n) print flush } if
-    [ /pop cvx 3 -1 roll /exec cvx ] cvx ._cjkv_CIDFontmapForAll
+    [ /pop cvx 3 -1 roll /exec cvx ] cvx .cjkv_CIDFontmapForAll
   } bind def
 currentdict
 end
Comment 3 mpsuzuki 2007-08-29 06:27:32 UTC
Created attachment 3328 [details]
patch for SVN revision 8185: fix bugs in gs8-cjk resource handler

By this patch, the regression tests have passed if CIDFnmap
is appropriately configured. This patch is applicable to
discontinued ESP-GS 8.15.x too.

# Type11 dict generated by gs8-cjk has /CIDFontName entry
# with string type. According to PostScript Refernce Manual,
# it should be nametype.

Index: lib/cjkv/cjkvttcf.ps
===================================================================
--- lib/cjkv/cjkvttcf.ps	(revision 8185)
+++ lib/cjkv/cjkvttcf.ps	(working copy)
@@ -59,7 +59,7 @@
   CJKV_DEBUG_TTCF { (--- making scratch dict...\n) print flush } if
   15 _cjkv_base_util /.cjkv_newdicttomark get exec
   CJKV_DEBUG_TTCF { (---			ok\n) print flush } if
-  dup /CIDFontName fontname dup length string copy put
+  dup /CIDFontName fontname dup length string copy cvn put
   CJKV_DEBUG_TTCF { (--- CIDFontName put ok\n) print flush } if
   dup /CIDFontType 2 put
   CJKV_DEBUG_TTCF { (--- CIDFontType put ok\n) print flush } if

# The pathname of CMap is restricted to 100 bytes, it can be too
# short, here it is extended to maximum in PostScript.
# This is not essential.

Index: lib/cjkv/tt11util.ps
===================================================================
--- lib/cjkv/tt11util.ps	(revision 8185)
+++ lib/cjkv/tt11util.ps	(working copy)
@@ -414,7 +414,7 @@
   .dicttomark def	   % .parsecmapdict
   
   
-  /.parsecmapfname 100 string def
+  /.parsecmapfname 65530 string def
   
   % <CMapName> .parsecmap <array>
   % Return the contents of the CMap.  If the CMap is not found, empty array

# 2 bugs are fixed.
# + ._cjkv_CIDFontmapForAll is a typo of .cjkv_CIDFontmapForAll
#   this is critical and breaks resourceforall procedure for CIDFont.
# + When /ResourceForAll procedure is executed, readonly gs8-cjk
#   dictionary is stacked to currentdict. The original current
#   dictionary is restored before user-defined procedure passed
#   to ResourceForAll. After the execution of user-defined procedure,
#   gs8-cjk dictionary is restacked.

Index: lib/cjkv/cjkfnmap.ps
===================================================================
--- lib/cjkv/cjkfnmap.ps	(revision 8185)
+++ lib/cjkv/cjkfnmap.ps	(working copy)
@@ -279,7 +357,7 @@
 
   /.cjkv_CIDFontmapForAllKey {
     CJKV_DEBUG_FNMAP { (*** .cjkv_CIDFontmapForAllKey\n) print flush } if
-    [ /pop cvx 3 -1 roll /exec cvx ] cvx ._cjkv_CIDFontmapForAll
+    [ /pop cvx 3 -1 roll /exec cvx ] cvx .cjkv_CIDFontmapForAll
   } bind def
 currentdict
 end
@@ -310,11 +388,19 @@
	 } ifelse
       } .cjkv_CIDFontmapForAllKey
     ]
+    % Here, CIDFont resource names matching given pattern are obtained.
+    % The current dictionary is unwritable gs-cjk /CIDFont resource
+    % handler (to use the procedure .cjkv_CIDFontmapForAllKey).
+    % The procedure for names expects to be executed with "vanilla"
+    % dictstack, so pop gs-cjk CIDFont resource handler from dictstack.
+    end
     exch setglobal
     4 -1 roll pop 3 1 roll [
       exch {cvs} aload pop 4 -1 roll aload pop
     ] cvx
     forall
+    % restore gs-cjk /CIDFont resource handler to dictstack
+    /CIDFont /Category findresource begin
   } put
 
   /.cjkv_loadcidfontresource {
Comment 4 mpsuzuki 2007-08-29 06:44:10 UTC
Created attachment 3329 [details]
patch for SVN revision 8185: patch to import cidfmap content

By this patch, TrueType font mapping rule by cidfmap is reflected
to gs8-cjk resources, without modification on gs_cidtt.ps.
This patch is also applicable to discontinued ESP-GS 8.15.x too.
Comment 5 mpsuzuki 2007-08-29 06:49:51 UTC
Created attachment 3330 [details]
patch for SVN revision 8185: disable gs8-cjk resource handler

On the other hand, simply ignoring gs8-cjk resource handler works,
although the modification on gs_cidtt.ps is essential. This patch
is not applicable to discontinued ESP-GS 8.15.x.

Index: lib/cjkv/cjkvinit.ps
===================================================================
--- lib/cjkv/cjkvinit.ps	(revision 8185)
+++ lib/cjkv/cjkvinit.ps	(working copy)
@@ -42,5 +42,5 @@
 (cjkv/tt42util.ps) runlibfile
 (cjkv/tt11util.ps) runlibfile
 (cjkv/cjkvttcf.ps) runlibfile
-(cjkv/cjkfnmap.ps) runlibfile
-(cjkv/cjkcidcm.ps) runlibfile
+% (cjkv/cjkfnmap.ps) runlibfile
+% (cjkv/cjkcidcm.ps) runlibfile