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 9213 2008-11-09 20:38:08Z leonardo $
17
% Define SubstCID, 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
98
2 copy get % b [Range] I1 e
100
% We've got char code duplicates for same CID.
101
dup type /integertype eq {
102
4 3 roll % [Range] I1 e b
105
dup length 1 add dup dup array dup % b [Range] I1 D l l D' D'
106
3 2 roll 0 exch getinterval % b [Range] I1 D l D' D''
107
4 3 roll exch copy pop % b [Range] I1 l D'
108
dup 3 2 roll 1 sub % b [Range] I1 D' D' l-1
109
6 5 roll % [Range] I1 D' D' l-1 b
118
{ % Writes the inversed CMap to .Ranges
119
counttomark 3 idiv { % (b) (e) I
120
exch .StringToInt % (b) I e
121
3 2 roll .StringToInt % I e b
122
% Note : this code does't handle multidimentional CID ranges.
123
% fixme : optimize below.
124
dup 3 2 roll exch sub 1 add % I b d
125
{ 2 copy //.SetCouple exec % I b
126
1 add exch 1 add exch
129
dup //.Ranges /CIDCount get gt { % I
130
dup //.Ranges exch /CIDCount exch put
137
/.GetCIDDecoding % - .GetCIDDEcoding <dict>
138
{ //.Ranges dup length dict copy
139
//.Ranges //.PurgeDict exec
140
//.Ranges /CIDCount 0 put
144
exch copy % Merge the dicts - see above.
145
/ProcSet defineresource pop
147
%----------------CIDDecoding category----------------------------
148
% Note that we put all instances in global memory - see FindResource.
150
/Generic /Category findresource dup length dict copy
152
/Category /CIDDecoding def
153
/InstanceType /dicttype def
156
% This lists CMaps to inverse and unite for creating a CIDDecoding.
157
% Choose by FAPIcidfmap.Registry concatenated with TrueType encoding ID.
158
% Font renderer must provide the glyph substitution internally.
160
/CNS1.Big5 [ /ETen-B5-H /ETen-B5-V ]
161
/CNS1.Unicode [ /UniCNS-UCS2-H /UniCNS-UCS2-V]
162
/GB1.GB2312 [ /GBK-EUC-H /GBK-EUC-V ]
163
/GB1.Unicode [ /UniGB-UCS2-H /UniGB-UCS2-V ]
164
/Japan1.ShiftJIS [ /90ms-RKSJ-H /90ms-RKSJ-V ]
165
/Japan1.Unicode [ /UniJIS-UCS2-H /UniJIS-UCS2-V]
166
/Japan2.ShiftJIS [ /90ms-RKSJ-H /90ms-RKSJ-V ]
167
/Japan2.Unicode [ /UniHojo-UCS2-H ]
168
/Korea1.Johab [ /KSC-Johab-V /KSC-Johab-H ]
169
/Korea1.Wansung [ /KSCms-UHC-V /KSCms-UHC-H ]
170
/Korea1.Unicode [ /UniKS-UCS2-H /UniKS-UCS2-V ]
171
/Identity.Symbol [ /Identity-H /Identity-V ]
172
/Unicode.Unicode [ /Identity-UTF16-H ]
175
/.MakeInstance % <name> .MakeInstance <inst>
177
//.CMapChooser exch .knownget not {
178
(Can't build /) print =string cvs print ( /CIDDecoding resource. See gs_ciddc.ps . ) =
179
/findresource cvx /undefinedresource signalerror
182
/CMap /Category findresource % [CMaps] <CMapCategory>
183
/ParseCMap_Inverse /ProcSet findresource % [CMaps] <CMapCategory> <PCI>
184
3 2 roll { % <CMapCategory> <PCI> /CMapName
185
3 2 roll begin % <PCI> /CMapName
186
dup .ResourceFile not {
187
(Can't find CMap ) print =string cvs print ( building a CIDDecoding resource. ) =
188
/findresource cvx /undefinedresource signalerror
190
currentdict end exch % <PCI> /CMapName <CMapCategory> file
193
cvx exec % <PCI> /CMapName <CMapCategory>
195
exch pop exch % <CMapCategory> <PCI>
202
/FindResource % <name> FindResource <dict>
203
{ currentglobal exch % bGlobal /InstName
205
dup //.MakeInstance exec % bGlobal /InstName <Inst>
206
DefineResource % bGlobal <Inst>
207
exch setglobal % <Inst>
211
/CIDDecoding exch /Category defineresource pop
213
%----------------SubstCID category----------------------------
215
/Generic /Category findresource dup length dict copy
217
/Category /SubstCID def
218
/InstanceType /dicttype def
220
/SubstCID exch /Category defineresource pop