1 % Copyright (C) 1994, 1996, 1997, 1998, 1999, 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: gs_ciddc.ps,v 1.14 2005/01/20 00:26:06 ray Exp $
17 % Define Decoding and CIDDecoding resource categories and related procsets.
19 languagelevel 2 .setlanguagelevel
20 currentglobal true setglobal
22 %----------------ParseDecoding procset----------------------------
26 /Parse % <resource_name> <num_tokens> Parse -
27 { dict begin % /ResName
29 { currentfile token not {
31 } if % /ResName nCode token
32 dup type /integertype eq { % /ResName nCode
35 1 index def % /ResName nCode
37 } loop % /ResName nCode
39 currentdict end /Decoding % /ResName <<inst>> /Decoding
43 >> /ProcSet defineresource pop
45 %----------------Decoding category----------------------------
47 /Generic /Category findresource dup length dict copy
48 dup /InstanceType /dicttype put
49 /Decoding exch /Category defineresource pop
51 %----------------ParseCMap_Inverse procset----------------------------
54 /findresource { pop } bind
55 /defineresource { pop pop } bind
66 /begincodespacerange { pop mark } bind
67 /endcodespacerange { cleartomark } bind
68 /beginnotdefrange { pop mark } bind
69 /endnotdefrange { cleartomark } bind
70 /beginbfchar { pop mark } bind
71 /endbfchar { pop mark } bind
72 /beginbfrange { begincidrange }
73 /endbfrange { endcidrange }
74 /begincidchar { beginbfchar }
75 /endcidchar { endbfchar }
76 /begincidrange { pop mark } bind
77 /endcidrange { cleartomark } bind
78 >> % Just keep it on stack for a while.
80 % Now we define another dict for local binding, than merge it with the previous one :
81 dup length 5 add dict begin
83 /.Ranges 40 dict def % Key = CID/256, value = array of 256 integer codes.
84 //.Ranges /CIDCount 0 put
86 /.StringToInt % <string> .StringToInt <integer>
87 { 0 exch { exch 8 bitshift add } forall
90 /.SetCouple % <I> <b> .SetCouple -
93 dup //.Ranges exch known not {
94 dup //.Ranges exch 256 array put
96 //.Ranges exch get % b I [Range]
97 exch 256 mod % b [Range] I1
102 { % Writes the inversed CMap to .Ranges
103 counttomark 3 idiv { % (b) (e) I
104 exch .StringToInt % (b) I e
105 3 2 roll .StringToInt % I e b
106 % Note : this code does't handle multidimentional CID ranges.
107 % fixme : optimize below.
108 dup 3 2 roll exch sub 1 add % I b d
109 { 2 copy //.SetCouple exec % I b
110 1 add exch 1 add exch
113 dup //.Ranges /CIDCount get gt { % I
114 dup //.Ranges exch /CIDCount exch put
121 /.GetCIDDecoding % - .GetCIDDEcoding <dict>
122 { //.Ranges dup length dict copy
123 //.Ranges //.PurgeDict exec
124 //.Ranges /CIDCount 0 put
128 exch copy % Merge the dicts - see above.
129 /ProcSet defineresource pop
131 %----------------CIDDecoding category----------------------------
132 % Note that we put all instances in global memory - see FindResource.
134 /Generic /Category findresource dup length dict copy
136 /Category /CIDDecoding def
137 /InstanceType /dicttype def
140 % This lists CMaps to inverse and unite for creating a CIDDecoding.
141 % Choose by FAPIcidfmap.Registry concatenated with TrueType encoding ID.
142 % Font renderer must provide the glyph substitution internally.
144 /CNS1.Big5 [ /ETen-B5-H /ETen-B5-V ]
145 /CNS1.Unicode [ /UniCNS-UCS2-H /UniCNS-UCS2-V]
146 /GB1.GB2312 [ /GBK-EUC-H /GBK-EUC-V ]
147 /GB1.Unicode [ /UniGB-UCS2-H /UniGB-UCS2-V ]
148 /Japan1.ShiftJIS [ /90ms-RKSJ-H /90ms-RKSJ-V ]
149 /Japan1.Unicode [ /UniJIS-UCS2-H /UniJIS-UCS2-V]
150 /Japan2.ShiftJIS [ /90ms-RKSJ-H /90ms-RKSJ-V ]
151 /Japan2.Unicode [ /UniHojo-UCS2-H ]
152 /Korea1.Johab [ /KSC-Johab-V /KSC-Johab-H ]
153 /Korea1.Wansung [ /KSCms-UHC-V /KSCms-UHC-H ]
154 /Korea1.Unicode [ /UniKS-UCS2-H /UniKS-UCS2-V ]
155 /Identity.Symbol [ /Identity-H /Identity-V ]
158 /.MakeInstance % <name> .MakeInstance <inst>
160 //.CMapChooser exch .knownget not {
161 (Can't build /) print =string cvs print ( /CIDDecoding resource. See gs_ciddc.ps . ) =
162 /findresource cvx /undefinedresource signalerror
165 /CMap /Category findresource % [CMaps] <CMapCategory>
166 /ParseCMap_Inverse /ProcSet findresource % [CMaps] <CMapCategory> <PCI>
167 3 2 roll { % <CMapCategory> <PCI> /CMapName
168 3 2 roll begin % <PCI> /CMapName
169 dup .ResourceFile not {
170 (Can't find CMap ) print =string cvs print ( building a CIDDecoding resource. ) =
171 /findresource cvx /undefinedresource signalerror
173 currentdict end exch % <PCI> /CMapName <CMapCategory> file
176 cvx exec % <PCI> /CMapName <CMapCategory>
178 exch pop exch % <CMapCategory> <PCI>
185 /FindResource % <name> FindResource <dict>
186 { currentglobal exch % bGlobal /InstName
188 dup //.MakeInstance exec % bGlobal /InstName <Inst>
189 DefineResource % bGlobal <Inst>
190 exch setglobal % <Inst>
194 /CIDDecoding exch /Category defineresource pop