% Copyright (C) 1991, 1992 Aladdin Enterprises. All rights reserved.
% Distributed by Free Software Foundation, Inc.
% This file is part of Ghostscript.
% Ghostscript is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
% to anyone for the consequences of using it or for whether it serves any
% particular purpose or works at all, unless he says so in writing. Refer
% to the Ghostscript General Public License for full details.
% Everyone is granted permission to copy, modify and redistribute
% Ghostscript, but only under the conditions described in the Ghostscript
% General Public License. A copy of this license is supposed to have been
% given to you along with Ghostscript so you can know your rights and
% responsibilities. It should be in a file named COPYING. Among other
% things, the copyright notice and this notice must be preserved on all
% Convert a PFB file to a Ghostscript font.
% A .pfb file is a sequence of packets. Each packet starts with byte
% 0x80. The second byte in the packet gives the type of packet: 1
% means it's a packet of ascii data which should be sent out as is
% (except for translating \r to the appropriate end-of-line
% character(s)); 2 means it's a packet of binary data which should be
% translated into hex; 3 means EOF. For types 1 and 2, the type byte
% is followed by four bytes giving the length of the packet, least
% ------ Packet writing routines ------ %
{ ofile exch writestring pop
{ ofile exch writestring exit
{ dup 0 30 getinterval ofile exch writehexstring
dup length 30 sub 30 exch getinterval
{ ofile exch writehexstring exit
} loop ofile (\n) writestring
buf 0 3 -1 roll getinterval
bufsize sub dup 0 le { exit } if
% ------ The main program ------ %
/pfbtogs % infilename outfilename pfbtogs ->
pfbname (r) file /ifile exch def
{ dup length 6 eq { 0 get 128 eq } { pop false } ifelse }
not { (Not a valid .PFB file.\n) print flush stop } if
psname (w) file /ofile exch def
{ ifile packet readstring
packet 5 get 256 mul packet 4 get add
256 mul packet 3 get add 256 mul packet 2 get add
{ { { ifile exch readstring pop pfbtext } pfbcopy }
{ { ifile exch readstring pop pfbbinary } pfbcopy }
% Enter the main program in the current dictionary.
{ envPFB begin pfbtogs end
% If the program was invoked from the command line, run it now.
shellarguments { pfbtogs } if