| 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 |
% A procset for Postscript font emulation |
| 17 |
|
| 18 |
% The procedures must not depend on the presence of the |
| 19 |
% procset dictionary on the dictionary stack. |
| 20 |
|
| 21 |
languagelevel 2 .setlanguagelevel |
| 22 |
|
| 23 |
%========================= Process xlatmap ==================== |
| 24 |
mark |
| 25 |
%% Replace 1 (xlatmap) |
| 26 |
(xlatmap) .runlibfile |
| 27 |
.dicttomark dup systemdict exch /.xlatmap_dict exch put |
| 28 |
|
| 29 |
% Convert it into a plain text to simplify the processing in C : |
| 30 |
% *(fontkind\0\0\ *(charmap\0decoding\0) ) \0 |
| 31 |
|
| 32 |
() exch { |
| 33 |
3 1 roll =string cvs concatstrings (\0\0) concatstrings |
| 34 |
exch |
| 35 |
{ =string cvs concatstrings (\0) concatstrings |
| 36 |
} forall |
| 37 |
} forall |
| 38 |
(\0) concatstrings |
| 39 |
systemdict exch /.xlatmap exch put |
| 40 |
|
| 41 |
/FontEmulationProcs 10 dict begin |
| 42 |
|
| 43 |
%-------------------------------Font-------------------------------- |
| 44 |
|
| 45 |
/FontCommon % - font_common - |
| 46 |
{ currentdict /PaintType known not { |
| 47 |
/PaintType 0 def |
| 48 |
} if |
| 49 |
currentdict /Encoding .knownget not { |
| 50 |
//StandardEncoding |
| 51 |
} if |
| 52 |
dup type /nametype eq { |
| 53 |
/Encoding findresource |
| 54 |
} if |
| 55 |
/Encoding exch def |
| 56 |
} .internalbind def |
| 57 |
|
| 58 |
/FontOptions 5 dict begin |
| 59 |
/make_procs currentdict def |
| 60 |
/NameKey /FontName def |
| 61 |
/TypeKey /FontType def |
| 62 |
|
| 63 |
1 |
| 64 |
{ |
| 65 |
currentdict /FontMatrix known not { /FontMatrix [0.001 0 0 0.001 0 0] def } if |
| 66 |
currentdict /FontBBox known not { /FontBBox [-128 -128 1024 1024] cvx def } if % zfapi.ps refines it. |
| 67 |
/Private 0 dict def |
| 68 |
% if we're using the FAPI/UFST code for Microtype fonts, |
| 69 |
% then we've already created a "fake" CharStrings, so don't replace it. |
| 70 |
% See gs_fapi.ps |
| 71 |
currentdict /CharStrings known not {/CharStrings << /.notdef () >> def} if |
| 72 |
//FontCommon exec |
| 73 |
} .internalbind def |
| 74 |
|
| 75 |
42 |
| 76 |
{ /FontMatrix [1 0 0 1 0 0] def |
| 77 |
/FontBBox [0 0 1 1] def % zfapi.ps refines it. |
| 78 |
/CharStrings <<>> def |
| 79 |
/sfnts [<00010000 0000 0000 0000 0000 0000>] def |
| 80 |
/GlyphDirectory [] def |
| 81 |
//FontCommon exec |
| 82 |
} .internalbind def |
| 83 |
|
| 84 |
%fixme : more font types. |
| 85 |
|
| 86 |
currentdict end def |
| 87 |
|
| 88 |
%---------------------------CIDFont--------------------------- |
| 89 |
|
| 90 |
/TranslateCSI % <record> TranslateCSI <CSI> |
| 91 |
{ RESMPDEBUG { (fntem TranslateCSI beg ) = } if |
| 92 |
begin |
| 93 |
CSI length 2 eq { |
| 94 |
<< /Registry (Adobe) |
| 95 |
/Ordering CSI aload pop |
| 96 |
/Supplement exch |
| 97 |
>> |
| 98 |
} { |
| 99 |
<< /Registry CSI 0 get |
| 100 |
/Ordering CSI 1 get |
| 101 |
/Supplement CSI 2 get |
| 102 |
>> |
| 103 |
} ifelse |
| 104 |
end |
| 105 |
RESMPDEBUG { (fntem TranslateCSI end ) = } if |
| 106 |
} .internalbind def |
| 107 |
|
| 108 |
/CIDFontCommon |
| 109 |
{ /CIDSystemInfo currentdict //TranslateCSI exec def |
| 110 |
currentdict /CSI undef |
| 111 |
/FontBBox [-128 -128 1024 1024] def % zfapi.ps refines it. |
| 112 |
/CIDCount 1 def % ChooseDecoding will set a reasonable value. |
| 113 |
} .internalbind def |
| 114 |
|
| 115 |
% GFlyph substitution table for narrow, wide, proportional glyphs - |
| 116 |
% used with TrueTypes. |
| 117 |
|
| 118 |
currentpacking //false setpacking |
| 119 |
/SubstNWP << |
| 120 |
|
| 121 |
% Array format : orig_type, beg_CID, end_CID, subst_beg_CID, subst_type |
| 122 |
% type = (n==narrow, w==wide, p==proportional). |
| 123 |
|
| 124 |
/Japan1 |
| 125 |
{ p 1 94 231 n |
| 126 |
|
| 127 |
p 17 26 780 w |
| 128 |
p 34 59 790 w |
| 129 |
p 66 91 816 w |
| 130 |
w 842 842 7918 w % fixme: These substitutions require to shift the glyph origin. |
| 131 |
w 844 844 7919 w |
| 132 |
w 846 846 7920 w |
| 133 |
w 848 848 7921 w |
| 134 |
w 850 850 7922 w |
| 135 |
w 876 876 7923 w |
| 136 |
w 908 908 7924 w |
| 137 |
w 910 910 7925 w |
| 138 |
w 912 912 7926 w |
| 139 |
w 914 914 7927 w |
| 140 |
w 925 925 7928 w |
| 141 |
w 927 927 7929 w |
| 142 |
w 929 929 7930 w |
| 143 |
w 931 931 7931 w |
| 144 |
w 933 933 7932 w |
| 145 |
w 959 959 7933 w |
| 146 |
w 991 991 7934 w |
| 147 |
w 993 993 7935 w |
| 148 |
w 995 995 7936 w |
| 149 |
w 1002 1002 7937 w |
| 150 |
w 1009 1009 7938 w |
| 151 |
w 1010 1010 7939 w |
| 152 |
} cvlit |
| 153 |
|
| 154 |
/Japan2 1 index |
| 155 |
|
| 156 |
/CNS1 |
| 157 |
{ p 1 94 13648 n |
| 158 |
|
| 159 |
p 17 26 333 w |
| 160 |
p 34 59 365 w |
| 161 |
p 66 91 391 w |
| 162 |
} cvlit |
| 163 |
|
| 164 |
/GB1 |
| 165 |
{ p 2 94 814 n |
| 166 |
|
| 167 |
p 2 94 262 w |
| 168 |
|
| 169 |
p 1 1 7716 n |
| 170 |
} cvlit |
| 171 |
|
| 172 |
/Korea1 |
| 173 |
{ p 1 60 8094 n |
| 174 |
p 62 94 8155 n |
| 175 |
|
| 176 |
p 2 59 264 w |
| 177 |
p 63 94 325 w |
| 178 |
} cvlit |
| 179 |
|
| 180 |
/Identity [] |
| 181 |
|
| 182 |
/Unicode [] |
| 183 |
|
| 184 |
>> def |
| 185 |
setpacking |
| 186 |
|
| 187 |
/CIDFontOptions 5 dict begin |
| 188 |
/make_procs currentdict def |
| 189 |
/NameKey /CIDFontName def |
| 190 |
/TypeKey /CIDFontType def |
| 191 |
|
| 192 |
0 |
| 193 |
{ //CIDFontCommon exec |
| 194 |
/FDArray [ |
| 195 |
14 dict begin |
| 196 |
/FontName CIDFontName =string cvs (%) concatstrings cvn def |
| 197 |
/FontType 1 def |
| 198 |
/FontMatrix [0.001 0 0 0.001 0 0 ] def |
| 199 |
/PaintType 0 def |
| 200 |
/Private 0 dict def |
| 201 |
currentdict |
| 202 |
end |
| 203 |
] def |
| 204 |
/GlyphDirectory [] def |
| 205 |
/GDBytes 1 def |
| 206 |
/FDBytes 0 def |
| 207 |
} .internalbind def |
| 208 |
|
| 209 |
1 |
| 210 |
{ //CIDFontCommon exec |
| 211 |
/FontMatrix [1 0 0 1 0 0] def |
| 212 |
/BuildGlyph {} def |
| 213 |
} .internalbind def |
| 214 |
|
| 215 |
2 |
| 216 |
{ //CIDFontCommon exec |
| 217 |
/FontMatrix [1 0 0 1 0 0] def |
| 218 |
/GDBytes 2 def |
| 219 |
/CIDMap <0000> def |
| 220 |
/sfnts [<00010000 0000 0000 0000 0000 0000>] def |
| 221 |
/Encoding [] def |
| 222 |
/CharStrings << /.notdef 0 >> def |
| 223 |
} .internalbind def |
| 224 |
|
| 225 |
currentdict end def |
| 226 |
|
| 227 |
/complete_instance % <font_name> <FontDict> <Options> complete_FAPI_Font <font_name> <FontDict> |
| 228 |
{ begin |
| 229 |
dup length dict copy |
| 230 |
begin |
| 231 |
dup type /nametype ne { cvn } if |
| 232 |
dup NameKey exch def |
| 233 |
currentglobal //true setglobal |
| 234 |
make_procs TypeKey load .knownget { |
| 235 |
exec |
| 236 |
} { setglobal |
| 237 |
/complete_instance cvx /invalidfont signalerror |
| 238 |
} ifelse |
| 239 |
setglobal |
| 240 |
currentdict end |
| 241 |
end |
| 242 |
} .internalbind def |
| 243 |
|
| 244 |
/GetFilePath % <scratch> <Name> <record> GetFilePath <filepath> |
| 245 |
{ exch pop % (scratch) <record> |
| 246 |
/Path get % (scratch) (path) |
| 247 |
exch copy |
| 248 |
% What we make here it is not a complete PS resource. |
| 249 |
% Unable to provide full conformity : |
| 250 |
% the attempt to run this file may fail. |
| 251 |
} .internalbind def |
| 252 |
|
| 253 |
/GetSize % <Name> <record> GetSize <size> |
| 254 |
{ pop pop -1 % Unknown size. |
| 255 |
% fixme: probably we could provide an estimation size for some fonts. |
| 256 |
} .internalbind def |
| 257 |
|
| 258 |
/RecordVirtualMethodsStub 3 dict begin |
| 259 |
/GetFilePath //GetFilePath def |
| 260 |
/GetSize //GetSize def |
| 261 |
currentdict end def |
| 262 |
|
| 263 |
% ---------------------- Decoding helpers ---------------------------- |
| 264 |
|
| 265 |
/encodingnames mark |
| 266 |
StandardEncoding /StandardEncoding |
| 267 |
ISOLatin1Encoding /ISOLatin1Encoding |
| 268 |
SymbolEncoding /SymbolEncoding |
| 269 |
DingbatsEncoding /DingbatsEncoding |
| 270 |
.dicttomark def |
| 271 |
|
| 272 |
/ChooseDecoding % <font> ChooseDecoding <font> |
| 273 |
{ |
| 274 |
{ % A loop for 'exit' context. |
| 275 |
dup /Decoding .knownget { |
| 276 |
dup type /nametype eq { |
| 277 |
1 index /CIDFontType known { /CIDDecoding } { /Decoding } ifelse |
| 278 |
findresource 1 index exch /Decoding exch put |
| 279 |
} { |
| 280 |
pop |
| 281 |
} ifelse |
| 282 |
dup /CIDFontType known { |
| 283 |
dup dup /Decoding get /CIDCount get /CIDCount exch put |
| 284 |
} if |
| 285 |
exit |
| 286 |
} if |
| 287 |
dup /CIDFontType known { |
| 288 |
% This is a hooked CID font, no need for Decoding. |
| 289 |
exit |
| 290 |
} if |
| 291 |
% This works when the renderer can't choose character by name, |
| 292 |
% and we cannot determine the charset. |
| 293 |
% Probably this branch is to be removed after UFST problem is fixed. |
| 294 |
dup /Encoding get % <<font>> encoding |
| 295 |
dup type /nametype eq { |
| 296 |
/Decoding findresource 1 index exch /Decoding exch put |
| 297 |
} { |
| 298 |
dup //encodingnames |
| 299 |
exch .knownget { |
| 300 |
{ /Decoding findresource } stopped {pop pop //true}{ exch pop 1 index exch /Decoding exch put //false } ifelse |
| 301 |
} |
| 302 |
{ |
| 303 |
//true |
| 304 |
} ifelse |
| 305 |
|
| 306 |
{ |
| 307 |
% unknown encoding, or an encoding for which we don't have a |
| 308 |
% predefined decoding, convert it to decoding : |
| 309 |
currentglobal 3 1 roll 2 index gcheck setglobal |
| 310 |
dup length dict begin |
| 311 |
/.notdef 0 def |
| 312 |
0 1 currentdict length 1 sub |
| 313 |
{ dup 2 index exch get |
| 314 |
dup dup /.notdef ne exch type /nulltype ne and { |
| 315 |
exch def |
| 316 |
} { |
| 317 |
pop pop |
| 318 |
} ifelse |
| 319 |
} for |
| 320 |
pop |
| 321 |
currentdict end |
| 322 |
3 -1 roll setglobal |
| 323 |
1 index exch /Decoding exch put |
| 324 |
} if |
| 325 |
} ifelse |
| 326 |
exit |
| 327 |
} loop |
| 328 |
dup /CIDFontType known { |
| 329 |
dup /SubstNWP .knownget not { |
| 330 |
dup /CIDSystemInfo get /Ordering get cvn |
| 331 |
} if |
| 332 |
dup type /nametype eq { |
| 333 |
//SubstNWP exch .knownget not { |
| 334 |
[] |
| 335 |
} if % <<font>> [SubstNWP] |
| 336 |
} if |
| 337 |
1 index exch /SubstNWP exch put |
| 338 |
} if |
| 339 |
} .internalbind def |
| 340 |
|
| 341 |
/PrintFontRef % <string|name> <font> PrintFontRef <string|name> <font> |
| 342 |
{ dup /FontName known { (Font ) } { (CIDFont ) } ifelse print |
| 343 |
1 index =string cvs print |
| 344 |
dup /FontName .knownget not { |
| 345 |
dup /CIDFontName get |
| 346 |
} if % <string|name> <font> <fontname> |
| 347 |
dup 3 index ne { |
| 348 |
( \( aliased from ) print |
| 349 |
=string cvs print ( \)) print |
| 350 |
} { |
| 351 |
pop |
| 352 |
} ifelse |
| 353 |
} .internalbind def |
| 354 |
|
| 355 |
/GetFontType % <font> GetFontType int |
| 356 |
{ dup /CIDFontType .knownget { |
| 357 |
exch pop 9 add |
| 358 |
} { |
| 359 |
/FontType get |
| 360 |
} ifelse |
| 361 |
} .internalbind def |
| 362 |
|
| 363 |
/FindInArray % <array> <elem> .array_find <bool> |
| 364 |
{ //false 3 1 roll |
| 365 |
exch { % false elem elem_i |
| 366 |
1 index eq { % false elem |
| 367 |
pop //true exch |
| 368 |
} if |
| 369 |
} forall |
| 370 |
pop |
| 371 |
} .internalbind def |
| 372 |
|
| 373 |
/ProvideUnicodeDecoding % <font> ProvideUnicodeDecoding <font> |
| 374 |
{ |
| 375 |
% If the font is maintained by FAPI, or if it is TT-emulated CID font, |
| 376 |
% it already has /Decoding. But its value isn't guaranteeed to |
| 377 |
% be an Unicode decoding. Since we can't determine whether |
| 378 |
% it is an Unicode decoding, we unconditionally load an appropriate Unicode decoding |
| 379 |
% and attach it with /GlyphNames2Unicode entry. |
| 380 |
% |
| 381 |
% Another interesting case is when the font already has /GlyphNames2Unicode. |
| 382 |
% The latter to be used instead. Note that /GlyphNames2Unicode |
| 383 |
% appears only when type 32 fonts are disable (see .pdf_hook_DSC_Creator), |
| 384 |
% but an automatic disabling is not implemented yet. |
| 385 |
|
| 386 |
currentglobal //true setglobal exch |
| 387 |
dup /FontInfo known not { |
| 388 |
dup /FontInfo 1 dict put |
| 389 |
} if |
| 390 |
{ % A loop just for 'exit' context. |
| 391 |
dup /FontInfo get /GlyphNames2Unicode known { |
| 392 |
exit |
| 393 |
} if |
| 394 |
dup /CIDFontType known { |
| 395 |
dup mark exch % bool <font> [ <font> |
| 396 |
dup /CIDSystemInfo get /Ordering get (.Unicode) % bool <font> [ <font> () () |
| 397 |
concatstrings cvn % bool <font> [ <font> /Name |
| 398 |
/CIDDecoding { findresource } stopped { |
| 399 |
% Can't provide a decoding, giving up without creating /GlyphNames2Unicode. |
| 400 |
cleartomark exit |
| 401 |
} if % bool <font> [ <font> <D> |
| 402 |
exch /FontInfo get exch % bool <font> [ <FI> <D> |
| 403 |
/GlyphNames2Unicode exch |
| 404 |
.forceput % FontInfo can be read-only. |
| 405 |
pop % bool <font> |
| 406 |
exit |
| 407 |
} executeonly if |
| 408 |
dup /FontInfo get % bool <font> <FI> |
| 409 |
/GlyphNames2Unicode /Unicode /Decoding findresource |
| 410 |
.forceput % FontInfo can be read-only. |
| 411 |
exit |
| 412 |
} executeonly loop |
| 413 |
exch setglobal |
| 414 |
} .forcebind odef % must be bound and hidden for .forceput |
| 415 |
|
| 416 |
currentdict end /ProcSet defineresource pop |
| 417 |
|
| 418 |
.setlanguagelevel |