Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!apple!well!shiva From: shiva@well.sf.ca.us (Kenneth Porter) Newsgroups: comp.lang.postscript Subject: Re: PostScript downloadable font formats Summary: Adobe Binary Font (ABF) Decompression Keywords: postscript font download Message-ID: <20831@well.sf.ca.us> Date: 28 Sep 90 18:50:12 GMT References: <64@frcs.UUCP> <1579@chinacat.Unicom.COM> Distribution: comp Lines: 251 Sorry Woody, my PC fonts arrived in binary form, and I had to use Adobe's downloader to decrypt them. I used my Sun 386i DOS window to capture the ASCII output to a file. Once I had more time, I wrote a program to decrypt the Adobe binary format. /* Decompress .pfb file into .pfa file */ /* Copyright 1990 Kenneth Porter (shiva@well.sf.ca.us) This is freely re-distributable, NOT public domain. Adobe PostScript font files are distributed in a compressed binary format to be decompressed and downloaded to the printer by Adobe's download utilities. Since we want to download the fonts ourselves, this utility is necessary to convert the binary file into an ASCII file readable by the printer. */ #include #include #include /* pfb record types */ #define PFBTXT 0x180 /* followed by long byte count */ #define PFBBIN 0x280 /* followed by long byte count */ #define PFBEOF 0x380 char *ExitServerString = "%!PS-Adobe-2.0 ExitServer\n" "%%BeginExitServer: 0\n" "serverdict begin 0 exitserver\n" "%%EndExitServer\n"; int Mac2IBM(FILE *mac, FILE *ibm, unsigned long count); int Bin2Txt(FILE *bin, FILE *txt, unsigned long count); FILE *srcopen(char *name); FILE *dstopen(char *name); FILE *fileopen(char *name, char *mode, char *humanmode); unsigned long fgetl(FILE *f); void ExitServer(char *tempfile,char *dstfile); void CheckFontName(char *linebuf); void main(int argc, char *argv[]) { FILE *pfb, *pfa; unsigned long count; int eof = 0; unsigned rtype; /* pfb record type */ char temp[L_tmpnam]; banner(); if (argc < 3 || argc > 4) { fprintf(stderr,"syntax: %s [persistent]\n",argv[0]); exit(1); } pfb = srcopen(argv[1]); pfa = dstopen(tmpnam(temp)); while (!eof) { rtype = getw(pfb); if (feof(pfb)) { fprintf(stderr,"Unexpected end of file\n"); break; } switch (rtype) { case PFBEOF: eof = 1; break; case PFBTXT: count = fgetl(pfb); printf("Text count = %ld\n",count); if (feof(pfb)) { fprintf(stderr,"Unexpected end of file\n"); eof = 1; break; } if (Mac2IBM(pfb,pfa,count)) { fprintf(stderr,"Unexpected end of file\n"); eof = 1; break; } break; case PFBBIN: count = fgetl(pfb); printf("Bin count = %ld\n",count); if (feof(pfb)) { fprintf(stderr,"Unexpected end of file\n"); eof = 1; break; } if (Bin2Txt(pfb,pfa,count)) { fprintf(stderr,"Unexpected end of file\n"); eof = 1; break; } break; default: fprintf(stderr,"Record type %X not recognized\n",rtype); eof = 1; break; } } fclose(pfa); fclose(pfb); if (argc == 4) ExitServer(temp,argv[2]); else rename(temp,argv[2]); exit(0); } #define CR 13 /* Mac ends line with carriage return, IBM with CRLF */ int Mac2IBM(FILE *mac, FILE *ibm, unsigned long count) { int c; char *lp; static char linebuf[128]; linebuf[0] = 0; lp = linebuf; while (count--) { c = fgetc(mac); if (feof(mac)) return(EOF); if (c == CR) { fputc('\n',ibm); *lp = 0; CheckFontName(linebuf); linebuf[0] = 0; lp = linebuf; } else { fputc(c,ibm); *lp++ = c; } } *lp = 0; CheckFontName(linebuf); return(0); } int Bin2Txt(FILE *bin, FILE *txt, unsigned long count) { int c; unsigned long i; for (i=0; i