]> git.lizzy.rs Git - plan9front.git/blob - sys/lib/ghostscript/cid2code.ps
etherbcm: handle 64-bit host addresses, use PCIWADDR() instead of PADDR()
[plan9front.git] / sys / lib / ghostscript / cid2code.ps
1 %    Copyright (C) 1998, 2000 Aladdin Enterprises.  All rights reserved.
2
3 % This software is provided AS-IS with no warranty, either express or
4 % implied.
5
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.
9
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.
15
16 % $Id: cid2code.ps,v 1.5 2002/02/21 21:49:28 giles Exp $
17 % Construct an inverse map from CIDs to codes.
18
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:
23 %
24 %       gs -dNODISPLAY -dBATCH lib/cid2code.ps -c .cmap2code\
25 %         -f Resource/CMap/UniJIS-UCS2-H > mapfile
26
27 /.cmap2codedict 10 dict begin
28
29 /begincmap {
30   mark
31 } def
32 /endcmap {
33                 % Stack: mark code_lo1 code_hi1 cid1 ...
34   20 dict begin
35     /depth counttomark 3 sub def
36                 % Do a first pass to determine the maximum CID.
37     0 0 3 depth {
38       1 add /d exch def
39       d index d 2 add index 1 get add d 3 add index 1 get sub .max
40     } for
41     1 add /ncid exch def
42     /map ncid 2 mul string def
43                 % Now fill in the map.
44     0 3 depth {
45       /d exch def
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
49       lo 1 get 1 hi 1 get {
50         map cid2 lo 0 get put
51         map cid2 1 add 3 -1 roll put
52         /cid2 cid2 2 add def
53       } for
54     } for
55                 % Print the map.
56     (%stdout) (w) file
57       dup (<) print
58       dup /ASCIIHexEncode filter
59         dup map writestring
60       closefile
61       () = flush
62     closefile
63   end
64 } def
65 %/begincodespacerange
66 /endcodespacerange {cleartomark} def
67 %/usecmap
68
69 %/beginbfchar
70 /endbfchar {cleartomark} def
71 %/beginbfrange
72 /endbfrange {cleartomark} def
73
74 %/begincidchar
75 /endcidchar {
76   counttomark 2 idiv { dup counttomark 1 add 3 roll } repeat pop
77 } def
78 %/begincidrange
79 /endcidrange {
80   counttomark 1 add -1 roll pop
81 } def
82
83 %/beginnotdefchar
84 /endnotdefchar {cleartomark} def
85 %/beginnotdefrange
86 /endnotdefrange {cleartomark} def
87
88 currentdict end readonly def
89
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
94 } def
95
96 % Extract and print reverse mapping information from a cid2code.txt file.
97 /.printhex2 {           % <int16> .printhex2 -
98   (<) print
99   16#10000 add 16 =string cvrs 1 4 getinterval print
100   (>) print
101 } def
102 /.cid2code {            % <cmaptemplate> <file> <column> .cid2code -
103   30 dict begin
104   /column exch def
105   (r) file /f exch def
106   (%!) =
107   (/CIDInit /ProcSet findresource begin   12 dict begin   begincmap) =
108                 % Print the information from the template.
109   {
110     exch ==only ( ) print
111     dup type /dicttype eq {
112       dup length =only ( dict dup begin) = {
113         (  ) print exch ===only ( ) print ===only ( def) =
114       } forall (end def) =
115     } {
116       ===only
117     } ifelse ( def) =
118   } forall
119                 % Read the data from the cid2code.txt file.
120   {
121     f =string readline pop (CID\t) anchorsearch { pop pop exit } if pop
122   } loop
123   /map [ {
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
131   } loop ] def
132                 % Print the code space range(s).
133   /maxcid map length 1 sub def
134   mark maxcid
135   dup 255 and 255 eq {
136     0 exch
137   } {
138     dup 16#ff00 and exch 0 2 index 1 sub
139   } ifelse
140   counttomark 2 idiv dup =only ( begincodespacerange) = {
141     exch .printhex2 .printhex2 () =
142   } repeat (endcodespacerange) =
143                 % Print the map data.
144   0 1 100 maxcid {
145     /lo exch def
146     /hi lo 99 add maxcid .min def
147     0 lo 1 hi { map exch get 0 ne { 1 add } if } for
148     dup 0 eq {
149       pop
150     } {
151       =only ( begincidchar) = lo 1 hi {
152         map 1 index get dup 0 eq { pop pop } { exch .printhex2 = } ifelse
153       } for (endcidchar) =
154     } ifelse
155   } for
156                 % Wrap up.
157   (endcmap   CMapName currentdict /CMap defineresource pop   end   end) =
158   f closefile
159   end
160 } bind def