v20i006: pfb2ps - conversion of binary encoded postscript files (.PFB), Part01/01
Erik Wallin
d87-ewa at nada.kth.se
Wed May 22 13:46:33 AEST 1991
Submitted-by: Erik Wallin <d87-ewa at nada.kth.se>
Posting-number: Volume 20, Issue 6
Archive-name: pfb2ps/part01
I received so many requests for this utility when I mentioned it in
comp.fonts that I decided to post the source here instead of mailing
it to everyone.
This a filter for converting postscript files encoded in a special
binary format used on PCs. (Called .PFB files.) The output will be an
ASCII text file that can be transferred to other systems or downloaded
to a printer.
The README describes how to obtain information about the binary format.
Erik Wallin <d87-ewa at nada.kth.se>
----------------- Cut here ---------------------------
: This is a shar archive. Extract with sh, not csh.
: This archive ends with exit, so do not worry about trailing junk.
echo 'Extracting README'
sed 's/^X//' > README << '+ END-OF-FILE README'
Xpfb2ps - filter for converting postscript fonts encoded as .PFB on a
XPC to plain ASCII.
X
XThis program is a simple conversion program based on information found
Xin a document called "Supporting downloadable Postscript fonts" by
XAdobe. It will convert a .PFB file (binary format for storing
XPostscript files on a PC) to plain ASCII.
X
XThe document mentioned above can be be obtained from Adobe's
Xfileserver. To get started send a mail, containing the single word help,
Xto <ps-file-server at adobe.com>. To get the document send
X"send Documents supportingfonts.ps". The document is also called
XTechnical note #5040.
X
X
XUSE
X
XTo use the program just pipe the .PFB file into pfb2ps. The plain text
Xrepresentation will be output on stdout.
X
XFor exapmle
X
X pfb2ps <melior.pfb >melior.ps
X
XThere is no conversion of CR/LF in pfb2ps. Therefore you might have to
Xsubstitute LF for CR if you move a file from PC to Unix.
X
X
XCOMPILING
X
XThere is no makefile since the program is only one file. Just compile
Xit with your favorite C-compiler.
X
X
XAUTHOR
X
XErik Wallin, student since 1987 at Computer Science and Engineering,
XRoyal Institute of Technology, Stockholm, Sweden
XInternet: d87-ewa at nada.kth.se
+ END-OF-FILE README
chmod 'u=rw,g=r,o=r' 'README'
echo ' -rw-r--r-- 1 d87-ewa 1178 May 15 16:10 README (as sent)'
echo -n ' '
/bin/ls -l README
echo 'Extracting pfb2ps.c'
sed 's/^X//' > pfb2ps.c << '+ END-OF-FILE pfb2ps.c'
X/* pfb2ps.c - Copyright 1991-05-12 Erik Wallin, d87-ewa at nada.kth.se.
X This program may be distributed freely, modified or included in
X other free programs long as this copyright notice is still
X included.
X
Xpfb2ps is a filter for converting postscript fonts stored in a binary
Xformat used by PC-programs. (.PFM files) The output will be a plain
Xtext file.
X
XNote that you have to pipe the .PFM file into pfb2ps.
X
X pfb2ps <xxx.pfb >xxx.ps
X*/
X#include <stdio.h>
X#include <malloc.h>
X
X#define HEX_PER_LINE 32
X
Xint getlen()
X{
X int c1,c2,c3,c4;
X c1 = getchar();
X c2 = getchar();
X c3 = getchar();
X c4 = getchar();
X return c1 + (256 * (c2 + 256 * (c3 + 256 * c4)));
X}
X
X
Xvoid main ()
X{
X int t, l, i;
X unsigned char *buf;
X
X while(!feof(stdin))
X {
X if (getchar() != 128)
X {
X fprintf(stderr, "Magic number (128) not found or no input on stdin.\n");
X exit (-1);
X }
X t = getchar();
X fprintf(stderr, "Type: %d, ", t);
X switch (t) {
X case 1:
X l = getlen();
X fprintf(stderr, " plain text, length %d\n", l);
X buf = (void *) malloc(l);
X if (fread(buf, sizeof(unsigned char), l, stdin) != l)
X {
X fprintf(stderr, "Wrong length of ascii field: %d or could not read file.\n", l);
X exit (-1);
X }
X if (fwrite(buf, sizeof(unsigned char), l, stdout) != l)
X {
X fprintf(stderr, "Could not write stdout.\n");
X exit (-1);
X }
X free(buf);
X break;
X case 2:
X l = getlen();
X fprintf(stderr, " binary data, length %d\n", l);
X buf = (void *) malloc(l);
X if (fread(buf, sizeof(unsigned char), l, stdin) != l)
X {
X fprintf(stderr, "Wrong length of binary field: %d or could not read file.\n", l);
X exit (-1);
X }
X for(i = 0;i < l ;i++)
X {
X printf("%2.2X", buf[i]);
X if (!((i+1) % HEX_PER_LINE))
X printf("\n");
X }
X printf("\n");
X free(buf);
X break;
X case 3:
X fprintf(stderr, "End of file\n");
X exit(0);
X break;
X default:
X {
X fprintf(stderr, "Unknown field type: %d\n", t);
X exit(-1);
X }
X }
X }
X}
+ END-OF-FILE pfb2ps.c
chmod 'u=rw,g=r,o=r' 'pfb2ps.c'
echo ' -rw-r--r-- 1 d87-ewa 2076 May 15 16:16 pfb2ps.c (as sent)'
echo -n ' '
/bin/ls -l pfb2ps.c
exit 0
----------------- Cut here ---------------------------
exit 0 # Just in case...
--
Kent Landfield INTERNET: kent at sparky.IMD.Sterling.COM
Sterling Software, IMD UUCP: uunet!sparky!kent
Phone: (402) 291-8300 FAX: (402) 291-4362
Please send comp.sources.misc-related mail to kent at uunet.uu.net.
More information about the Comp.sources.misc
mailing list