1 % Copyright (C) 1998, 2000 Aladdin Enterprises. All rights reserved.
3 % This software is provided AS-IS with no warranty, either express or
6 % This software is distributed under license and may not be copied,
7 % modified or distributed except as expressly authorized under the terms
8 % of the license contained in the file LICENSE in this distribution.
10 % For more information about licensing, please refer to
11 % http://www.ghostscript.com/licensing/. For information on
12 % commercial licensing, go to http://www.artifex.com/licensing/ or
13 % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14 % San Rafael, CA 94903, U.S.A., +1(415)492-9861.
16 % $Id: cid2code.ps,v 1.5 2002/02/21 21:49:28 giles Exp $
17 % Construct an inverse map from CIDs to codes.
19 % Create an inverse map from CIDs to code values.
20 % We only use this for 16-bit Unicode, so it has some limitations.
21 % After invoking .cmap2code, loading a CMap file prints out the map
22 % instead of doing what it usually does. For example:
24 % gs -dNODISPLAY -dBATCH lib/cid2code.ps -c .cmap2code\
25 % -f Resource/CMap/UniJIS-UCS2-H > mapfile
27 /.cmap2codedict 10 dict begin
33 % Stack: mark code_lo1 code_hi1 cid1 ...
35 /depth counttomark 3 sub def
36 % Do a first pass to determine the maximum CID.
39 d index d 2 add index 1 get add d 3 add index 1 get sub .max
42 /map ncid 2 mul string def
43 % Now fill in the map.
46 d index 2 mul /cid2 exch def
47 d 1 add index /hi exch def
48 d 2 add index 2 string copy /lo exch def
51 map cid2 1 add 3 -1 roll put
58 dup /ASCIIHexEncode filter
66 /endcodespacerange {cleartomark} def
70 /endbfchar {cleartomark} def
72 /endbfrange {cleartomark} def
76 counttomark 2 idiv { dup counttomark 1 add 3 roll } repeat pop
80 counttomark 1 add -1 roll pop
84 /endnotdefchar {cleartomark} def
86 /endnotdefrange {cleartomark} def
88 currentdict end readonly def
90 /.cmap2code { % - .cmap2code -
91 /CIDInit /ProcSet findresource dup length dict copy
92 .cmap2codedict { 3 copy put pop pop } forall
93 /CIDInit exch /ProcSet defineresource pop
96 % Extract and print reverse mapping information from a cid2code.txt file.
97 /.printhex2 { % <int16> .printhex2 -
99 16#10000 add 16 =string cvrs 1 4 getinterval print
102 /.cid2code { % <cmaptemplate> <file> <column> .cid2code -
107 (/CIDInit /ProcSet findresource begin 12 dict begin begincmap) =
108 % Print the information from the template.
110 exch ==only ( ) print
111 dup type /dicttype eq {
112 dup length =only ( dict dup begin) = {
113 ( ) print exch ===only ( ) print ===only ( def) =
119 % Read the data from the cid2code.txt file.
121 f =string readline pop (CID\t) anchorsearch { pop pop exit } if pop
124 f =string readline not { pop exit } if
125 column { (\t) search pop pop pop } repeat
126 (\t) search { exch pop exch pop } if
127 (,) search { exch pop exch pop } if
128 dup length 4 ne { pop (*) } if
129 dup (*) eq { pop (0000) } if
130 (16#) exch concatstrings cvi
132 % Print the code space range(s).
133 /maxcid map length 1 sub def
138 dup 16#ff00 and exch 0 2 index 1 sub
140 counttomark 2 idiv dup =only ( begincodespacerange) = {
141 exch .printhex2 .printhex2 () =
142 } repeat (endcodespacerange) =
143 % Print the map data.
146 /hi lo 99 add maxcid .min def
147 0 lo 1 hi { map exch get 0 ne { 1 add } if } for
151 =only ( begincidchar) = lo 1 hi {
152 map 1 index get dup 0 eq { pop pop } { exch .printhex2 = } ifelse
157 (endcmap CMapName currentdict /CMap defineresource pop end end) =