home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Impressora_PDF / converter.exe / GPLGS / gs_fonts.ps < prev    next >
Text File  |  2004-08-03  |  45KB  |  1,207 lines

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