home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p024 / 6.img / SUPPORT4.LIB / ACADPSF.PS < prev    next >
Encoding:
Text File  |  1992-02-13  |  11.0 KB  |  276 lines

  1. %    Copyright (C) 1990, 1991 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. %
  29. %  ***********************************************************************
  30. %  *                                                                     *
  31. %  *    M   M    OOO    DDDD     III    FFFFF    III    EEEEE   DDDD     *
  32. %  *    MM MM   O   O   D   D     I     F         I     E       D   D    *
  33. %  *    M M M   O   O   D   D     I     F         I     E       D   D    *
  34. %  *    M   M   O   O   D   D     I     FFF       I     EEE     D   D    *
  35. %  *    M   M   O   O   D   D     I     F         I     E       D   D    *
  36. %  *    M   M   O   O   D   D     I     F         I     E       D   D    *
  37. %  *    M   M    OOO    DDDD     III    F        III    EEEEE   DDDD     *
  38. %  *                                                                     *
  39. %  *                                                                     *
  40. %  *                   FFFFF    III    L       EEEEE                     *
  41. %  *                   F         I     L       E                         *
  42. %  *                   F         I     L       E                         *
  43. %  *                   FFF       I     L       EEE                       *
  44. %  *                   F         I     L       E                         *
  45. %  *                   F         I     L       E                         *
  46. %  *                   F        III    LLLLL   EEEEE                     *
  47. %  *                                                                     *
  48. %  ***********************************************************************
  49. %
  50. %                              .-------------.
  51. %                              |      /\     |
  52. %                              |     /  \    |
  53. %                              |    / /\ \   |
  54. %                              |   / /  \ \  |
  55. %                              |  / / /\ \ \ |
  56. %                              | / / /  \ \ \|
  57. %                              `-------------'  (R)
  58. %                               Autodesk, Inc.
  59. %                   Tools For the Golden Age of Engineering
  60. %
  61. %   In  keeping with subparagraph 2a of the Gnu General Public License
  62. %   (Version 1, February 1989):
  63. %
  64. %   2.  You may modify your copy or  copies  of  the  Program  or  any
  65. %   portion  of  it,  and copy and distribute such modifications under
  66. %   the terms of Paragraph 1 above, provided  that  you  also  do  the
  67. %   following:
  68. %
  69. %      a)  cause the modified files to carry prominent notices stating
  70. %          that you changed the files and the date of any change; and...
  71. %
  72. %   the  following  is  a  summary of the changes to this file made by
  73. %   Autodesk, Inc. in August 1991 in order to adapt Ghostscript to run
  74. %   as  an  ADS  application  and  thereby  to  perform  rendering  of
  75. %   PostScript files within AutoCAD.
  76. %
  77. %   ACADPSF.PS      Ghostscript    font    loading   procedures.    Called
  78. %                   GS_FONTS.PS in standard Ghostscript.
  79. %
  80. %                   Added handling for various strange  characteristics of
  81. %                   fonts encountered in the real world.
  82. %
  83. %            Added exception handling when fontmap.ps has an incorrect
  84. %            entry, to prevent infinite recursion.
  85. % ************************************************************************
  86.  
  87. % Define the default font.
  88. /defaultfontname /Ugly def
  89.  
  90.  
  91. % Internal procedure to load the font name -> font file name map
  92. % if it isn't loaded already, and push it on the stack.
  93. /Fontmap
  94.  { /FontFileMap where
  95.     { /FontFileMap get }
  96.     { (fontmap.ps) findlibfile not
  97.        { (Can't find ) print print (!\n) print stop }
  98.       if
  99.  
  100.       FontDirectory maxlength dict exch
  101.       2 dict begin
  102.         mark exch 2 index exch
  103.         /;
  104.          { % The stack contains a mark, the dictionary, the font name,
  105.            % the file name, and additional information about the font.
  106.            counttomark 3 sub { pop } repeat put
  107.            1 index
  108.          } bind def
  109.         run
  110.       end
  111.       pop pop           % pop the mark and the copy of the dictionary
  112.       userdict exch /FontFileMap exch put
  113.       FontFileMap
  114.      }
  115.    ifelse
  116.  } bind def
  117.  
  118.  
  119. % Define definefont.  This is a procedure built on an operator that
  120. % does all the error checking and key insertion.
  121. /definefont
  122.  { 1 dict begin count /d exch def       % save stack depth in case of error
  123.    { .buildfont readonly } stopped
  124.    { count d sub { pop } repeat end /invalidfont signalerror }
  125.    { end dup FontDirectory 4 2 roll put }
  126.    ifelse
  127.  } odef
  128.  
  129. /GnernDict 1 dict def
  130.  
  131. % Define findfont so it tries to load a font if it's not found.
  132. /findfont
  133.  {
  134.         % If the key is a string, convert it to a name for lookup.
  135.         dup type /stringtype eq { cvn } if
  136.  
  137.         % If the font isn't in FontDirectory already, load it.
  138.         dup FontDirectory exch known
  139.          { FontDirectory exch get
  140.          }
  141.          { dup          % save the font name on the stack
  142.  
  143.            % Push the font name -> font file name map on the stack,
  144.            % loading it if necessary.
  145.            Fontmap
  146.  
  147.            % Read the file name from the map.
  148.            % (The stack contains the font name and the font file map.)
  149.            1 index known not
  150.             { QUIET not
  151.                { (Substituting ) print defaultfontname cvx =only
  152.                  ( for unknown font ) print == flush
  153.                } { pop } ifelse
  154.               pop defaultfontname findfont
  155.             }
  156.             { FontFileMap exch get
  157.  
  158.               % If we can't find the file, substitute for the font.
  159.               dup findlibfile
  160.            % save the filename here; we'll need it if the load fails.
  161.            2 index /savedfilename exch def
  162.                { QUIET not
  163.                   { (Loading font file ) print exch print (... ) print flush }
  164.                   { exch pop }
  165.                  ifelse
  166.  
  167.               %
  168.               %   Discard trash before PostScript sentinel
  169.               %
  170.               %   Fonts that come with Adobe Type Manager have some
  171.               %   trash binary bytes before the "%!" sentinel.  Walk
  172.               %   through the file and make sure we start reading at
  173.               %   the sentinel.
  174.               %
  175.                       {   dup read
  176.                               { 37 eq { dup read { 33 eq
  177.                                   { dup dup fileposition 2 sub setfileposition exit }
  178.                                   { unread } } { exit} ifelse
  179.                                   ifelse } if }
  180.                               { exit } ifelse
  181.                       } loop
  182.               %
  183.               %   End discarding of trash before PostScript sentinel
  184.               %
  185.  
  186.               %   Now it's time for some more adhocracy, another
  187.               %   indulgence in Kelvinist predestination.  It turns out
  188.               %   that the various fonts we've accreted over the years
  189.               %   obey no coherent conventions for what they leave or don't
  190.               %   leave on the stack and some, based on the Adobe Type 1
  191.               %   encryption decoder, even leave marks on the stack.  To
  192.               %   guarantee that we emerge from the font code with the
  193.               %   stack in a valid state, we save the stack depth in a
  194.               %   variable then programmatically pop any trash off the
  195.               %   stack when we're done.  This is ugly, but it works
  196.               %   with every font I've tried.
  197.  
  198.               count GnernDict begin /GnernK exch def end
  199.  
  200.                  mark exch
  201.                    systemdict begin   run   end         % run can take a file
  202.                  cleartomark
  203.  
  204.               %   Now for the actial dirty work to put the stack back
  205.               %   the way it was before we loaded the font.
  206.  
  207.               GnernDict begin
  208.               { count GnernK lt { exit } if pop} loop
  209.               end
  210.  
  211.                  QUIET not
  212.                   { vmstatus 3 { =only ( ) print } repeat
  213.                     (done.\n) print flush
  214.                   } if
  215.          
  216.              % OK, make sure the thing has really been loaded.
  217.          dup FontDirectory exch known not
  218.          {
  219.             % Oops.
  220.             (The font ) print =only
  221.             ( is not really in the file ) print
  222.             savedfilename =only
  223.             (\n) print flush
  224.             defaultfontname
  225.          } if
  226.                  findfont
  227.                }
  228.                { pop 1 index defaultfontname eq
  229.                   { (Can't find default font!\n) print
  230.                     pop pop NullFont
  231.                   }
  232.                   { (Can't find font file ) print print
  233.                     (, substituting ) print defaultfontname cvx =only
  234.                     (.\n) print flush
  235.                     pop defaultfontname findfont
  236.                   }
  237.                  ifelse
  238.                }
  239.               ifelse
  240.             }
  241.            ifelse
  242.  
  243.          } ifelse
  244.  
  245.  } bind def
  246.  
  247.  
  248. % The CharStrings for a Ghostscript font are a dictionary in which
  249. % the key is the character name, and the value is a compressed
  250. % representation of a path, as produced by type1imagepath.
  251. % For detailed information, see the book
  252. % "Adobe Type 1 Font Format", published by Adobe Systems Inc.
  253.  
  254. % Here is the BuildChar implementation
  255. % for Type 1 (Ghostscript standard) fonts.
  256. % The name Type1BuildChar is known to the interpreter.
  257.  
  258. /Type1BuildChar
  259.  { exch begin
  260.     Encoding exch get
  261.     dup CharStrings exch known not
  262.      { QUIET not
  263.         { (Substituting .notdef for ) print = flush
  264.         } { pop } ifelse
  265.        /.notdef
  266.      } if
  267.     CharStrings exch get
  268.     PaintType 0 ne
  269.      { 1 setmiterlimit 1 setlinejoin 1 setlinecap
  270.        currentdict /StrokeWidth known { StrokeWidth } { 0 } ifelse
  271.        setlinewidth }
  272.     if
  273.     type1addpath        % does a fill or stroke
  274.    end
  275.  } bind def
  276.