home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / lib / ghostscript / gs_fonts.ps < prev    next >
Text File  |  1994-12-22  |  21KB  |  695 lines

  1. %    Copyright (C) 1990, 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2. %
  3. % This file is part of Ghostscript.
  4. %
  5. % Ghostscript is distributed in the hope that it will be useful, but
  6. % WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. % to anyone for the consequences of using it or for whether it serves any
  8. % particular purpose or works at all, unless he says so in writing.  Refer
  9. % to the Ghostscript General Public License for full details.
  10. %
  11. % Everyone is granted permission to copy, modify and redistribute
  12. % Ghostscript, but only under the conditions described in the Ghostscript
  13. % General Public License.  A copy of this license is supposed to have been
  14. % given to you along with Ghostscript so you can know your rights and
  15. % responsibilities.  It should be in a file named COPYING.  Among other
  16. % things, the copyright notice and this notice must be preserved on all
  17. % copies.
  18.  
  19. % Font initialization and management code.
  20.  
  21. % The standard representation for PostScript compatible fonts is described
  22. % in the book "Adobe Type 1 Font Format", published by Adobe Systems Inc.
  23.  
  24. % Define the default font.
  25. /defaultfontname /Ugly def
  26.  
  27. % Load the font name -> font file name map.
  28. userdict /Fontmap FontDirectory maxlength dict put
  29. /.loadFontmap        % <filename> .loadFontmap -
  30.  { 2 dict begin
  31.      mark Fontmap
  32.      /;
  33.       { % The stack contains a mark, the dictionary, the font name,
  34.         % the file or alias name, and possibly additional information
  35.     % about the font.
  36.     counttomark 3 sub { pop } repeat .growput
  37.     Fontmap
  38.       } bind def
  39.      3 -1 roll run
  40.    end
  41.    pop pop        % pop the mark and the copy of the dictionary
  42.  } bind def
  43. (Fontmap) .loadFontmap
  44.  
  45. % Parse a font file just enough to find the FontName.
  46. /.findfontname        % <file> .findfontname <name> true
  47.             % <file> .findfontname false
  48.             % Closes the file in either case.
  49.  {  { dup token not { false exit } if        % end of file
  50.       dup /eexec eq { pop false exit } if    % reached eexec section
  51.       dup /FontName eq
  52.        { xcheck not { dup token exit } if }    % found /FontName
  53.        { pop }
  54.       ifelse
  55.     } loop
  56.    dup { 3 } { 2 } ifelse -1 roll closefile
  57.  } bind def
  58.  
  59. (GS_FONTPATH) getenv not { (%END GS_FONTPATH) .skipeof } if
  60. pop
  61.  
  62. % Scan directories looking for plausible fonts.  "Plausible" means that
  63. % the file begins either with %!PS-AdobeFont-, or with \200\001
  64. % followed by four arbitrary bytes and then "%!PS-AdobeFont-".
  65. % To speed up the search, we skip any file whose name appears in
  66. % the Fontmap (with any extension and upper/lower case variation) already.
  67. %
  68. % NOTE: The current implementation of this procedure is Unix/DOS-
  69. % specific.  It assumes that '/' and '\' are directory separators; that
  70. % the part of a file name following the last '.' is the extension;
  71. % that ';' cannot appear in a file name; and that ':' can appear in a
  72. % file name only if the file name doesn't begin with '/', '\', or '.'.
  73. % (this is so that Unix systems can use ':' as the separator).
  74. %
  75. /.lowerstring        % <string> .lowerstring <lowerstring>
  76.  { 0 1 2 index length 1 sub
  77.     { 2 copy get dup 65 ge exch 90 le and
  78.        { 2 copy 2 copy get 32 add put }
  79.      if pop
  80.     }
  81.    for
  82.  } bind def
  83. /.splitfilename        % <dir.../base.extn> .basename <base> <extn>
  84.  {  { (/) search { true } { (\\) search } ifelse
  85.        { pop pop }
  86.        { exit }
  87.       ifelse
  88.     }
  89.    loop
  90.    dup { (.) search { pop pop } { exit } ifelse } loop
  91.    2 copy eq
  92.     { pop () }
  93.     { exch dup length 2 index length 1 add sub 0 exch getinterval exch }
  94.    ifelse
  95.  } bind def
  96. /.scanfontdict Fontmap maxlength dict def
  97. /.scanfontbegin
  98.  {    % Construct the table of all file names already in Fontmap.
  99.    Fontmap
  100.     { exch pop dup type /stringtype eq
  101.        { .splitfilename pop =string copy .lowerstring cvn
  102.          .scanfontdict exch true .growput
  103.        }
  104.        { pop
  105.        }
  106.       ifelse
  107.     }
  108.    forall
  109.  } bind def
  110. /.scanfontskip 4 dict dup begin
  111.   (afm) true def
  112.   (pfm) true def
  113. end def
  114. /.scan1fontstring 128 string def
  115. /.fontheader (\200\001????%!PS-AdobeFont-*) def
  116. /.scan1fontfirst .fontheader length string def
  117. /.scan1fontdir        % <dirname> .scan1fontdir -
  118.  { QUIET not { (Scanning ) print dup print ( for fonts... ) print flush } if
  119.    0 exch (/*) concatstrings
  120.     { dup .splitfilename
  121.       .scanfontskip exch known exch .scanfontdict exch known or
  122.        { pop
  123.        }
  124.        { dup (r) file
  125.          dup .scan1fontfirst readstring pop
  126.      dup .fontheader 6 16 getinterval .stringmatch
  127.       { pop true }
  128.       { .fontheader .stringmatch }
  129.      ifelse
  130.       { dup 0 setfileposition .findfontname
  131.          { dup Fontmap exch known
  132.             { pop pop
  133.         }
  134.         { exch copystring exch
  135.           Fontmap exch 2 index .growput
  136.           .splitfilename pop true .scanfontdict 3 1 roll .growput
  137.           1 add
  138.         }
  139.            ifelse
  140.          }
  141.         if
  142.       }
  143.       { closefile pop
  144.       }
  145.      ifelse
  146.        }
  147.       ifelse
  148.     }
  149.    .scan1fontstring filenameforall
  150.    QUIET { pop } { =only ( found.\n) print flush } ifelse
  151.  } bind def
  152. % Scan all the directories mentioned in GS_FONTPATH.
  153. (GS_FONTPATH) getenv
  154.  { .scanfontbegin
  155.     % Parsing the list of dictionaries is messy, since we have to
  156.     % handle both the Unix : and the other-system ; as separators.
  157.     % See the earlier comment for the restrictions that make this work.
  158.     { dup length 0 eq { pop exit } if
  159.       (;) search
  160.        { exch pop
  161.        }
  162.        { dup 0 1 getinterval (/\\.) exch search
  163.           { pop pop pop (:) search
  164.          { exch pop }
  165.          { () exch }
  166.         ifelse
  167.       }
  168.       { pop () exch
  169.       }
  170.      ifelse
  171.        }
  172.       ifelse .scan1fontdir
  173.     }
  174.    loop
  175.  }
  176. if
  177.  
  178. %END GS_FONTPATH
  179.  
  180. % If DISKFONTS is true, we load individual CharStrings as they are needed.
  181. % (This is intended primarily for machines with very small memories.)
  182. % In this case, we define another dictionary, parallel to FontDirectory,
  183. % that retains an open file for every font loaded.
  184. /FontFileDirectory 10 dict def
  185.  
  186. % Define an augmented version of .buildfont1 that inserts UnderlinePosition
  187. % and UnderlineThickness entries in FontInfo if they aren't there already.
  188. % (This works around the incorrect assumption, made by many word processors,
  189. % that these entries are present in the built-in fonts.)
  190. /.buildfont1x
  191.  { dup /FontInfo known not
  192.     { dup /FontInfo 2 dict .growput }
  193.    if
  194.    dup dup /FontInfo get dup dup
  195.    /UnderlinePosition known exch /UnderlineThickness known and
  196.     { pop pop        % entries already present
  197.     }
  198.     { dup length 2 add dict copy
  199.       dup /UnderlinePosition known not
  200.        { dup /UnderlinePosition 3 index /FontBBox get
  201.          1 get 2 div put        % 1/2 the font descent
  202.        }
  203.       if
  204.       dup /UnderlineThickness known not
  205.        { dup /UnderlineThickness 3 index /FontBBox get
  206.          dup 3 get exch 1 get sub 20 div put    % 1/20 the font height
  207.        }
  208.       if
  209.       1 index /FontInfo get wcheck not { readonly } if
  210.       /FontInfo exch put
  211.     }
  212.    ifelse .buildfont1
  213.  } bind def
  214. % Define definefont.  This is a procedure built on a set of operators
  215. % that do all the error checking and key insertion.
  216. mark
  217.     /.buildfont0 where { pop 0 /.buildfont0 load } if
  218.     /.buildfont1 where { pop 1 /.buildfont1x load } if
  219.     /.buildfont3 where { pop 3 /.buildfont3 load } if
  220. .dicttomark /.buildfontdict exch def
  221. /definefont
  222.  { 1 dict begin count /d exch def    % save stack depth in case of error
  223.     {        % Check for disabled platform fonts.
  224.       NOPLATFONTS
  225.        { dup maxlength 1 index length sub 2 lt { dup .growdict } if
  226.      dup /ExactSize 0 put
  227.        }
  228.        {    % Hack: if the Encoding looks like it might be the
  229.         % Symbol or Dingbats encoding, load those now (for the
  230.         % benefit of platform font matching) just in case
  231.         % the font didn't actually reference them.
  232.      dup /Encoding get length 65 ge
  233.       { dup /Encoding get 64 get
  234.         dup /congruent eq { SymbolEncoding pop } if
  235.         /a9 eq { DingbatsEncoding pop } if
  236.       }
  237.      if
  238.        }
  239.       ifelse
  240.       dup /FontType get //.buildfontdict exch get exec
  241.       DISKFONTS
  242.        { FontFileDirectory 2 index known
  243.           { dup /FontFile FontFileDirectory 4 index get .growput
  244.       }
  245.      if
  246.        }
  247.       if
  248.       readonly
  249.     }
  250.    stopped
  251.     { count d sub { pop } repeat end /invalidfont signalerror }
  252.     { end dup FontDirectory 4 2 roll .growput }
  253.    ifelse
  254.  } odef
  255.  
  256.  
  257. % If