gs_fonts.ps 43 KB

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