| 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 |
% Font initialization and management code. |
| 17 |
|
| 18 |
% Define the default font. |
| 19 |
/defaultfontname /Courier def |
| 20 |
|
| 21 |
% Define the name of the font map file. |
| 22 |
% Note that the "%%Replace " comment below provides the font map file name |
| 23 |
% for compiling initialization files into executable. Most likely it should be |
| 24 |
% consistent with the one specified here. |
| 25 |
/FONTMAP where |
| 26 |
{/FONTMAP get /defaultfontmap exch def} |
| 27 |
{/defaultfontmap (Fontmap) def} |
| 28 |
ifelse |
| 29 |
|
| 30 |
% we have to set .languagelevel to 2 so the parser will accept the names |
| 31 |
% '<<' and '>>', then we use a local definition here. |
| 32 |
.languagelevel 2 .setlanguagelevel |
| 33 |
/defaultfontmap_content 50 dict |
| 34 |
4 dict begin |
| 35 |
(<<) cvn /mark load def |
| 36 |
(>>) cvn /.dicttomark load def |
| 37 |
/; { 2 index 3 1 roll .growput }.internalbind def |
| 38 |
%% Replace 0 (Fontmap) |
| 39 |
end def |
| 40 |
.setlanguagelevel |
| 41 |
|
| 42 |
% ------ End of editable parameters ------ % |
| 43 |
|
| 44 |
% Define the UniqueIDs and organization XUID assigned to Artifex. |
| 45 |
% UniqueIDs 5,066,501 - 5,066,580 are assigned as follows: |
| 46 |
% 01 and 02 for shareware Cyrillic |
| 47 |
% 33 through 67 for Type 1 versions of the Hershey fonts |
| 48 |
% UniqueIDs 5,115,501 - 5,115,600 are currently unassigned. |
| 49 |
/AladdinEnterprisesXUID 107 def |
| 50 |
|
| 51 |
% If SUBSTFONT is defined, make it the default font. |
| 52 |
/SUBSTFONT where { pop /defaultfontname /SUBSTFONT load def } if |
| 53 |
|
| 54 |
% Define a reliable way of accessing FontDirectory in systemdict. |
| 55 |
/.FontDirectory |
| 56 |
{ /FontDirectory .systemvar |
| 57 |
} .forcebind odef |
| 58 |
|
| 59 |
% Define a temporary string for local use, since using =string |
| 60 |
% interferes with some PostScript programs. |
| 61 |
/.fonttempstring 8192 string def |
| 62 |
|
| 63 |
% Split up a search path into individual directories or files. |
| 64 |
/.pathlist % <path> .pathlist <dir1|file1> ... |
| 65 |
{ { dup length 0 eq { pop exit } if |
| 66 |
.filenamelistseparator search not { exit } if |
| 67 |
exch pop exch |
| 68 |
} |
| 69 |
loop |
| 70 |
}.internalbind def |
| 71 |
|
| 72 |
% <dir.../base.extn> .basename <dir> |
| 73 |
/.splitdirname { |
| 74 |
(/) rsearch { //true } { (\\) rsearch } ifelse |
| 75 |
{exch concatstrings exch pop //true}{//false} ifelse |
| 76 |
}.internalbind def |
| 77 |
|
| 78 |
% <dict> .addfontmappermitpaths |
| 79 |
% As fontmap can contain a *lot* of individual entries |
| 80 |
% we split off the filenames, and add directories to the |
| 81 |
% allowed paths. |
| 82 |
% We accumulate the paths in a dictionary, then iterate |
| 83 |
% the dictionary adding the paths to the PermitReading |
| 84 |
% list. This leverages the efficiency of dictionaries |
| 85 |
% handling duplicate keys. |
| 86 |
/.addfontmappermitpaths |
| 87 |
{ |
| 88 |
dup length dict begin |
| 89 |
{ |
| 90 |
exch pop dup type /stringtype eq |
| 91 |
{//.splitdirname exec {dup def} {pop} ifelse} |
| 92 |
{pop} |
| 93 |
ifelse |
| 94 |
} forall |
| 95 |
currentdict end |
| 96 |
{exch pop /PermitFileReading exch .addcontrolpath}forall |
| 97 |
}.internalbind def |
| 98 |
|
| 99 |
defaultfontmap_content length 0 gt |
| 100 |
{defaultfontmap_content .addfontmappermitpaths} if |
| 101 |
|
| 102 |
% Load a font name -> font file name map. |
| 103 |
userdict /Fontmap .FontDirectory maxlength dict put |
| 104 |
userdict /.nativeFontmap .FontDirectory maxlength dict put |
| 105 |
/.loadFontmap { % <file> .loadFontmap - |
| 106 |
% We would like to simply execute .definefontmap as we read, |
| 107 |
% but we have to maintain backward compatibility with an older |
| 108 |
% specification that makes later entries override earlier |
| 109 |
% ones within the same file. |
| 110 |
50 dict exch .readFontmap |
| 111 |
dup //.addfontmappermitpaths exec |
| 112 |
{ .definefontmap } forall |
| 113 |
}.internalbind def |
| 114 |
/.readFontmap { % <dict> <file> .readFontmap <dict> |
| 115 |
{ dup token not { closefile exit } if |
| 116 |
% stack: dict file fontname |
| 117 |
% This is a hack to get around the absurd habit of MS-DOS editors |
| 118 |
% of adding an EOF character at the end of the file. |
| 119 |
dup (\032) eq { pop closefile exit } if |
| 120 |
1 index token not |
| 121 |
{ (Fontmap entry for ) print dup =only |
| 122 |
( has no associated file or alias name! Giving up.) = flush |
| 123 |
{.readFontmap} 0 get 1 .quit |
| 124 |
} if |
| 125 |
dup type dup /stringtype eq exch /nametype eq or not |
| 126 |
{ (Fontmap entry for ) print 1 index =only |
| 127 |
( has an invalid file or alias name! Giving up.) = flush |
| 128 |
{.readFontmap} 0 get 1 .quit |
| 129 |
} if |
| 130 |
% stack: dict file fontname filename|aliasname |
| 131 |
dup type /nametype eq |
| 132 |
{ |
| 133 |
dup (<<) cvn eq |
| 134 |
{ |
| 135 |
pop mark |
| 136 |
{ |
| 137 |
counttomark 2 add index token not {//false exit} if |
| 138 |
dup (>>) cvn eq {pop //true exit} if |
| 139 |
} loop |
| 140 |
{ .dicttomark }{cleartomark} ifelse |
| 141 |
} if |
| 142 |
} if |
| 143 |
1 index type /stringtype eq |
| 144 |
1 index type /nametype eq and 1 index xcheck and |
| 145 |
1 index /run eq 2 index /.runlibfile eq or and { |
| 146 |
% This is an inclusion entry. |
| 147 |
pop findlibfile { exch pop } { file } ifelse |
| 148 |
2 index exch .readFontmap pop |
| 149 |
} { |
| 150 |
% This is a real entry. |
| 151 |
% Read and pop tokens until a semicolon. |
| 152 |
{ 2 index token not |
| 153 |
{ (Fontmap entry for ) print 1 index =only |
| 154 |
( ends prematurely! Giving up.) = flush |
| 155 |
{//.loadFontmap exec} 0 get 1 .quit |
| 156 |
} if |
| 157 |
dup /; eq { pop 3 index 3 1 roll .growput exit } if |
| 158 |
pop |
| 159 |
} loop |
| 160 |
} ifelse |
| 161 |
} loop |
| 162 |
}.internalbind def |
| 163 |
% Add an entry in Fontmap. We redefine this if the Level 2 |
| 164 |
% resource machinery is loaded. |
| 165 |
/.definefontmapaux % <bool> <fontname> <file|alias> .definefontmapaux - |
| 166 |
{ % Since Fontmap is global, make sure the values are storable. |
| 167 |
% If the fontname contains Unicode (first byte == \000) and |
| 168 |
% this is not an alias definition, define an alias using ASCII |
| 169 |
% (stripping out the high \000 bytes). Observed with some TT fonts. |
| 170 |
1 index 100 string cvs |
| 171 |
dup length 0 gt { |
| 172 |
0 get 0 eq 1 index type /nametype ne and { |
| 173 |
1 index 100 string cvs dup length 2 div cvi string //true exch |
| 174 |
0 1 2 index length 1 sub { |
| 175 |
% stack: fontname filename fontnamestring addflag newstring index |
| 176 |
dup 4 index exch 2 mul get 0 ne { |
| 177 |
% High byte of pair is not \000 |
| 178 |
pop pop //false exch |
| 179 |
exit |
| 180 |
} if |
| 181 |
dup 4 index exch 2 mul 1 add get 2 index 3 1 roll put |
| 182 |
} for |
| 183 |
exch { |
| 184 |
DEBUG { (\nAdding alias for: ) print 1 index ==only ( as: ) print dup //== exec flush } if |
| 185 |
cvn exch cvn .definefontmapaux % recurse with an alias |
| 186 |
} { |
| 187 |
pop pop % discard the name |
| 188 |
} ifelse |
| 189 |
} if |
| 190 |
} { |
| 191 |
pop |
| 192 |
} ifelse |
| 193 |
.currentglobal 3 1 roll //true .setglobal |
| 194 |
dup type /stringtype eq |
| 195 |
{ dup .gcheck not { dup length string copy } if |
| 196 |
} |
| 197 |
if |
| 198 |
|
| 199 |
4 -1 roll {.nativeFontmap}{Fontmap} ifelse |
| 200 |
3 -1 roll 2 copy .knownget |
| 201 |
{ % Add an element to the end of the existing value, |
| 202 |
% unless it's the same as the current last element. |
| 203 |
mark exch aload pop counttomark 4 add -1 roll |
| 204 |
2 copy eq { cleartomark pop pop } { ] readonly .growput } ifelse |
| 205 |
} |
| 206 |
{ % Make a new entry. |
| 207 |
mark 4 -1 roll ] readonly .growput |
| 208 |
} |
| 209 |
ifelse .setglobal |
| 210 |
}.internalbind def |
| 211 |
|
| 212 |
/.definefontmap % <fontname> <file|alias> .definefontmap - |
| 213 |
{ |
| 214 |
//false 3 1 roll //.definefontmapaux exec |
| 215 |
}.internalbind def |
| 216 |
|
| 217 |
/.definenativefontmap % <fontname> <file|alias> .definenativefontmap - |
| 218 |
{ |
| 219 |
//true 3 1 roll //.definefontmapaux exec |
| 220 |
}.internalbind def |
| 221 |
|
| 222 |
% Parse a font file just enough to find the FontName or FontType. |
| 223 |
/.findfontvalue { % <file> <key> .findfontvalue <value> true |
| 224 |
% <file> <key> .findfontvalue false |
| 225 |
% Closes the file in either case. |
| 226 |
exch dup read { |
| 227 |
2 copy .unread 16#80 eq { |
| 228 |
dup (xxxxxx) readstring pop pop % skip .PFB header |
| 229 |
} if |
| 230 |
{ % Stack: key file |
| 231 |
% Protect ourselves against syntax errors here. |
| 232 |
dup { token } stopped { //false exit } if |
| 233 |
not { //false exit } if % end of file |
| 234 |
dup /eexec eq { pop //false exit } if % reached eexec section |
| 235 |
dup /Subrs eq { pop //false exit } if % Subrs without eexec |
| 236 |
dup /CharStrings eq { pop //false exit } if % CharStrings without eexec |
| 237 |
dup 3 index eq |
| 238 |
{ xcheck not { dup token exit } if } % found key |
| 239 |
{ pop } |
| 240 |
ifelse |
| 241 |
} loop |
| 242 |
% Stack: key file value true (or) |
| 243 |
% Stack: key file false |
| 244 |
dup { 4 } { 3 } ifelse -2 roll closefile pop |
| 245 |
} { closefile pop //false } ifelse |
| 246 |
}.internalbind def |
| 247 |
/.findfontname |
| 248 |
{ /FontName .findfontvalue |
| 249 |
}.internalbind def |
| 250 |
|
| 251 |
% If there is no FONTPATH, try to get one from the environment. |
| 252 |
NOFONTPATH { /FONTPATH () def } if |
| 253 |
/FONTPATH where |
| 254 |
{ pop } |
| 255 |
{ /FONTPATH (GS_FONTPATH) getenv not { () } if def } |
| 256 |
ifelse |
| 257 |
|
| 258 |
% The following are dummy definitions that, if we have a FONTPATH, will |
| 259 |
% be replaced in the following section. |
| 260 |
% They are here so immediately evaulation will work, and allow them to |
| 261 |
% undefined at the bottom of the file. |
| 262 |
/.scanfontbegin{}.internalbind def |
| 263 |
/.scanfontdir {}.internalbind def |
| 264 |
|
| 265 |
FONTPATH length 0 eq { (%END FONTPATH) .skipeof } if |
| 266 |
/FONTPATH [ FONTPATH .pathlist ] def |
| 267 |
|
| 268 |
FONTPATH |
| 269 |
{ |
| 270 |
/PermitFileReading exch .addcontrolpath |
| 271 |
} forall |
| 272 |
|
| 273 |
% Scan directories looking for plausible fonts. "Plausible" means that |
| 274 |
% the file begins with %!PS-AdobeFont or %!FontType1, or with \200\001 |
| 275 |
% followed by four arbitrary bytes and then either of these strings. |
| 276 |
% To speed up the search, we skip any file whose name appears in |
| 277 |
% the Fontmap (with any extension and upper/lower case variation) already, |
| 278 |
% and any file whose extension definitely indicates it is not a font. |
| 279 |
% |
| 280 |
% NOTE: The current implementation of this procedure is somewhat Unix/DOS- |
| 281 |
% specific. It assumes that '/' and '\' are directory separators, and that |
| 282 |
% the part of a file name following the last '.' is the extension. |
| 283 |
% |
| 284 |
/.lowerstring % <string> .lowerstring <lowerstring> |
| 285 |
{ 0 1 2 index length 1 sub |
| 286 |
{ 2 copy get dup 65 ge exch 90 le and |
| 287 |
{ 2 copy 2 copy get 32 add put } |
| 288 |
if pop |
| 289 |
} |
| 290 |
for |
| 291 |
}.internalbind def |
| 292 |
/.splitfilename { % <dir.../base.extn> .basename <base> <extn> |
| 293 |
% Make the file name read-only to detect aliasing bugs. |
| 294 |
% We really don't like doing this, but we've had one |
| 295 |
% such bug already. |
| 296 |
readonly { |
| 297 |
(/) search { //true } { (\\) search } ifelse { pop pop } { exit } ifelse |
| 298 |
} loop |
| 299 |
dup { (.) search { pop pop } { exit } ifelse } loop |
| 300 |
2 copy eq { |
| 301 |
pop () |
| 302 |
} { |
| 303 |
exch dup length 2 index length 1 add sub 0 exch getinterval exch |
| 304 |
} ifelse |
| 305 |
}.internalbind def |
| 306 |
/.scanfontdict 1 dict def % establish a binding |
| 307 |
/.scanfontbegin |
| 308 |
{ % Construct the table of all file names already in Fontmap. |
| 309 |
currentglobal //true setglobal |
| 310 |
//.scanfontdict dup maxlength Fontmap length 2 add .max .setmaxlength |
| 311 |
Fontmap |
| 312 |
{ exch pop |
| 313 |
{ dup type /stringtype eq |
| 314 |
{ //.splitfilename exec pop //.fonttempstring copy //.lowerstring exec cvn |
| 315 |
//.scanfontdict exch //true put |
| 316 |
} |
| 317 |
{ pop |
| 318 |
} |
| 319 |
ifelse |
| 320 |
} |
| 321 |
forall |
| 322 |
} |
| 323 |
forall |
| 324 |
setglobal |
| 325 |
}.internalbind def |
| 326 |
/.scanfontskip mark |
| 327 |
% Strings are converted to names anyway, so.... |
| 328 |
/afm //true |
| 329 |
/bat //true |
| 330 |
/c //true |
| 331 |
/cmd //true |
| 332 |
/com //true |
| 333 |
/dir //true |
| 334 |
/dll //true |
| 335 |
/doc //true |
| 336 |
/drv //true |
| 337 |
/exe //true |
| 338 |
/fon //true |
| 339 |
/fot //true |
| 340 |
/h //true |
| 341 |
/o //true |
| 342 |
/obj //true |
| 343 |
/pfm //true |
| 344 |
/pss //true % Adobe Multiple Master font instances |
| 345 |
/txt //true |
| 346 |
.dicttomark def |
| 347 |
/.scan1fontstring 8192 string def |
| 348 |
% BeginFont: is not per Adobe documentation, but a few fonts have it. |
| 349 |
/.scanfontheaders [(%!PS-Adobe*) (%!FontType*) (%%BeginFont:*)] def |
| 350 |
0 /.scanfontheaders .systemvar { length .max } forall 6 add % extra for PFB header |
| 351 |
/.scan1fontfirst exch string def |
| 352 |
/.scanfontdir % <dirname> .scanfontdir - |
| 353 |
{ currentglobal exch //true setglobal |
| 354 |
QUIET not { (Scanning ) print dup print ( for fonts...) print flush } if |
| 355 |
[ 1 index ] (*) .generate_dir_list_templates |
| 356 |
0 0 0 4 -1 roll % found scanned files |
| 357 |
{ % stack: <fontcount> <scancount> <filecount> <filename> |
| 358 |
exch 1 add exch % increment filecount |
| 359 |
dup //.splitfilename exec //.fonttempstring copy //.lowerstring exec |
| 360 |
% stack: <fontcount> <scancount> <filecount+1> <filename> |
| 361 |
% <BASE> <ext> |
| 362 |
//.scanfontskip exch known exch //.scanfontdict exch known or |
| 363 |
{ pop |
| 364 |
% stack: <fontcount> <scancount> <filecount+1> |
| 365 |
} |
| 366 |
{ 3 -1 roll 1 add 3 1 roll |
| 367 |
% stack: <fontcount> <scancount+1> <filecount+1> <filename> |
| 368 |
dup (r) { file } //.internalstopped exec |
| 369 |
{ pop pop //null () |
| 370 |
% stack: <fontcount> <scancount+1> <filecount+1> <filename> |
| 371 |
% null () |
| 372 |
} |
| 373 |
{ |
| 374 |
% On some platforms, the file operator will open directories, |
| 375 |
% but an error will occur if we try to read from one. |
| 376 |
% Handle this possibility here. |
| 377 |
dup //.scan1fontfirst { readstring } //.internalstopped exec |
| 378 |
{ pop pop () } |
| 379 |
{ pop } |
| 380 |
ifelse |
| 381 |
% stack: <fontcount> <scancount+1> <filecount+1> |
| 382 |
% <filename> <file> <header> |
| 383 |
} |
| 384 |
ifelse |
| 385 |
% Check for PFB file header. |
| 386 |
dup (\200\001????*) .stringmatch |
| 387 |
{ dup length 6 sub 6 exch getinterval } |
| 388 |
if |
| 389 |
% Check for font file headers. |
| 390 |
//false /.scanfontheaders .systemvar |
| 391 |
{ 2 index exch .stringmatch or |
| 392 |
} |
| 393 |
forall exch pop |
| 394 |
{ % stack: <fontcount> <scancount+1> <filecount+1> <filename> |
| 395 |
% <file> |
| 396 |
dup 0 setfileposition //.findfontname exec |
| 397 |
{ dup .nativeFontmap exch known |
| 398 |
{ pop pop |
| 399 |
} |
| 400 |
{ exch |
| 401 |
dup length string copy % copy string |
| 402 |
exch |
| 403 |
DEBUG { ( ) print dup =only flush } if |
| 404 |
1 index //.definenativefontmap exec |
| 405 |
//.splitfilename exec pop //true //.scanfontdict 3 1 roll .growput |
| 406 |
% Increment fontcount. |
| 407 |
3 -1 roll 1 add 3 1 roll |
| 408 |
} |
| 409 |
ifelse |
| 410 |
} |
| 411 |
{ pop |
| 412 |
} |
| 413 |
ifelse |
| 414 |
} |
| 415 |
% .findfontname will have done a closefile in the above case. |
| 416 |
{ dup //null eq { pop } { closefile } ifelse pop |
| 417 |
} |
| 418 |
ifelse |
| 419 |
} |
| 420 |
ifelse |
| 421 |
} |
| 422 |
//.scan1fontstring filenameforall |
| 423 |
QUIET |
| 424 |
{ pop pop pop } |
| 425 |
{ ( ) print =only ( files, ) print =only ( scanned, ) print |
| 426 |
=only ( new fonts.) = flush |
| 427 |
} |
| 428 |
ifelse |
| 429 |
pop |
| 430 |
setglobal |
| 431 |
}.internalbind def |
| 432 |
|
| 433 |
%END FONTPATH |
| 434 |
|
| 435 |
/FONTMAP where |
| 436 |
{ |
| 437 |
dup /FONTMAP get /FONTMAP exch [ exch //.pathlist exec] put |
| 438 |
/FONTMAP dup where pop exch get {/PermitFileReading exch .addcontrolpath} forall |
| 439 |
} if |
| 440 |
|
| 441 |
% Try to enumerate native fonts registered with the os |
| 442 |
% and add them to the fontmap. This relies on a custom |
| 443 |
% operator which calls platform-specific C code. It |
| 444 |
% returns an array of arrays, each containing a pair |
| 445 |
% of strings: what the system thinks is the ps name, |
| 446 |
% and the access path. |
| 447 |
/.setnativefontmapbuilt { % set whether we've been run |
| 448 |
dup type /booleantype eq { |
| 449 |
systemdict exch /.nativefontmapbuilt exch .forceput |
| 450 |
} executeonly |
| 451 |
{pop} |
| 452 |
ifelse |
| 453 |
} .forcebind odef |
| 454 |
systemdict /NONATIVEFONTMAP known .setnativefontmapbuilt |
| 455 |
/.buildnativefontmap { % - .buildnativefontmap <bool> |
| 456 |
systemdict /.nativefontmapbuilt .knownget not |
| 457 |
{ //false} if |
| 458 |
|
| 459 |
{//false} |
| 460 |
{ |
| 461 |
QUIET not { |
| 462 |
(Querying operating system for font files...\n) |
| 463 |
print flush |
| 464 |
} if |
| 465 |
.getnativefonts dup |
| 466 |
{ |
| 467 |
exch |
| 468 |
{ |
| 469 |
% stack: [ (name) (path) ] |
| 470 |
% verify the font name ourselves |
| 471 |
dup 1 get (r) { file } //.internalstopped exec |
| 472 |
{ |
| 473 |
% skip the entry if we can't open the returned path |
| 474 |
pop pop pop |
| 475 |
}{ |
| 476 |
% we could open the font file |
| 477 |
mark 2 1 roll |
| 478 |
{//.findfontname exec} //.internalstopped exec |
| 479 |
{ |
| 480 |
cleartomark |
| 481 |
pop |
| 482 |
} |
| 483 |
{ |
| 484 |
counttomark 1 add -1 roll pop |
| 485 |
not { dup 0 get } if % stack: (newname) [ (name) (path) ] |
| 486 |
% DEBUG { ( found ) print dup print (\n) print flush } if |
| 487 |
% add entry to the fontmap |
| 488 |
1 index exch 0 exch dup type /nametype ne {cvn} if put |
| 489 |
aload pop //.definenativefontmap exec |
| 490 |
} ifelse |
| 491 |
} ifelse |
| 492 |
} forall |
| 493 |
} if |
| 494 |
% record that we've been run |
| 495 |
//true //.setnativefontmapbuilt |
| 496 |
} ifelse |
| 497 |
}.internalbind odef |
| 498 |
|
| 499 |
% Create the dictionary that registers the .buildfont procedure |
| 500 |
% (called by definefont) for each FontType. |
| 501 |
/buildfontdict 20 dict def |
| 502 |
|
| 503 |
% Register Type 3 fonts, which are always supported, for definefont. |
| 504 |
buildfontdict 3 /.buildfont3 cvx put |
| 505 |
|
| 506 |
% Register Type 0 fonts if they are supported. Strictly speaking, |
| 507 |
% we should do this in its own file (gs_type0.ps), but since this is |
| 508 |
% the only thing that would be in that file, it's simpler to put it here. |
| 509 |
/.buildfont0 where { pop buildfontdict 0 /.buildfont0 cvx put } if |
| 510 |
|
| 511 |
% Define definefont. This is a procedure built on a set of operators |
| 512 |
% that do all the error checking and key insertion. |
| 513 |
/.growfontdict |
| 514 |
{ % Grow the font dictionary, if necessary, to ensure room for an |
| 515 |
% added entry, making sure there is at least one slot left for FID. |
| 516 |
dup maxlength 1 index length sub 2 lt |
| 517 |
{ dup dup wcheck |
| 518 |
{ //.growdict exec} |
| 519 |
{ //.growdictlength exec dict .copydict } |
| 520 |
ifelse |
| 521 |
} |
| 522 |
{ dup wcheck not { dup maxlength dict .copydict } if |
| 523 |
} |
| 524 |
ifelse |
| 525 |
}.internalbind def |
| 526 |
/.completefont { |
| 527 |
{ % Check for disabled platform fonts. |
| 528 |
NOPLATFONTS |
| 529 |
{ % Make sure we leave room for FID. |
| 530 |
//.growfontdict exec dup /ExactSize 0 put |
| 531 |
} |
| 532 |
{ % Hack: if the Encoding looks like it might be the |
| 533 |
% Symbol or Dingbats encoding, load those now (for the |
| 534 |
% benefit of platform font matching) just in case |
| 535 |
% the font didn't actually reference them. |
| 536 |
% Note that some types of font don't have an Encoding. |
| 537 |
dup /Encoding .knownget { |
| 538 |
dup length 65 ge { |
| 539 |
64 get |
| 540 |
dup /congruent eq { SymbolEncoding pop } if |
| 541 |
/a9 eq { DingbatsEncoding pop } if |
| 542 |
} { |
| 543 |
pop |
| 544 |
} ifelse |
| 545 |
} if |
| 546 |
} |
| 547 |
ifelse |
| 548 |
dup /OrigFont known not { |
| 549 |
dup dup /OrigFont exch .growput |
| 550 |
} if |
| 551 |
//true exch |
| 552 |
% If this is a CIDFont, CIDFontType takes precedence |
| 553 |
% over FontType. |
| 554 |
dup /CIDFontType known { |
| 555 |
/.buildcidfont where { |
| 556 |
pop exch not exch % true => false |
| 557 |
} if |
| 558 |
} if |
| 559 |
exch { |
| 560 |
dup /FontType get //buildfontdict exch get |
| 561 |
} { |
| 562 |
{.buildcidfont} % so it gets bound |
| 563 |
} ifelse |
| 564 |
} stopped { $error /command get /invalidfont signalerror } if |
| 565 |
|
| 566 |
% Execute the .buildxxxfontx outside the 'stopped', because we don't |
| 567 |
% want its errors converted to invalidfont. |
| 568 |
exec |
| 569 |
|
| 570 |
{ |
| 571 |
systemdict /ProvideUnicode .knownget not { //false } if { |
| 572 |
/FontEmulationProcs /ProcSet findresource |
| 573 |
/ProvideUnicodeDecoding get exec |
| 574 |
} if |
| 575 |
readonly % stack: name fontdict |
| 576 |
} stopped { $error /command get /invalidfont signalerror } if |
| 577 |
}.internalbind odef |
| 578 |
/definefont |
| 579 |
{ dup rcheck not { |
| 580 |
/definefont cvx /invalidaccess signalerror |
| 581 |
} if |
| 582 |
/definefont cvx {.completefont} .errorexec |
| 583 |
% If the current allocation mode is global, also enter |
| 584 |
% the font in LocalFontDirectory. |
| 585 |
.currentglobal |
| 586 |
{ //systemdict /LocalFontDirectory .knownget |
| 587 |
{ 2 index 2 index .forceput } % readonly |
| 588 |
if |
| 589 |
} |
| 590 |
if |
| 591 |
dup //.FontDirectory 4 -2 roll .forceput % readonly |
| 592 |
% If the font originated as a resource, register it. |
| 593 |
currentfile .currentresourcefile eq { dup .registerfont } if |
| 594 |
readonly |
| 595 |
} .forcebind odef |
| 596 |
|
| 597 |
% Define a procedure for defining aliased fonts. |
| 598 |
% We use this only for explicitly aliased fonts, not substituted fonts: |
| 599 |
% we think this matches the observed behavior of Adobe interpreters. |
| 600 |
/.aliasfont % <name> <font> .aliasfont <newFont> |
| 601 |
{ |
| 602 |
currentglobal 3 1 roll dup gcheck setglobal |
| 603 |
% <bool> <name> <font> |
| 604 |
dup length 2 add dict % <bool> <name> <font> <dict> |
| 605 |
dup 3 -1 roll % <bool> <name> <dict> <dict> <font> |
| 606 |
{ 1 index /FID eq { pop pop } { put dup } ifelse } forall |
| 607 |
% <bool> <name> <dict> <dict> |
| 608 |
% Stack: global fontname newfont newfont. |
| 609 |
% We might be defining a global font whose FontName |
| 610 |
% is a local string. This is weird, but legal, |
| 611 |
% and doesn't cause problems anywhere else: |
| 612 |
% to avoid any possible problems in this case, do a cvn. |
| 613 |
% We might also be defining (as an alias) a global font |
| 614 |
% whose FontName is a local non-string, if someone passed a |
| 615 |
% garbage value to findfont. In this case, just don't |
| 616 |
% call definefont at all. |
| 617 |
2 index dup type /stringtype eq exch gcheck or 1 index gcheck not or |
| 618 |
{ pop % <bool> <name> <dict> |
| 619 |
1 index dup type /stringtype eq { cvn } if |
| 620 |
% <bool> <name> <dict> <name1> |
| 621 |
% HACK: |
| 622 |
% We want to know whether we alias a font, |
| 623 |
% because in this case its FontName to be replaced with the alias. |
| 624 |
% There is no simple way to know that at this point. |
| 625 |
% But if the original font has defaultfontname, |
| 626 |
% we probably substitute it rather than alias. |
| 627 |
% Using such condition as an approximation to the strong condition. |
| 628 |
% |
| 629 |
% Note it works wrongly if Fontmap maps something to defaultfontname like this : |
| 630 |
% /Courier /NimbusMonL-Regu ; |
| 631 |
% /Something /Courier ; |
| 632 |
% The FontName of Something will not be /Something. It will be /Courier . |
| 633 |
% |
| 634 |
1 index /FontName get defaultfontname ne { |
| 635 |
2 copy /FontName exch put |
| 636 |
} if |
| 637 |
1 index exch /.Alias exch put % <bool> <name> <dict> |
| 638 |
dup dup /OrigFont exch .growput |
| 639 |
% Don't bind in definefont, since Level 2 redefines it. |
| 640 |
/definefont .systemvar exec |
| 641 |
} |
| 642 |
{ |
| 643 |
/findfont cvx {.completefont} //.errorexec exec pop exch pop |
| 644 |
} |
| 645 |
ifelse |
| 646 |
exch setglobal |
| 647 |
}.internalbind odef % so findfont will bind it |
| 648 |
|
| 649 |
% Define .loadfontfile for loading a font. If we recognize Type 1 and/or |
| 650 |
% TrueType fonts, gs_type1.ps and/or gs_ttf.ps will redefine this. |
| 651 |
/.loadfontfile { |
| 652 |
% According to Ed Taft, Adobe interpreters push userdict |
| 653 |
% before loading a font, and pop it afterwards. |
| 654 |
userdict begin |
| 655 |
cvx exec |
| 656 |
end |
| 657 |
}.internalbind def |
| 658 |
/.setloadingfont { |
| 659 |
//systemdict /.loadingfont 3 -1 roll .forceput |
| 660 |
} .forcebind odef % .forceput must be bound and hidden |
| 661 |
/.loadfont |
| 662 |
{ % Some buggy fonts leave extra junk on the stack, |
| 663 |
% so we have to make a closure that records the stack depth |
| 664 |
% in a fail-safe way. |
| 665 |
//true .setloadingfont |
| 666 |
{ /FAPI_hook_disable pop % gs_fapi accesses this with execstack_lookup - don't remove ! |
| 667 |
{{.loadfontfile} .execasresource} count 1 sub 2 .execn |
| 668 |
count exch sub { pop } repeat |
| 669 |
exit |
| 670 |
} loop % this loop is a pattern for execstack_lookup, don't remove ! |
| 671 |
//false .setloadingfont |
| 672 |
}.internalbind def |
| 673 |
|
| 674 |
% Find an alternate font to substitute for an unknown one. |
| 675 |
% We go to some trouble to parse the font name and extract |
| 676 |
% properties from it. Later entries take priority over earlier. |
| 677 |
/.substitutefaces [ |
| 678 |
% Define substitutes for the fonts we define in Fontmap.GS |
| 679 |
[(Charter) /Times 0] |
| 680 |
[(Utopia) /Times 0] |
| 681 |
[(Antiqua) /Times 0] |
| 682 |
[(Calligraphic) /Helvetica 0] |
| 683 |
[(Hershey) /Times 0] |
| 684 |
% Guess at suitable substitutions for random unknown fonts. |
| 685 |
[(Book) /NewCenturySchlbk 0] |
| 686 |
[(Grot) /Helvetica 0] |
| 687 |
[(Roman) /Times 0] |
| 688 |
[(Chancery) /ZapfChancery-MediumItalic 0] |
| 689 |
% If the family name appears in the font name, |
| 690 |
% use a font from that family. |
| 691 |
[(Arial) /Helvetica 0] |
| 692 |
[(Avant) /AvantGarde 0] |
| 693 |
[(Bookman) /Bookman 0] |
| 694 |
[(Century) /NewCenturySchlbk 0] |
| 695 |
[(Cour) /Courier 0] |
| 696 |
[(Frut) /Helvetica 0] |
| 697 |
[(Garamond) /Palatino 0] |
| 698 |
[(Geneva) /Helvetica 0] |
| 699 |
[(Helv) /Helvetica 0] |
| 700 |
[(NewYork) /Bookman 0] |
| 701 |
[(Pala) /Palatino 0] |
| 702 |
[(Schlbk) /NewCenturySchlbk 0] |
| 703 |
[(Swiss) /Helvetica 0] |
| 704 |
[(Symbol) /Symbol 0] |
| 705 |
[(Times) /Times 0] |
| 706 |
% Substitute for Adobe Multiple Master fonts. |
| 707 |
[(Minion) /Times 0] |
| 708 |
[(Myriad) /Helvetica 0] |
| 709 |
% If the font wants to be monospace, use Courier. |
| 710 |
[(Monospace) /Courier 0] |
| 711 |
[(Typewriter) /Courier 0] |
| 712 |
% Define substitutes for the other Adobe PostScript 3 fonts. |
| 713 |
% For some of them, the substitution is pretty bad! |
| 714 |
[(Albertus) /Palatino 0] |
| 715 |
[(AntiqueOlive) /Helvetica 0] |
| 716 |
[(Bodoni) /NewCenturySchlbk 0] |
| 717 |
[(Chicago) /Helvetica 2] |
| 718 |
[(Clarendon) /Bookman 0] |
| 719 |
[(Cooper) /NewCenturySchlbk 0] |
| 720 |
[(Copperplate) /AvantGarde 0] % inappropriate, small-cap font |
| 721 |
[(Coronet) /ZapfChancery-MediumItalic 0] |
| 722 |
[(Eurostile) /Helvetica 0] |
| 723 |
[(Geneva) /Courier 2] % should be fixed-pitch sans demi |
| 724 |
[(GillSans) /Helvetica 2] |
| 725 |
[(GillSans-Light) /Helvetica 0] |
| 726 |
[(Goudy) /Palatino 0] |
| 727 |
[(Hoefler) /NewCenturySchlbk 0] |
| 728 |
[(Joanna) /Times 0] |
| 729 |
[(LetterGothic) /Courier 0] % should be fixed-pitch sans |
| 730 |
[(LubalinGraph-Book) /Bookman 2] |
| 731 |
[(LubalinGraph-Demi) /Bookman 0] |
| 732 |
[(Marigold) /ZapfChancery-MediumItalic 0] |
| 733 |
[(MonaLisa-Recut) /Palatino 0] % inappropriate |
| 734 |
[(Monaco) /Courier 2] % should be fixed-pitch sans demi |
| 735 |
[(Optima) /Helvetica 0] |
| 736 |
[(Oxford) /ZapfChancery-MediumItalic 0] |
| 737 |
[(Tekton) /Helvetica 0] |
| 738 |
[(Univers) /Helvetica 0] |
| 739 |
] readonly def |
| 740 |
/.substituteproperties [ |
| 741 |
[(It) 1] [(Oblique) 1] |
| 742 |
[(Black) 2] [(Bd) 2] [(Bold) 2] [(bold) 2] [(Demi) 2] [(Heavy) 2] [(Sb) 2] |
| 743 |
[(Cn) 4] [(Cond) 4] [(Narrow) 4] [(Pkg) 4] [(Compr) 4] |
| 744 |
[(Serif) 8] [(Sans) -8] |
| 745 |
] readonly def |
| 746 |
|
| 747 |
/.fontnamestring { % <fontname> .fontnamestring <string|name> |
| 748 |
dup type dup /nametype eq { |
| 749 |
pop .namestring |
| 750 |
} { |
| 751 |
/stringtype ne { pop () } if |
| 752 |
} ifelse |
| 753 |
}.internalbind def |
| 754 |
|
| 755 |
/.fontnameproperties { % <int> <string|name> .fontnameproperties |
| 756 |
% <int'> |
| 757 |
//.fontnamestring exec |
| 758 |
//.substituteproperties { |
| 759 |
2 copy 0 get search { |
| 760 |
pop pop pop dup length 1 sub 1 exch getinterval 3 -1 roll exch { |
| 761 |
dup 0 ge { or } { neg not and } ifelse |
| 762 |
} forall exch |
| 763 |
} { |
| 764 |
pop pop |
| 765 |
} ifelse |
| 766 |
} forall pop |
| 767 |
}.internalbind def |
| 768 |
/.substitutefamilies mark |
| 769 |
/AvantGarde |
| 770 |
{/AvantGarde-Book /AvantGarde-BookOblique |
| 771 |
/AvantGarde-Demi /AvantGarde-DemiOblique} |
| 772 |
/Bookman |
| 773 |
{/Bookman-Demi /Bookman-DemiItalic /Bookman-Light /Bookman-LightItalic} |
| 774 |
/Courier |
| 775 |
{/Courier /Courier-Oblique /Courier-Bold /Courier-BoldOblique} |
| 776 |
/Helvetica |
| 777 |
{/Helvetica /Helvetica-Oblique /Helvetica-Bold /Helvetica-BoldOblique |
| 778 |
/Helvetica-Narrow /Helvetica-Narrow-Oblique |
| 779 |
/Helvetica-Narrow-Bold /Helvetica-Narrow-BoldOblique} |
| 780 |
/NewCenturySchlbk |
| 781 |
{/NewCenturySchlbk-Roman /NewCenturySchlbk-Italic |
| 782 |
/NewCenturySchlbk-Bold /NewCenturySchlbk-BoldItalic} |
| 783 |
/Palatino |
| 784 |
{/Palatino-Roman /Palatino-Italic /Palatino-Bold /Palatino-BoldItalic} |
| 785 |
/Symbol |
| 786 |
{/Symbol /Symbol /Symbol /Symbol} |
| 787 |
/Times |
| 788 |
{/Times-Roman /Times-Italic /Times-Bold /Times-BoldItalic} |
| 789 |
/ZapfChancery-MediumItalic |
| 790 |
{/ZapfChancery-MediumItalic} |
| 791 |
.dicttomark readonly def |
| 792 |
/.nametostring { % <name> .nametostring <string> |
| 793 |
% <other> .nametostring <other> |
| 794 |
dup type /nametype eq { .namestring } if |
| 795 |
}.internalbind def |
| 796 |
|
| 797 |
/.substitutefontname { % <fontname> <properties> .substitutefontname |
| 798 |
% <altname|null> |
| 799 |
% Look for properties and/or a face name in the font name. |
| 800 |
% If we find any, use Times (serif) or Helvetica (sans) as the |
| 801 |
% base font; otherwise, use the default font. |
| 802 |
% Note that the "substituted" font name may be the same as |
| 803 |
% the requested one; the caller must check this. |
| 804 |
exch //.fontnamestring exec { |
| 805 |
defaultfontname /Helvetica-Oblique /Helvetica-Bold /Helvetica-BoldOblique |
| 806 |
/Helvetica-Narrow /Helvetica-Narrow-Oblique |
| 807 |
/Helvetica-Narrow-Bold /Helvetica-Narrow-BoldOblique |
| 808 |
/Times-Roman /Times-Italic /Times-Bold /Times-BoldItalic |
| 809 |
/Helvetica-Narrow /Helvetica-Narrow-Oblique |
| 810 |
/Helvetica-Narrow-Bold /Helvetica-Narrow-BoldOblique |
| 811 |
} 3 1 roll |
| 812 |
% Stack: facelist properties fontname |
| 813 |
% Look for a face name. |
| 814 |
//.substitutefaces { |
| 815 |
2 copy 0 get search { |
| 816 |
pop pop pop |
| 817 |
% Stack: facelist properties fontname [(pattern) family properties] |
| 818 |
dup 2 get 4 -1 roll or 3 1 roll |
| 819 |
1 get //.substitutefamilies exch get |
| 820 |
4 -1 roll pop 3 1 roll |
| 821 |
} { |
| 822 |
pop pop |
| 823 |
} ifelse |
| 824 |
} forall pop |
| 825 |
1 index length mod get exec |
| 826 |
}.internalbind odef |
| 827 |
/.substitutefont { % <fontname> .substitutefont <altname> |
| 828 |
dup 0 exch //.fontnameproperties exec .substitutefontname |
| 829 |
% Only accept fonts known in the Fontmap. |
| 830 |
Fontmap 1 index known not |
| 831 |
{ |
| 832 |
.nativeFontmap 1 index known not |
| 833 |
{pop defaultfontname } if |
| 834 |
} if |
| 835 |
}.internalbind odef |
| 836 |
|
| 837 |
% If requested, make (and recognize) fake entries in FontDirectory for fonts |
| 838 |
% present in Fontmap but not actually loaded. Thanks to Ray Johnston for |
| 839 |
% the idea behind this code. |
| 840 |
FAKEFONTS not { (%END FAKEFONTS) .skipeof } if |
| 841 |
|
| 842 |
% We use the presence or absence of the FontMatrix key to indicate whether |
| 843 |
% a font is real or fake. We must pop the arguments at the very end, |
| 844 |
% so that stack protection will be effective. |
| 845 |
|
| 846 |
/definefont { % <name> <font> definefont <font> |
| 847 |
dup /FontMatrix known { |
| 848 |
//definefont |
| 849 |
} { |
| 850 |
2 copy /FontName get findfont //definefont exch pop exch pop |
| 851 |
} ifelse |
| 852 |
}.internalbind odef |
| 853 |
|
| 854 |
/scalefont { % <font> <scale> scalefont <font> |
| 855 |
1 index /FontMatrix known { |
| 856 |
//scalefont |
| 857 |
} { |
| 858 |
1 index /FontName get findfont 1 index //scalefont |
| 859 |
exch pop exch pop |
| 860 |
} ifelse |
| 861 |
}.internalbind odef |
| 862 |
|
| 863 |
/makefont { % <font> <matrix> makefont <font> |
| 864 |
1 index /FontMatrix known { |
| 865 |
//makefont |
| 866 |
} { |
| 867 |
1 index /FontName get findfont 1 index //makefont |
| 868 |
exch pop exch pop |
| 869 |
} ifelse |
| 870 |
}.internalbind odef |
| 871 |
|
| 872 |
/setfont { % <font> setfont - |
| 873 |
dup /FontMatrix known { |
| 874 |
//setfont |
| 875 |
} { |
| 876 |
dup /FontName get findfont //setfont pop |
| 877 |
} ifelse |
| 878 |
}.internalbind odef |
| 879 |
|
| 880 |
%END FAKEFONTS |
| 881 |
|
| 882 |
% Define findfont so it tries to load a font if it's not found. |
| 883 |
% The Red Book requires that findfont be a procedure, not an operator, |
| 884 |
% but it still needs to restore the stacks reliably if it fails, |
| 885 |
% so we do all the work in an operator. |
| 886 |
/.findfont { % <fontname> .findfont <font> |
| 887 |
mark 1 index % <fontname> mark <fontname> |
| 888 |
//systemdict begin .dofindfont |
| 889 |
% <fontname> mark <alias> ... <font> |
| 890 |
% Define any needed aliases. |
| 891 |
counttomark 1 sub { .aliasfont } repeat end |
| 892 |
% <fontname> mark <font> |
| 893 |
exch pop exch pop |
| 894 |
}.internalbind odef |
| 895 |
/findfont { |
| 896 |
.findfont |
| 897 |
}.internalbind def |
| 898 |
% Check whether the font name we are about to look for is already on the list |
| 899 |
% of aliases we're accumulating; if so, cause an error. |
| 900 |
/.checkalias % -mark- <alias1> ... <name> .checkalias <<same>> |
| 901 |
{ counttomark 1 sub -1 1 |
| 902 |
{ index 1 index eq |
| 903 |
{ pop QUIET not |
| 904 |
{ (Unable to substitute for font.) = flush |
| 905 |
} if |
| 906 |
/findfont cvx /invalidfont signalerror |
| 907 |
} |
| 908 |
if |
| 909 |
} |
| 910 |
for |
| 911 |
}.internalbind def |
| 912 |
% Get a (non-fake) font if present in a FontDirectory. |
| 913 |
/.fontknownget % <fontdir> <fontname> .fontknownget <font> true |
| 914 |
% <fontdir> <fontname> .fontknownget false |
| 915 |
{ .knownget |
| 916 |
{ FAKEFONTS |
| 917 |
{ dup /FontMatrix known { //true } { pop //false } ifelse } |
| 918 |
{ //true } |
| 919 |
ifelse |
| 920 |
} |
| 921 |
{ //false |
| 922 |
} |
| 923 |
ifelse |
| 924 |
}.internalbind def |
| 925 |
% This is the standard procedure for handling font substitution. |
| 926 |
% Its location is per an Adobe newsgroup posting. |
| 927 |
% It is called with the font name on the stack, standing in for findfont. |
| 928 |
/.stdsubstfont { % mark <alias1> ... <fontname> .stdsubstfont mark <alias1> ... <aliasN> <font> |
| 929 |
/SUBSTFONT where { |
| 930 |
pop QUIET not { |
| 931 |
(Substituting for font ) print dup =only |
| 932 |
(.) = flush |
| 933 |
} if |
| 934 |
% No aliasing. |
| 935 |
% This mode is incompatible with high level devices. |
| 936 |
defaultfontname /None eq { /findfont cvx /invalidfont signalerror } if |
| 937 |
cleartomark mark defaultfontname |
| 938 |
} { |
| 939 |
dup .substitutefont |
| 940 |
2 copy eq { |
| 941 |
defaultfontname /None eq { /findfont cvx /invalidfont signalerror } if |
| 942 |
pop defaultfontname |
| 943 |
} if |
| 944 |
//.checkalias exec |
| 945 |
QUIET not { |
| 946 |
SHORTERRORS { |
| 947 |
(%%[) print 1 index =only |
| 948 |
( not found, substituting ) print dup =only (]%%) |
| 949 |
} { |
| 950 |
(Substituting font ) print dup =only |
| 951 |
( for ) print 1 index =only (.) |
| 952 |
} ifelse = flush |
| 953 |
} if |
| 954 |
} ifelse |
| 955 |
/Font findresource |
| 956 |
}.internalbind def |
| 957 |
|
| 958 |
% Default font substitution does {pop /Courier} om many implementations. |
| 959 |
% GS post-process font substitution in .stdsubstfont and uses {} for |
| 960 |
% backward compatibility |
| 961 |
$error /SubstituteFont { } put |
| 962 |
|
| 963 |
% Scan the next directory on FONTPATH. |
| 964 |
/.scannextfontdir { % - .scannextfontdir <bool> |
| 965 |
% If we haven't scanned all the directories in |
| 966 |
% FONTPATH, scan the next one. |
| 967 |
//null 0 1 FONTPATH length 1 sub { |
| 968 |
FONTPATH 1 index get //null ne { exch pop exit } if pop |
| 969 |
} for dup //null ne { |
| 970 |
dup 0 eq { //.scanfontbegin exec} if |
| 971 |
FONTPATH 1 index get //.scanfontdir exec |
| 972 |
FONTPATH exch //null put //true |
| 973 |
} { |
| 974 |
pop //false |
| 975 |
} ifelse |
| 976 |
}.internalbind def |
| 977 |
% Do the work of findfont, including substitution, defaulting, and |
| 978 |
% scanning of FONTPATH. |
| 979 |
/.dofindfont { % mark <fontname> .dofindfont % mark <alias> ... <font> |
| 980 |
.tryfindfont not { |
| 981 |
% We didn't find the font. If we haven't scanned |
| 982 |
% all the directories in FONTPATH, scan the next one |
| 983 |
% now and look for the font again. |
| 984 |
//.scannextfontdir exec { |
| 985 |
% Start over with an empty alias list. |
| 986 |
counttomark 1 sub { pop } repeat % mark <fontname> |
| 987 |
.dofindfont |
| 988 |
} { |
| 989 |
% No more directories to scan. Try building the native |
| 990 |
% font map entries if we haven't already done so. |
| 991 |
.buildnativefontmap { |
| 992 |
% Same stack as at the beginning of .dofindfont. |
| 993 |
.dofindfont % start over |
| 994 |
} { |
| 995 |
% No luck. Make sure we're not already |
| 996 |
% looking for the default font. |
| 997 |
QUIET not { |
| 998 |
(Didn't find this font on the system!\n) |
| 999 |
print |
| 1000 |
} if |
| 1001 |
dup defaultfontname eq { |
| 1002 |
QUIET not { |
| 1003 |
(Unable to load default font ) print |
| 1004 |
dup =only (! Giving up.) = flush |
| 1005 |
} if |
| 1006 |
/findfont cvx /invalidfont signalerror |
| 1007 |
} if |
| 1008 |
% Substitute for the font. Don't alias. |
| 1009 |
% Same stack as at the beginning of .dofindfont. |
| 1010 |
|
| 1011 |
$error /SubstituteFont get exec |
| 1012 |
% |
| 1013 |
% igorm: I guess the surrounding code assumes that .stdsubstfont |
| 1014 |
% must ADD an alias to allow .checkalias and .findfont to work properly. |
| 1015 |
% Also I guess that a trailing recursion is |
| 1016 |
% used in .dofindfont and through .stdsubstfont |
| 1017 |
% just to represent a simple iteration, |
| 1018 |
% which accumulates the aliases after the mark. |
| 1019 |
//.stdsubstfont exec |
| 1020 |
} ifelse |
| 1021 |
} ifelse |
| 1022 |
} if |
| 1023 |
}.internalbind def |
| 1024 |
|
| 1025 |
% any user of .putgstringcopy must use bind and executeonly |
| 1026 |
/.putgstringcopy % <dict> <name> <string> .putgstringcopy - |
| 1027 |
{ 2 index gcheck currentglobal |
| 1028 |
2 copy eq { |
| 1029 |
pop pop .forceput |
| 1030 |
} executeonly { |
| 1031 |
5 1 roll setglobal |
| 1032 |
dup length string copy |
| 1033 |
.forceput setglobal |
| 1034 |
} executeonly ifelse |
| 1035 |
} .forcebind odef % must be bound and hidden for .forceput |
| 1036 |
|
| 1037 |
/.loadfontloop { % <fontname> <filename> <libflag> .loadfontloop |
| 1038 |
% <font> true |
| 1039 |
% -or- |
| 1040 |
% <fontname> false |
| 1041 |
% See above regarding the use of 'loop'. |
| 1042 |
{ % Is the font name a string? |
| 1043 |
1 index type /stringtype ne |
| 1044 |
{ pop |
| 1045 |
QUIET not |
| 1046 |
{ (Can't find font with non-string name: ) print dup =only (.) = flush |
| 1047 |
} |
| 1048 |
if pop //false exit |
| 1049 |
} if |
| 1050 |
|
| 1051 |
% check <libflag> |
| 1052 |
{ |
| 1053 |
findlibfile not |
| 1054 |
} |
| 1055 |
{ |
| 1056 |
//true |
| 1057 |
} ifelse |
| 1058 |
|
| 1059 |
|
| 1060 |
% if findlibfile didn't work, try just opening the file direcly. |
| 1061 |
{ |
| 1062 |
dup (r) { file } stopped { |
| 1063 |
pop pop //true |
| 1064 |
} { |
| 1065 |
//false |
| 1066 |
} ifelse |
| 1067 |
} |
| 1068 |
{ |
| 1069 |
//false |
| 1070 |
}ifelse |
| 1071 |
|
| 1072 |
% If just opening the file didn't work, try opening the file name |
| 1073 |
% in the font resource directory |
| 1074 |
{ |
| 1075 |
dup |
| 1076 |
//.fonttempstring /FontResourceDir getsystemparam .genericrfn |
| 1077 |
(r) { file } stopped { |
| 1078 |
pop pop //true |
| 1079 |
} { |
| 1080 |
dup .filename |
| 1081 |
{ 3 -1 roll pop exch } |
| 1082 |
{ pop } |
| 1083 |
ifelse |
| 1084 |
//false |
| 1085 |
} ifelse |
| 1086 |
} |
| 1087 |
{ |
| 1088 |
//false |
| 1089 |
}ifelse |
| 1090 |
|
| 1091 |
{ |
| 1092 |
QUIET not |
| 1093 |
{ (Can't find \(or can't open\) font file ) print dup print |
| 1094 |
(.) = flush |
| 1095 |
} |
| 1096 |
if pop //false exit |
| 1097 |
} if |
| 1098 |
% Stack: fontname fontfilename fontfile |
| 1099 |
QUIET not |
| 1100 |
{ (Loading ) print 2 index =only |
| 1101 |
( font from ) print 1 index print (... ) print flush |
| 1102 |
} |
| 1103 |
if |
| 1104 |
% If LOCALFONTS isn't set, load the font into local or global |
| 1105 |
% VM according to FontType; if LOCALFONTS is set, load the font |
| 1106 |
% into the current VM, which is what Adobe printers (but not |
| 1107 |
% DPS or CPSI) do. |
| 1108 |
LOCALFONTS { //false } { /setglobal where } ifelse |
| 1109 |
{ pop /FontType .findfontvalue { 1 eq } { //false } ifelse |
| 1110 |
% .setglobal, like setglobal, aliases FontDirectory to |
| 1111 |
% GlobalFontDirectory if appropriate. However, we mustn't |
| 1112 |
% allow the current version of .setglobal to be bound in, |
| 1113 |
% because it's different depending on language level. |
| 1114 |
.currentglobal exch /.setglobal .systemvar exec |
| 1115 |
% Remove the fake definition, if any. |
| 1116 |
//.FontDirectory 3 index .forceundef % readonly |
| 1117 |
1 index (r) file .loadfont //.FontDirectory exch |
| 1118 |
/.setglobal .systemvar exec |
| 1119 |
} executeonly |
| 1120 |
{ .loadfont //.FontDirectory |
| 1121 |
} |
| 1122 |
ifelse |
| 1123 |
% Stack: fontname fontfilename fontdirectory |
| 1124 |
QUIET not |
| 1125 |
{ //systemdict /level2dict known |
| 1126 |
{ .currentglobal //false .setglobal vmstatus |
| 1127 |
//true .setglobal vmstatus 3 -1 roll pop |
| 1128 |
6 -1 roll .setglobal 5 |
| 1129 |
} |
| 1130 |
{ vmstatus 3 |
| 1131 |
} |
| 1132 |
ifelse { =only ( ) print } repeat |
| 1133 |
(done.) = flush |
| 1134 |
} if |
| 1135 |
|
| 1136 |
% Check to make sure the font was actually loaded. |
| 1137 |
dup 3 index //.fontknownget exec |
| 1138 |
{ dup /PathLoad 4 index //.putgstringcopy |
| 1139 |
4 1 roll pop pop pop //true exit |
| 1140 |
} executeonly if |
| 1141 |
|
| 1142 |
% Maybe the file had a different FontName. |
| 1143 |
% See if we can get a FontName from the file, and if so, |
| 1144 |
% whether a font by that name exists now. |
| 1145 |
exch dup % Stack: origfontname fontdirectory path path |
| 1146 |
(r) file //.findfontname exec |
| 1147 |
{ % Stack: origfontname fontdirectory path filefontname |
| 1148 |
2 index 1 index //.fontknownget exec |
| 1149 |
{ % Yes. Stack: origfontname fontdirectory path filefontname fontdict |
| 1150 |
dup 4 -1 roll /PathLoad exch //.putgstringcopy |
| 1151 |
% Stack: origfontname fontdirectory filefontname fontdict |
| 1152 |
3 -1 roll pop |
| 1153 |
% Stack: origfontname filefontname fontdict |
| 1154 |
dup /FontName get dup //.FontDirectory exch .forceundef |
| 1155 |
/GlobalFontDirectory .systemvar exch .forceundef |
| 1156 |
dup length dict .copydict dup 3 index /FontName exch put |
| 1157 |
2 index exch definefont |
| 1158 |
exch |
| 1159 |
QUIET |
| 1160 |
{ pop |
| 1161 |
} |
| 1162 |
{ (Using ) print =only |
| 1163 |
( font for ) print 1 index =only |
| 1164 |
(.) = flush |
| 1165 |
} |
| 1166 |
ifelse % Stack: origfontname fontdict |
| 1167 |
exch pop //true exit |
| 1168 |
% Stack: fontdict |
| 1169 |
} executeonly |
| 1170 |
if pop % Stack: origfontname fontdirectory path |
| 1171 |
} executeonly |
| 1172 |
if pop pop % Stack: origfontname |
| 1173 |
|
| 1174 |
% The font definitely did not load correctly. |
| 1175 |
QUIET not |
| 1176 |
{ (Loading ) print dup =only |
| 1177 |
( font failed.) = flush |
| 1178 |
} if |
| 1179 |
//false exit |
| 1180 |
|
| 1181 |
} loop % end of loop |
| 1182 |
|
| 1183 |
}.internalbind def % must be bound and hidden for .putgstringcopy |
| 1184 |
|
| 1185 |
% Attempt to load a font from a file. |
| 1186 |
/.tryloadfont { % <fontname> .tryloadfont <font> true |
| 1187 |
% <fontname> .tryloadfont false |
| 1188 |
dup //.nametostring exec |
| 1189 |
% Hack: check for the presence of the resource machinery. |
| 1190 |
/.genericrfn where { |
| 1191 |
pop |
| 1192 |
pop dup //.fonttempstring /FontResourceDir getsystemparam .genericrfn |
| 1193 |
{//false //.loadfontloop exec} //.internalstopped exec {//false} if { |
| 1194 |
//true |
| 1195 |
} { |
| 1196 |
dup //.nametostring exec |
| 1197 |
{//true //.loadfontloop exec} //.internalstopped exec {//false} if |
| 1198 |
} ifelse |
| 1199 |
} { |
| 1200 |
{//true //.loadfontloop exec} //.internalstopped exec {//false} if |
| 1201 |
} ifelse |
| 1202 |
}.internalbind def |
| 1203 |
|
| 1204 |
% Try to find a font using only the present contents of Fontmap. |
| 1205 |
/.tryfindfont { % <fontname> .tryfindfont <font> true |
| 1206 |
% <fontname> .tryfindfont false |
| 1207 |
//.FontDirectory 1 index //.fontknownget exec |
| 1208 |
{ % Already loaded |
| 1209 |
exch pop //true |
| 1210 |
} |
| 1211 |
{ |
| 1212 |
dup Fontmap exch .knownget |
| 1213 |
{ //true //true } |
| 1214 |
{ % Unknown font name. Look for a file with the |
| 1215 |
% same name as the requested font. |
| 1216 |
dup //.tryloadfont exec |
| 1217 |
{ exch pop //true //false } |
| 1218 |
{ |
| 1219 |
% if we can't load by name check the native font map |
| 1220 |
.nativeFontmap exch .knownget |
| 1221 |
{ //true //true } |
| 1222 |
{ //false //false } ifelse |
| 1223 |
} ifelse |
| 1224 |
} ifelse |
| 1225 |
|
| 1226 |
{ % Try each element of the Fontmap in turn. |
| 1227 |
pop |
| 1228 |
//false exch % (in case we exhaust the list) |
| 1229 |
% Stack: fontname false fontmaplist |
| 1230 |
{ exch pop |
| 1231 |
dup type /nametype eq |
| 1232 |
{ % Font alias |
| 1233 |
//.checkalias exec |
| 1234 |
dup .tryfindfont |
| 1235 |
{ |
| 1236 |
% We don't want to reuse an embedded font as a substitute |
| 1237 |
% so make sure the font came from disk before using it. |
| 1238 |
dup /Path known |
| 1239 |
1 index /PathLoad known or |
| 1240 |
{ exch pop //true exit } |
| 1241 |
{ |
| 1242 |
% if the candidate didn't come from disk, remove it from |
| 1243 |
% FontDirectory and try again. |
| 1244 |
pop dup undefinefont |
| 1245 |
.tryfindfont exit |
| 1246 |
} |
| 1247 |
ifelse |
| 1248 |
} if |
| 1249 |
} |
| 1250 |
{ dup dup type dup /arraytype eq exch /packedarraytype eq or exch xcheck and |
| 1251 |
{ % Font with a procedural definition |
| 1252 |
exec % The procedure will load the font. |
| 1253 |
% Check to make sure this really happened. |
| 1254 |
//.FontDirectory 1 index .knownget |
| 1255 |
{ exch pop //true exit } |
| 1256 |
if |
| 1257 |
} |
| 1258 |
{ % Font file name |
| 1259 |
dup type /dicttype eq |
| 1260 |
{ |
| 1261 |
begin |
| 1262 |
Path |
| 1263 |
} |
| 1264 |
{ |
| 1265 |
1 dict begin |
| 1266 |
} ifelse |
| 1267 |
//true //.loadfontloop exec |
| 1268 |
end |
| 1269 |
{ //true exit } if |
| 1270 |
} |
| 1271 |
ifelse |
| 1272 |
} |
| 1273 |
ifelse //false |
| 1274 |
} |
| 1275 |
forall |
| 1276 |
% Stack: font true -or- fontname false |
| 1277 |
{ //true |
| 1278 |
} |
| 1279 |
{ % None of the Fontmap entries worked. |
| 1280 |
% Try loading a file with the same name |
| 1281 |
% as the requested font. |
| 1282 |
//.tryloadfont exec |
| 1283 |
} |
| 1284 |
ifelse |
| 1285 |
} |
| 1286 |
if |
| 1287 |
} |
| 1288 |
ifelse |
| 1289 |
}.internalbind def |
| 1290 |
|
| 1291 |
% Define a procedure to load all known fonts. |
| 1292 |
% This isn't likely to be very useful. |
| 1293 |
/loadallfonts |
| 1294 |
{ |
| 1295 |
[Fontmap .nativeFontmap] { { pop findfont pop } forall } forall |
| 1296 |
}.internalbind def |
| 1297 |
|
| 1298 |
% If requested, load all the fonts defined in the Fontmap into FontDirectory |
| 1299 |
% as "fake" fonts i.e., font dicts with only FontName and FontType defined. |
| 1300 |
% (We define FontType only for the sake of some questionable code in the |
| 1301 |
% Apple Printer Utility 2.0 font inquiry code.) |
| 1302 |
% |
| 1303 |
% Note that this procedure only creates fake fonts in the FontDirectory |
| 1304 |
% associated with the current VM. This is because in multi-context systems, |
| 1305 |
% creating the fake fonts in local VM leads to undesirable complications. |
| 1306 |
/.definefakefonts |
| 1307 |
{ |
| 1308 |
} |
| 1309 |
{ |
| 1310 |
(gs_fonts FAKEFONTS) VMDEBUG |
| 1311 |
[Fontmap .nativeFontmap ] |
| 1312 |
{ |
| 1313 |
{ |
| 1314 |
pop dup type /stringtype eq { cvn } if |
| 1315 |
//.FontDirectory 1 index known not { |
| 1316 |
2 dict dup /FontName 3 index put |
| 1317 |
dup /FontType 1 put |
| 1318 |
//.FontDirectory 3 1 roll //.forceput exec % readonly |
| 1319 |
} { |
| 1320 |
pop |
| 1321 |
} ifelse |
| 1322 |
} forall |
| 1323 |
} forall |
| 1324 |
} executeonly % hide .forceput |
| 1325 |
FAKEFONTS { exch } if pop def % don't bind, .current/setglobal get redefined |
| 1326 |
|
| 1327 |
% Install initial fonts from Fontmap. |
| 1328 |
/.loadinitialfonts |
| 1329 |
{ NOFONTMAP not |
| 1330 |
{ /FONTMAP where |
| 1331 |
{ pop FONTMAP |
| 1332 |
{ dup VMDEBUG findlibfile |
| 1333 |
{ exch pop //.loadFontmap exec } |
| 1334 |
{ /undefinedfilename signalerror } |
| 1335 |
ifelse |
| 1336 |
} |
| 1337 |
} |
| 1338 |
{ LIBPATH |
| 1339 |
{ defaultfontmap |
| 1340 |
//false .file_name_combine |
| 1341 |
{ |
| 1342 |
dup VMDEBUG |
| 1343 |
(r) { file } //.internalstopped exec { |
| 1344 |
pop pop |
| 1345 |
defaultfontmap_content { .definefontmap } forall |
| 1346 |
} { |
| 1347 |
//.loadFontmap exec |
| 1348 |
} ifelse |
| 1349 |
} { |
| 1350 |
pop pop |
| 1351 |
} ifelse |
| 1352 |
} |
| 1353 |
} |
| 1354 |
ifelse forall |
| 1355 |
} |
| 1356 |
if |
| 1357 |
userdict /defaultfontmap_content .undef |
| 1358 |
//.definefakefonts exec % current VM is global |
| 1359 |
} def % don't bind, .current/setglobal get redefined |
| 1360 |
|
| 1361 |
% Undef these, not needed outside this file |
| 1362 |
[ |
| 1363 |
% /.fonttempstring /.scannextfontdir - are also used in gs_res.ps, so are undefined there |
| 1364 |
% /.scanfontheaders - used in gs_cff.ps, gs_ttf.ps |
| 1365 |
/.loadfontloop /.tryloadfont /.findfont /.pathlist /.loadFontmap /.lowerstring |
| 1366 |
/.splitfilename /.scanfontdict /.scanfontbegin |
| 1367 |
/.scanfontskip /.scan1fontstring |
| 1368 |
/.scan1fontfirst /.scanfontdir |
| 1369 |
/.setnativefontmapbuilt /.aliasfont |
| 1370 |
/.setloadingfont /.substitutefaces /.substituteproperties /.substitutefamilies |
| 1371 |
/.nametostring /.fontnamestring /.checkalias /.fontknownget /.stdsubstfont |
| 1372 |
/.putgstringcopy |
| 1373 |
/.definenativefontmap |
| 1374 |
/.findfontname /.addfontmappermitpaths /.splitdirname |
| 1375 |
] systemdict .undefinternalnames |