home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / ghostscript / 8.64 / Resource / Init / gs_fonts.ps < prev    next >
Encoding:
Text File  |  2009-04-17  |  43.4 KB  |  1,224 lines

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