home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Impressora_PDF / converter.exe / GPLGS / gs_type1.ps < prev    next >
Text File  |  2004-09-01  |  8KB  |  204 lines

  1. %    Copyright (C) 1994, 2000 Aladdin Enterprises.  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_type1.ps,v 1.14.2.1 2004/08/31 04:03:30 ray Exp $
  14. % Type 1 font support code.
  15.  
  16. % The standard representation for PostScript compatible fonts is described
  17. % in the book "Adobe Type 1 Font Format", published by Adobe Systems Inc.
  18.  
  19. % Define an augmented version of .buildfont1 that inserts UnderlinePosition
  20. % and UnderlineThickness entries in FontInfo if they aren't there already,
  21. % and FontBBox isn't degenerate.
  22. % (This works around the incorrect assumption, made by many word processors,
  23. % that these entries are present in the built-in fonts.)
  24. /.buildfont1
  25.  {
  26.    dup .fontbbox {
  27.      pop pop pop pop
  28.      dup /FontInfo known not
  29.       { .growfontdict dup /FontInfo 2 dict put }
  30.      if
  31.      dup dup /FontInfo get dup dup
  32.      /UnderlinePosition known exch /UnderlineThickness known and
  33.       { pop pop        % entries already present
  34.       }
  35.       { dup length 2 add dict .copydict
  36.         dup /UnderlinePosition known not
  37.          { dup /UnderlinePosition 3 index /FontBBox get
  38.            1 get 2 div put             % 1/2 the font descent
  39.          }
  40.         if
  41.         dup /UnderlineThickness known not
  42.          { dup /UnderlineThickness 3 index /FontBBox get
  43.            dup 3 get exch 1 get sub 20 div put     % 1/20 the font height
  44.          }
  45.         if
  46.         1 index /FontInfo get wcheck not { readonly } if
  47.         /FontInfo exch put
  48.       }
  49.      ifelse
  50.    } if
  51.    //.buildfont1
  52.  } bind def
  53. % If the diskfont feature isn't included, define a dummy .loadfontdict.
  54. /.loadfontdict where
  55.  { pop }
  56.  { /.loadfontdict 0 dict readonly def }
  57. ifelse
  58. /.loadfontfile        % <file> .loadfontfile -
  59.  { mark exch
  60.    DISKFONTS { .loadfontdict begin } if
  61.     % In order to load fonts reliably, we should push systemdict
  62.     % here.  However, Ed Taft says that Adobe implementations
  63.     % push userdict and nothing else!
  64.     % We really would just like systemdict on the stack,
  65.     % but fonts produced by Fontographer require a writable dictionary.
  66.     % However, we can't use any of the other well-known dictionaries
  67.     % (such as userdict), since the whole point of pushing systemdict
  68.     % is to make sure that nothing important has been redefined.
  69.    userdict begin
  70.     % We can't just use `run', because we want to check for .PFB files.
  71.    currentpacking
  72.     { false setpacking .loadfont1 true setpacking }
  73.     { .loadfont1 }
  74.    ifelse end
  75.     { stop } if
  76.    DISKFONTS { end } if
  77.    cleartomark
  78.  } bind def
  79.  % container for CloseSource flag (default true to prevent buildup of file handles)
  80.  /closesourcedict mark
  81.    /CloseSource true
  82.  .dicttomark readonly def
  83. /.loadfont1 {        % <file> .loadfont1 <errorflag>
  84.   {    % We would like to use `false /PFBDecode filter',
  85.     % but this occasionally produces a whitespace character as
  86.     % the first of an eexec section, so we can't do it.
  87.     % Also, since the real input file never reaches EOF if we are using
  88.     % a PFBDecode filter (the filter stops just after reading the last
  89.     % character), we must explicitly close the real file in this case.
  90.     % Since the file might leave garbage on the operand stack,
  91.     % we have to create a procedure to close the file reliably.
  92.     dup read not { -1 } if
  93.     2 copy unread 16#80 eq {
  94.     dup //closesourcedict //true /PFBDecode filter cvx
  95.     exch .currentresourcefile eq {
  96.       dup /.execasresource .systemvar
  97.     } {
  98.       {exec}
  99.     } ifelse
  100.     2 index cvlit
  101.     /closefile .systemvar 3 .execn
  102.       } {
  103.     cvx exec
  104.     } ifelse
  105.   } stopped
  106. } bind def
  107. % undefine a dict that is only used internally, and is immediately bound
  108. currentdict /closesourcedict .undef
  109.  
  110. % Here are the BuildChar and BuildGlyph implementation for Type 1 fonts.
  111. % The names %Type1BuildChar and %Type1BuildGlyph are known to the interpreter.
  112. % The real work is done in an operator:
  113. %    <font> <code|name> <name> <charstring> .type1execchar -
  114.  
  115. (%Type1BuildChar)  cvn {    % <font> <code> %Type1BuildChar -
  116.   1 index /Encoding get 1 index get .type1build .type1execchar
  117. } bind def
  118. (%Type1BuildGlyph) cvn {    % <font> <name> %Type1BuildGlyph -
  119.   dup .type1build .type1execchar
  120. } bind def
  121. % Note: this procedure is used for both Type 1 and Type 2 fonts.
  122. /.type1build {        % <font> <code|name> <name> .type1build
  123.             %   <font> <code|name> <name> <charstring>
  124.   2 index begin
  125.     dup CharStrings exch .knownget not {
  126.       2 copy eq { exch pop /.notdef exch } if
  127.        QUIET not
  128.     { (Substituting .notdef for ) print = flush }
  129.     { pop }
  130.        ifelse
  131.        /.notdef CharStrings /.notdef get
  132.     } if
  133.   end
  134. } bind def
  135.  
  136. 1183615869 internaldict begin
  137. % CCRun is an undocumented procedure provided for Type 4 and Type 0 fonts.
  138. % Apparently there are two different argument lists for CCRun.
  139. % Handling the one with the extra Private dictionary requires fabricating
  140. % a Type 1 font on the fly, since we aren't currently prepared to parse the
  141. % dictionary any other way.
  142. /CCRun {    % <font> <code|name> <charstring> CCRun -
  143.         % <font> <code|name> <charstring> <Private> CCRun -
  144.   dup type /dicttype eq {
  145.     dup 4 index /Private .knownget { ne } { pop true } ifelse {
  146.         % The Private dictionary was supplied, and is different
  147.         % from the Private dictionary of the font.  Fabricate a
  148.         % Type 1 font with this Private dictionary.  Most of the
  149.         % font entries are arbitrary or not needed.
  150.       .currentglobal false .setglobal 10 dict exch .setglobal begin
  151.     /Private exch def
  152.     /FontType 1 def
  153.     /FontMatrix 3 index /FontMatrix get def
  154.     /Encoding 3 index /Encoding .knownget not { StandardEncoding } if def
  155.     /FontBBox 3 index /FontBBox .knownget not { {0 0 0 0} } if def
  156.     /PaintType 0 def
  157.     /CharStrings 1 dict dup /.notdef () put def
  158.       3 -1 roll pop () currentdict end .buildfont1 exch pop 3 1 roll
  159.     } {
  160.       pop
  161.     } ifelse
  162.   } if
  163.   1 index dup type /integertype eq {
  164.     3 index /Encoding get exch get
  165.   } if exch .type1execchar
  166. } bind def
  167.  
  168. % setweightvector is an undocumented procedure that force writes
  169. % weight vector to the font. Do extra checks for safety.
  170. /setweightvector { % <font> <vector> setweightvector -
  171.   dup type dup /arraytype ne exch /packedarraytype ne and
  172.   2 index type /dicttype ne or {
  173.     /setweightvector cvx /typecheck signalerror
  174.   } if
  175.   1 index /FontType known not {
  176.     /setweightvector cvx /invalidfont signalerror
  177.   } if
  178.   dup gcheck 2 index gcheck not and {
  179.     /setweightvector cvx /invalidaccess signalerror
  180.   } if
  181.   2 copy /WeightVector exch .forceput
  182.   .setweightvector
  183. } .bind executeonly def 
  184. end
  185.  
  186. % Register the font types for definefont.
  187. buildfontdict 1 /.buildfont1 cvx put
  188. buildfontdict 4 /.buildfont4 cvx put
  189.  
  190. % Add Type 2 support if applicable.
  191. /.buildfont2 where not { (%END2) .skipeof } if
  192. pop
  193. (%Type2BuildChar)  cvn {    % <font> <code> %Type2BuildChar -
  194.   1 index /Encoding get 1 index get .type1build .type2execchar
  195. } bind def
  196. (%Type2BuildGlyph) cvn {    % <font> <name> %Type2BuildGlyph -
  197.   dup .type1build .type2execchar
  198. } bind def
  199. buildfontdict 2 /.buildfont2 cvx put
  200. %END2
  201.