| 1 |
% Copyright (C) 2001-2023 Artifex Software, Inc. |
| 2 |
% All Rights Reserved. |
| 3 |
% |
| 4 |
% This software is provided AS-IS with no warranty, either express or |
| 5 |
% implied. |
| 6 |
% |
| 7 |
% This software is distributed under license and may not be copied, |
| 8 |
% modified or distributed except as expressly authorized under the terms |
| 9 |
% of the license contained in the file LICENSE in this distribution. |
| 10 |
% |
| 11 |
% Refer to licensing information at http://www.artifex.com or contact |
| 12 |
% Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, |
| 13 |
% CA 94129, USA, for further information. |
| 14 |
% |
| 15 |
|
| 16 |
% Define SubstCID, Decoding and CIDDecoding resource categories and related procsets. |
| 17 |
|
| 18 |
languagelevel 2 .setlanguagelevel |
| 19 |
currentglobal //true setglobal |
| 20 |
|
| 21 |
%----------------ParseDecoding procset---------------------------- |
| 22 |
|
| 23 |
/ParseDecoding << |
| 24 |
|
| 25 |
/Parse % <resource_name> <num_tokens> Parse - |
| 26 |
{ dict begin % /ResName |
| 27 |
0 % /ResName nCode |
| 28 |
{ currentfile token not { |
| 29 |
exit |
| 30 |
} if % /ResName nCode token |
| 31 |
dup type /integertype eq { % /ResName nCode |
| 32 |
exch pop |
| 33 |
} { |
| 34 |
1 index def % /ResName nCode |
| 35 |
} ifelse |
| 36 |
} loop % /ResName nCode |
| 37 |
pop % /ResName |
| 38 |
currentdict end /Decoding % /ResName <<inst>> /Decoding |
| 39 |
defineresource pop |
| 40 |
} .internalbind |
| 41 |
|
| 42 |
>> /ProcSet defineresource pop |
| 43 |
|
| 44 |
%----------------Decoding category---------------------------- |
| 45 |
|
| 46 |
/Generic /Category findresource dup length dict copy |
| 47 |
dup /InstanceType /dicttype put |
| 48 |
/Decoding exch /Category defineresource pop |
| 49 |
|
| 50 |
%----------------ParseCMap_Inverse procset---------------------------- |
| 51 |
|
| 52 |
/ParseCMap_Inverse << |
| 53 |
/findresource { pop } .internalbind |
| 54 |
/defineresource { pop pop } .internalbind |
| 55 |
/dict {} |
| 56 |
/def { pop pop } .internalbind |
| 57 |
/dup //null |
| 58 |
/begin { pop } .internalbind |
| 59 |
/end {} |
| 60 |
/currentdict //null |
| 61 |
/CMapName //null |
| 62 |
/usecmap { pop } .internalbind |
| 63 |
/begincmap {} |
| 64 |
/endcmap {} |
| 65 |
/begincodespacerange { pop mark } .internalbind |
| 66 |
/endcodespacerange { cleartomark } .internalbind |
| 67 |
/beginnotdefrange { pop mark } .internalbind |
| 68 |
/endnotdefrange { cleartomark } .internalbind |
| 69 |
/beginbfchar { pop mark } .internalbind |
| 70 |
/endbfchar { pop mark } .internalbind |
| 71 |
/beginbfrange { begincidrange } |
| 72 |
/endbfrange { endcidrange } |
| 73 |
/begincidchar { beginbfchar } |
| 74 |
/endcidchar { endbfchar } |
| 75 |
/begincidrange { pop mark } .internalbind |
| 76 |
/endcidrange { cleartomark } .internalbind |
| 77 |
>> % Just keep it on stack for a while. |
| 78 |
|
| 79 |
% Now we define another dict for local .internalbinding, than merge it with the previous one : |
| 80 |
dup length 5 add dict begin |
| 81 |
|
| 82 |
/.Ranges 40 dict def % Key = CID/256, value = array of 256 integer codes. |
| 83 |
//.Ranges /CIDCount 0 put |
| 84 |
|
| 85 |
/.StringToInt % <string> .StringToInt <integer> |
| 86 |
{ 0 exch { exch 8 bitshift add } forall |
| 87 |
} .internalbind def |
| 88 |
|
| 89 |
/.SetCouple % <I> <b> .SetCouple - |
| 90 |
{ exch % b I |
| 91 |
dup 256 idiv % b I I0 |
| 92 |
dup //.Ranges exch known not { |
| 93 |
dup //.Ranges exch 256 array put |
| 94 |
} if % b I I0 |
| 95 |
//.Ranges exch get % b I [Range] |
| 96 |
exch 256 mod % b [Range] I1 |
| 97 |
2 copy get % b [Range] I1 e |
| 98 |
dup //null ne { |
| 99 |
% We've got char code duplicates for same CID. |
| 100 |
dup type /integertype eq { |
| 101 |
4 3 roll % [Range] I1 e b |
| 102 |
2 array astore put % |
| 103 |
} { |
| 104 |
dup length 1 add dup dup array dup % b [Range] I1 D l l D' D' |
| 105 |
3 2 roll 0 exch getinterval % b [Range] I1 D l D' D'' |
| 106 |
4 3 roll exch copy pop % b [Range] I1 l D' |
| 107 |
dup 3 2 roll 1 sub % b [Range] I1 D' D' l-1 |
| 108 |
6 5 roll % [Range] I1 D' D' l-1 b |
| 109 |
put put % |
| 110 |
} ifelse |
| 111 |
} { |
| 112 |
pop 3 2 roll put % |
| 113 |
} ifelse |
| 114 |
} .internalbind def |
| 115 |
|
| 116 |
/endcidrange |
| 117 |
{ % Writes the inversed CMap to .Ranges |
| 118 |
counttomark 3 idiv { % (b) (e) I |
| 119 |
exch .StringToInt % (b) I e |
| 120 |
3 2 roll .StringToInt % I e b |
| 121 |
% Note : this code does't handle multidimentional CID ranges. |
| 122 |
% fixme : optimize below. |
| 123 |
dup 3 2 roll exch sub 1 add % I b d |
| 124 |
{ 2 copy //.SetCouple exec % I b |
| 125 |
1 add exch 1 add exch |
| 126 |
} repeat % I b |
| 127 |
pop % I |
| 128 |
dup //.Ranges /CIDCount get gt { % I |
| 129 |
dup //.Ranges exch /CIDCount exch put |
| 130 |
} if % I |
| 131 |
pop |
| 132 |
} repeat |
| 133 |
pop % mark |
| 134 |
} .internalbind def |
| 135 |
|
| 136 |
/.GetCIDDecoding % - .GetCIDDEcoding <dict> |
| 137 |
{ //.Ranges dup length dict copy |
| 138 |
//.Ranges //.PurgeDict exec |
| 139 |
//.Ranges /CIDCount 0 put |
| 140 |
} .internalbind def |
| 141 |
|
| 142 |
currentdict end |
| 143 |
exch copy % Merge the dicts - see above. |
| 144 |
/ProcSet defineresource pop |
| 145 |
|
| 146 |
%----------------CIDDecoding category---------------------------- |
| 147 |
% Note that we put all instances in global memory - see FindResource. |
| 148 |
|
| 149 |
/Generic /Category findresource dup length dict copy |
| 150 |
begin |
| 151 |
/Category /CIDDecoding def |
| 152 |
/InstanceType /dicttype def |
| 153 |
|
| 154 |
/.CMapChooser << |
| 155 |
% This lists CMaps to inverse and unite for creating a CIDDecoding. |
| 156 |
% Choose by FAPIcidfmap.Registry concatenated with TrueType encoding ID. |
| 157 |
% Font renderer must provide the glyph substitution internally. |
| 158 |
|
| 159 |
/CNS1.Big5 [ /ETen-B5-H /ETen-B5-V ] |
| 160 |
/CNS1.Unicode [ /UniCNS-UCS2-H /UniCNS-UCS2-V] |
| 161 |
/CNS1.UCS-4 [ /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 |
/GB1.UCS-4 [ /UniGB-UCS2-H /UniGB-UCS2-V ] |
| 165 |
/Japan1.ShiftJIS [ /90ms-RKSJ-H /90ms-RKSJ-V ] |
| 166 |
/Japan1.Unicode [ /UniJIS-UCS2-H /UniJIS-UCS2-V] |
| 167 |
/Japan1.UCS-4 [ /UniJIS-UCS2-H /UniJIS-UCS2-V] |
| 168 |
/Japan2.ShiftJIS [ /90ms-RKSJ-H /90ms-RKSJ-V ] |
| 169 |
/Japan2.Unicode [ /UniHojo-UCS2-H ] |
| 170 |
/Japan2.UCS-4 [ /UniHojo-UCS2-H ] |
| 171 |
/Korea1.Johab [ /KSC-Johab-V /KSC-Johab-H ] |
| 172 |
/Korea1.Wansung [ /KSCms-UHC-V /KSCms-UHC-H ] |
| 173 |
/Korea1.Unicode [ /UniKS-UCS2-H /UniKS-UCS2-V ] |
| 174 |
/Identity.Symbol [ /Identity-H /Identity-V ] |
| 175 |
/Unicode.Unicode [ /Identity-UTF16-H ] |
| 176 |
/Identity.Unicode [ /Identity-UTF16-H ] |
| 177 |
/Identity.UCS-4 [ /Identity-H /Identity-V ] |
| 178 |
>> def |
| 179 |
|
| 180 |
/.MakeInstance % <name> .MakeInstance <inst> |
| 181 |
{ dup % /Name /Name |
| 182 |
//.CMapChooser exch .knownget not { |
| 183 |
(Can't build /) print =string cvs print |
| 184 |
( /CIDDecoding resource. See gs_ciddc.ps . ) = flush |
| 185 |
/findresource cvx /undefinedresource signalerror |
| 186 |
} if % /Name [CMaps] |
| 187 |
exch pop % [CMaps] |
| 188 |
/CMap /Category findresource % [CMaps] <CMapCategory> |
| 189 |
/ParseCMap_Inverse /ProcSet findresource % [CMaps] <CMapCategory> <PCI> |
| 190 |
3 2 roll { % <CMapCategory> <PCI> /CMapName |
| 191 |
3 2 roll begin % <PCI> /CMapName |
| 192 |
dup .ResourceFile not { |
| 193 |
(Can't find CMap ) print =string cvs print |
| 194 |
( building a CIDDecoding resource. ) = flush |
| 195 |
/findresource cvx /undefinedresource signalerror |
| 196 |
} if |
| 197 |
currentdict end exch % <PCI> /CMapName <CMapCategory> file |
| 198 |
|
| 199 |
3 index begin |
| 200 |
cvx exec % <PCI> /CMapName <CMapCategory> |
| 201 |
end |
| 202 |
exch pop exch % <CMapCategory> <PCI> |
| 203 |
} forall |
| 204 |
exch pop begin % |
| 205 |
.GetCIDDecoding |
| 206 |
end |
| 207 |
} .internalbind def |
| 208 |
|
| 209 |
/FindResource % <name> FindResource <dict> |
| 210 |
{ currentglobal exch % bGlobal /InstName |
| 211 |
//true setglobal |
| 212 |
dup //.MakeInstance exec % bGlobal /InstName <Inst> |
| 213 |
DefineResource % bGlobal <Inst> |
| 214 |
exch setglobal % <Inst> |
| 215 |
} .internalbind def |
| 216 |
|
| 217 |
currentdict end |
| 218 |
/CIDDecoding exch /Category defineresource pop |
| 219 |
|
| 220 |
%----------------SubstCID category---------------------------- |
| 221 |
|
| 222 |
/Generic /Category findresource dup length dict copy |
| 223 |
begin |
| 224 |
/Category /SubstCID def |
| 225 |
/InstanceType /dicttype def |
| 226 |
currentdict end |
| 227 |
/SubstCID exch /Category defineresource pop |
| 228 |
|
| 229 |
setglobal |
| 230 |
.setlanguagelevel |