home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / clipart / gs22.zip / GFONTS.PS < prev    next >
Text File  |  1990-12-31  |  6KB  |  184 lines

  1. %    Copyright (C) 1990 Aladdin Enterprises.  All rights reserved.
  2. %    Distributed by Free Software Foundation, Inc.
  3. %
  4. % This file is part of Ghostscript.
  5. %
  6. % Ghostscript is distributed in the hope that it will be useful, but
  7. % WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. % to anyone for the consequences of using it or for whether it serves any
  9. % particular purpose or works at all, unless he says so in writing.  Refer
  10. % to the Ghostscript General Public License for full details.
  11. %
  12. % Everyone is granted permission to copy, modify and redistribute
  13. % Ghostscript, but only under the conditions described in the Ghostscript
  14. % General Public License.  A copy of this license is supposed to have been
  15. % given to you along with Ghostscript so you can know your rights and
  16. % responsibilities.  It should be in a file named COPYING.  Among other
  17. % things, the copyright notice and this notice must be preserved on all
  18. % copies.
  19.  
  20. % Font initialization for Ghostscript.  Despite anything claimed below,
  21. % Ghostscript fonts are actually in the same format as Adobe Type 1 fonts,
  22. % except that the external form customarily does not use eexec encryption.
  23. % Someday there will be GNU documentation that describes this format.
  24. % Until then, you'll have to either get a copy of Adobe's book, or read
  25. % the Ghostscript code.  The interpreter for Type 1 fonts, which reveals
  26. % most of their structure, is in the file gstype1.c.
  27.  
  28. % Define the default font.
  29. /defaultfontname /Ugly def
  30.  
  31. % Internal procedure to load the font name -> font file name map
  32. % if it isn't loaded already, and push it on the stack.
  33. /Fontmap
  34.  { /FontFileMap where
  35.     { /FontFileMap get }
  36.     { (Fontmap) findlibfile not
  37.        { (Can't find ) print print (!\n) print stop }
  38.       if
  39.  
  40.       FontDirectory maxlength dict exch
  41.       2 dict begin
  42.         mark exch 2 index exch
  43.     /;
  44.      { % The stack contains a mark, the dictionary, the font name,
  45.        % the file name, and additional information about the font.
  46.        counttomark 3 sub { pop } repeat put
  47.        1 index
  48.      } bind def
  49.     run
  50.       end
  51.       pop pop        % pop the mark and the copy of the dictionary
  52.       userdict exch /FontFileMap exch put
  53.       FontFileMap
  54.      }
  55.    ifelse
  56.  } bind def
  57.  
  58. % Define findfont so it tries to load a font if it's not found.
  59. /findfont
  60.  {
  61.     % If the key is a string, convert it to a name for lookup.
  62.     dup type /stringtype eq { cvn } if
  63.  
  64.     % If the font isn't in FontDirectory already, load it.
  65.     dup FontDirectory exch known not
  66.      { dup        % save the font name on the stack
  67.  
  68.        % Push the font name -> font file name map on the stack,
  69.        % loading it if necessary.
  70.        Fontmap
  71.  
  72.        % Read the file name from the map.
  73.        % (The stack contains the font name and the font file map.)
  74.        1 index known not
  75.         { (Substituting ) print defaultfontname cvx =only
  76.           ( for ) print == flush
  77.           pop defaultfontname
  78.         }
  79.         { FontFileMap exch get
  80.  
  81.           % If we can't find the file, substitute for the font.
  82.           dup findlibfile
  83.            { (Loading font file ) print exch print (... ) print flush
  84.              mark exch run cleartomark        % run can take a file
  85.          (done.\n) print flush
  86.            }
  87.            { pop 1 index defaultfontname eq
  88.           { (Can't find default font!\n) print
  89.             pop pop /NullFont
  90.           }
  91.           { (Can't find font file ) print print
  92.             (, substituting ) print defaultfontname cvx =only
  93.             (.\n) print flush
  94.             pop defaultfontname
  95.           }
  96.          ifelse
  97.            }
  98.           ifelse
  99.         }
  100.        ifelse
  101.  
  102.      } if
  103.  
  104.     % Get the font from the augmented FontDirectory.
  105.     % Check for the possibility that we haven't loaded
  106.     % the default font yet.
  107.     dup FontDirectory exch known not
  108.      { findfont }
  109.      { FontDirectory exch get }
  110.     ifelse
  111.  
  112.  } bind def
  113.  
  114. % Here is a reference implementation of addcharpath for "type 7" paths
  115. % (the type formerly used by Ghostscript).  We include this for backward
  116. % compatibility because Ghostscript's format has changed.
  117. /addcharpath        % <string> <pathtype> ->
  118.  { pop        % don't bother to check the pathtype
  119.     { moveto 3 -1 roll pop { rlineto } 3 1 roll } exch
  120.    % In the loop, the top element of the stack is the remaining part
  121.    % of the string, and the next element is the moveto/rlineto procedure.
  122.     { dup length 0 eq { exit } if
  123.       dup 0 get
  124.       dup 16#88 eq
  125.       { pop exch pop
  126.          { moveto 3 -1 roll pop { rlineto } 3 1 roll } exch
  127.     1
  128.       }
  129.       { dup 16 ge
  130.         { dup 15 and 0 ne
  131.        { % xx
  132.          dup -4 bitshift 8 sub   exch 15 and 8 sub   1
  133.        }
  134.        { % x0
  135.          -4 bitshift 8 sub   1 index 1 get 128 sub   2
  136.        }
  137.       ifelse
  138.     }
  139.     { dup 15 and 0 ne
  140.        { % 0x
  141.          8 sub   1 index 1 get 128 sub exch   2
  142.        }
  143.        { % 00
  144.          pop   dup 1 get 128 sub   1 index 2 get 128 sub   3
  145.        }
  146.       ifelse
  147.     }
  148.     ifelse
  149.     3 1 roll        % now: proc string nbytes dx dy
  150.     0.25 mul exch 0.25 mul exch
  151.     4 index exec
  152.       }
  153.       ifelse
  154.       dup 2 index length exch sub getinterval
  155.     } loop
  156.    pop pop
  157.  }
  158. bind def
  159.  
  160.  
  161. % The CharStrings for a Ghostscript font are a dictionary in which
  162. % the key is the character name, and the value is a compressed
  163. % representation of a path, as produced by type1imagepath.
  164. % For detailed information, see the book
  165. % "Adobe Type 1 Font Format", published by Adobe Systems Inc.
  166.  
  167. % Here is the BuildChar implementation
  168. % for Type 1 (Ghostscript standard) fonts.
  169. % The name Type1BuildChar is known to the interpreter.
  170.  
  171. /Type1BuildChar
  172.  { exch begin
  173.     Encoding exch get
  174.     dup CharStrings exch known not
  175.      { (Substituting .notdef for ) print = flush /.notdef } if
  176.     CharStrings exch get
  177.     PaintType 0 ne
  178.      { 1 setmiterlimit 1 setlinejoin 1 setlinecap
  179.        StrokeWidth setlinewidth }
  180.     if
  181.     type1addpath    % does a fill or stroke
  182.    end
  183.  } bind def
  184.