home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / clipart / gs22.zip / PFBTOPS.PS < prev    next >
Text File  |  1991-03-27  |  3KB  |  97 lines

  1. %    Copyright (C) 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. % pfbtops.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 should 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 120 dict def
  33. envPFB begin
  34.  
  35. % ------ The main program ------ %
  36.  
  37.    /pfbtops        % infilename outfilename pfbtops ->
  38.     { /psname exch def
  39.       /pfbname exch def
  40.  
  41.       pfbname (r) file /ifile exch def
  42.       /packet 6 string def
  43.       ifile packet readstring
  44.        { dup length 6 eq { 0 get 128 eq } { pop false } ifelse }
  45.        { pop false }
  46.       ifelse
  47.       not { (Not a valid .PFB file.\n) print flush stop } if
  48.  
  49.       ifile 0 setfileposition
  50.       psname (w) file /ofile exch def
  51.  
  52.        { ifile packet readstring
  53.          not { exit } if
  54.      packet 5 get 256 mul packet 4 get add
  55.      256 mul packet 3 get add 256 mul packet 2 get add
  56.      packet 1 get 1 sub
  57.       { { string ifile exch readstring pop
  58.            { (\r) search
  59.               { ofile exch writestring pop
  60.             ofile (\n) writestring
  61.           }
  62.           { ofile exch writestring exit
  63.           }
  64.          ifelse
  65.            } loop
  66.         }
  67.         { string ifile exch readstring pop
  68.            { dup length 30 gt
  69.               { dup 0 30 getinterval ofile exch writehexstring
  70.             ofile (\n) writestring
  71.             dup length 30 sub 30 exch getinterval
  72.           }
  73.           { ofile exch writehexstring exit
  74.           }
  75.          ifelse
  76.            } loop
  77.         }
  78.         { exit
  79.         }
  80.       } exch get exec
  81.        } loop
  82.  
  83.       ofile closefile
  84.       ifile closefile
  85.  
  86.     } bind def
  87.  
  88. end
  89.  
  90. % Enter the main program in the current dictionary.
  91. /pfbtops
  92.  { envPFB begin   pfbtops end
  93.  } bind def
  94.  
  95. % If the program was invoked from the command line, run it now.
  96. shellarguments { pfbtops } if
  97.