home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / gnu / gs252b.lzh / GS252B / PFBTOGS.PS < prev    next >
Text File  |  1993-07-30  |  3KB  |  115 lines

  1. %    Copyright (C) 1991, 1992 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. % pfbtogs.ps
  21. % Convert a PFB file to a Ghostscript font.
  22.  
  23. % A .pfb file is a sequence of packets.  Each packet starts with byte
  24. % 0x80.  The second byte in the packet gives the type of packet: 1
  25. % means it's a packet of ascii data which should be sent out as is
  26. % (except for translating \r to the appropriate end-of-line
  27. % character(s)); 2 means it's a packet of binary data (which may be
  28. % translated into hex); 3 means EOF.  For types 1 and 2, the type byte
  29. % is followed by four bytes giving the length of the packet, least
  30. % significant first.
  31.  
  32. /envPFB 20 dict def
  33. envPFB begin
  34.  
  35. % ------ Packet writing routines ------ %
  36.  
  37.    /pfbtext        % str ->
  38.      {  { (\r) search
  39.            { ofile exch writestring pop
  40.          ofile (\n) writestring
  41.        }
  42.        { ofile exch writestring exit
  43.        }
  44.       ifelse
  45.     } loop
  46.      } def
  47.  
  48.    /pfbbinary        % str ->
  49.     {  { dup length 30 gt
  50.           { dup 0 30 getinterval ofile exch writehexstring
  51.         ofile (\n) writestring
  52.         dup length 30 sub 30 exch getinterval
  53.       }
  54.       { ofile exch writehexstring exit
  55.       }
  56.      ifelse
  57.        } loop ofile (\n) writestring
  58.      } def
  59.  
  60.    /pfbcopy        % count proc ->
  61.     { exch        % proc count
  62.        { dup bufsize min
  63.          buf 0 3 -1 roll getinterval
  64.      2 index exec
  65.      bufsize sub dup 0 le { exit } if
  66.        } loop pop pop
  67.     } def
  68.  
  69. % ------ The main program ------ %
  70.  
  71.    /bufsize 30000 def
  72.    /buf bufsize string def
  73.  
  74.    /pfbtogs        % infilename outfilename pfbtogs ->
  75.     { /psname exch def
  76.       /pfbname exch def
  77.  
  78.       pfbname (r) file /ifile exch def
  79.       /packet 6 string def
  80.       ifile packet readstring
  81.        { dup length 6 eq { 0 get 128 eq } { pop false } ifelse }
  82.        { pop false }
  83.       ifelse
  84.       not { (Not a valid .PFB file.\n) print flush stop } if
  85.  
  86.       ifile 0 setfileposition
  87.       psname (w) file /ofile exch def
  88.  
  89.        { ifile packet readstring
  90.          not { exit } if
  91.      (packet: ) print packet { ( ) print =only } forall (\n) print flush
  92.      packet 5 get 256 mul packet 4 get add
  93.      256 mul packet 3 get add 256 mul packet 2 get add
  94.      packet 1 get 1 sub
  95.       { { { ifile exch readstring pop pfbtext } pfbcopy }
  96.         { { ifile exch readstring pop pfbbinary } pfbcopy }
  97.         { exit }
  98.       } exch get exec
  99.        } loop
  100.  
  101.       ofile closefile
  102.       ifile closefile
  103.  
  104.     } bind def
  105.  
  106. end
  107.  
  108. % Enter the main program in the current dictionary.
  109. /pfbtogs
  110.  { envPFB begin   pfbtogs end
  111.  } bind def
  112.  
  113. % If the program was invoked from the command line, run it now.
  114. shellarguments { pfbtogs } if
  115.