home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Impressora_PDF / converter.exe / GPLGS / gs_diskf.ps < prev    next >
Text File  |  2002-02-22  |  8KB  |  225 lines

  1. %    Copyright (C) 1996 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_diskf.ps,v 1.4 2002/02/21 21:49:28 giles Exp $
  14. % Support for converting Type 1 fonts without eexec encryption to
  15. % Type 4 fonts that load individual character outlines on demand.
  16.  
  17. % If DISKFONTS is true, we load individual CharStrings as they are needed.
  18. % (This is intended primarily for machines with very small memories.)
  19. % Initially, the character definition is the file position of the definition;
  20. % this gets replaced with the actual CharString.
  21. % Note that if we are loading characters lazily, CharStrings is writable.
  22.  
  23. % _Cstring must be long enough to hold the longest CharString for
  24. % a character defined using seac.  This is lenIV + 4 * 5 (for the operands
  25. % of sbw, assuming div is not used) + 2 (for sbw) + 3 * 5 (for the operands
  26. % of seac other than the character codes) + 2 * 2 (for the character codes)
  27. % + 2 (for seac), i.e., lenIV + 43.
  28.  
  29. /_Cstring 60 string def
  30.  
  31. % When we initially load the font, we call
  32. %    <index|charname> <length> <readproc> cskip_C
  33. % to skip over each character definition and return the file position instead.
  34. % This substitutes for the procedure
  35. %    <index|charname> <length> string currentfile exch read[hex]string pop
  36. %      [encrypt]
  37. % What we actually store in the CharString is fileposition * 1000 + length,
  38. %   negated if the string is stored in binary form.
  39.  
  40. /cskip_C
  41.  { exch dup 1000 ge 3 index type /nametype ne or
  42.     { % This is a Subrs string, or the string is so long we can't represent
  43.       % its length.  Load it now.
  44.       exch exec
  45.     }
  46.     { % Record the position and length, and skip the string.
  47.       dup currentfile fileposition 1000 mul add
  48.       2 index 3 get /readstring cvx eq { neg } if
  49.       3 1 roll
  50.       dup _Cstring length idiv
  51.        { currentfile _Cstring 3 index 3 get exec pop pop
  52.        } repeat
  53.       _Cstring length mod _Cstring exch 0 exch getinterval
  54.       currentfile exch 3 -1 roll 3 get exec pop pop
  55.     }
  56.    ifelse
  57.  } bind def
  58.  
  59. % Load a CharString from the file.  The font is the top entry
  60. % on the dictionary stack.
  61. /load_C        % <charname> <fileposandlength> load_C -
  62.  { dup abs 1000 idiv FontFile exch setfileposition
  63.    CharStrings 3 1 roll
  64.    .currentglobal CharStrings .gcheck .setglobal exch
  65.    dup 0 lt
  66.     { neg 1000 mod string FontFile exch readstring }
  67.     { 1000 mod string FontFile exch readhexstring }
  68.    ifelse pop
  69.    exch .setglobal
  70. % If the CharStrings aren't encrypted on the file, encrypt now.
  71.    Private /-| get 0 get
  72.    dup type /nametype ne
  73.     { dup length 5 sub 5 exch getinterval exec }
  74.     { pop }
  75.    ifelse dup 4 1 roll put
  76. % If the character is defined with seac, load its components now.
  77.    mark exch seac_C
  78.    counttomark
  79.     { StandardEncoding exch get dup CharStrings exch get
  80.       dup type /integertype eq { load_C } { pop pop } ifelse
  81.     } repeat
  82.    pop        % the mark
  83.  } bind def
  84.  
  85. /seac_C        % <charstring> seac_C <achar> <bchar> ..or nothing..
  86.  { dup length _Cstring length le
  87.     { 4330 exch _Cstring .type1decrypt exch pop
  88.       dup dup length 2 sub 2 getinterval <0c06> eq    % seac
  89.        { dup length
  90.          Private /lenIV known { Private /lenIV get } { 4 } ifelse
  91.      exch 1 index sub getinterval
  92. % Parse the string just enough to extract the seac information.
  93. % We assume that the only possible operators are hsbw, sbw, and seac,
  94. % and that there are no 5-byte numbers.
  95.      mark 0 3 -1 roll
  96.       { exch
  97.          { { dup 32 lt
  98.               { pop 0 }
  99.           { dup 247 lt
  100.              { 139 sub 0 }
  101.              { dup 251 lt
  102.             { 247 sub 256 mul 108 add 1 1 }
  103.             { 251 sub -256 mul -108 add -1 1 }
  104.                ifelse
  105.              }
  106.             ifelse
  107.           }
  108.          ifelse
  109.            }            % 0
  110.            { mul add 0 }        % 1
  111.          }
  112.         exch get exec
  113.       }
  114.      forall pop
  115.      counttomark 1 add 2 roll cleartomark    % pop all but achar bchar
  116.        }
  117.        { pop    % not seac
  118.        }
  119.       ifelse
  120.     }
  121.     { pop    % punt
  122.     }
  123.    ifelse
  124.  } bind def
  125.  
  126. % Define replacement procedures for loading fonts.
  127. % If DISKFONTS is true and the body of the font is not encrypted with eexec:
  128. %    - Prevent the CharStrings from being made read-only.
  129. %    - Substitute a different CharString-reading procedure.
  130. % (eexec disables this because the implicit 'systemdict begin' hides
  131. % the redefinitions that make the scheme work.)
  132. % We assume that:
  133. %    - The magic procedures (-|, -!, |-, and |) are defined with
  134. %    executeonly or readonly;
  135. %    - The contents of the reading procedures are as defined in bdftops.ps;
  136. %    - The font includes the code
  137. %    <font> /CharStrings <CharStrings> readonly put
  138. /.loadfontdict 6 dict def mark
  139.  /begin            % push this dict after systemdict
  140.   { dup begin
  141.     //systemdict eq { //.loadfontdict begin } if
  142.   } bind
  143.  /end            % match begin
  144.   { currentdict end
  145.     //.loadfontdict eq currentdict //systemdict eq and { end } if
  146.   } bind
  147.  /dict            % leave room for FontFile, BuildChar, BuildGlyph
  148.   { 3 add dict
  149.   } bind
  150.  /executeonly        % for reading procedures
  151.   { readonly
  152.   }
  153.  /noaccess        % for Subrs strings and Private dictionary
  154.   { readonly
  155.   }
  156.  /readonly        % for procedures and CharStrings dictionary
  157.   {    % We want to take the following non-standard actions here:
  158.       %   - If the operand is the CharStrings dictionary, do nothing;
  159.     %   - If the operand is a number (a file position replacing the
  160.     %    actual CharString), do nothing;
  161.     %   - If the operand is either of the reading procedures (-| or -!),
  162.     %    substitute a different one.
  163.     dup type /dicttype eq        % CharStrings or Private
  164.     count 2 gt and
  165.      { 1 index /CharStrings ne { readonly } if }
  166.      { dup type /arraytype eq        % procedure or data array
  167.     { dup length 5 ge 1 index xcheck and
  168.        { dup 0 get /string eq
  169.          1 index 1 get /currentfile eq and
  170.          1 index 2 get /exch eq and
  171.          1 index 3 get dup /readstring eq exch /readhexstring eq or and
  172.          1 index 4 get /pop eq and
  173.           { /cskip_C cvx 2 packedarray cvx
  174.           }
  175.           { readonly
  176.           }
  177.          ifelse
  178.        }
  179.        { readonly
  180.        }
  181.       ifelse
  182.     }
  183.     { dup type /stringtype eq    % must be a Subr string
  184.        { readonly }
  185.       if
  186.     }
  187.        ifelse
  188.      }
  189.     ifelse
  190.   } bind
  191.  /definefont        % to insert BuildChar/Glyph and change FontType
  192.   { dup /FontType get 1 eq
  193.      { dup /FontType 4 put
  194.        dup /BuildChar /build_C load put
  195.        dup /BuildGlyph /build_C load put
  196.      }
  197.     if definefont
  198.   } bind
  199. counttomark 2 idiv { .loadfontdict 3 1 roll put } repeat pop
  200. .loadfontdict readonly pop
  201.  
  202. % Define the BuildChar and BuildGlyph procedures for modified fonts.
  203. % A single procedure serves for both.
  204. /build_C        % <font> <code|name> build_C -
  205.  { 1 index begin
  206.    dup dup type /integertype eq { Encoding exch get } if
  207.         % Stack: font code|name name
  208.    dup CharStrings exch .knownget not
  209.     { 2 copy eq { exch pop /.notdef exch } if
  210.       QUIET not
  211.        { (Substituting .notdef for ) print = flush }
  212.        { pop }
  213.       ifelse
  214.       /.notdef CharStrings /.notdef get
  215.     } if
  216.         % Stack: font code|name name charstring   
  217.    dup type /integertype eq
  218.     { load_C end build_C }
  219.     { end .type1execchar }
  220.    ifelse
  221.  } bind def
  222.