[comp.lang.postscript] PostScript downloadable font formats

paul@frcs.UUCP (Paul Nash) (09/14/90)

A client is planning to purchase some soft fonts for a PostScript
printer (Qume ScripTen). The supplier (who knows it all, of course :-)
says that as the fonts are for a Mac, they cannot be downloaded
from an IBM PClone. The supplier _says_ that they have tried copying
the fonts from a Mac to a PC, and then downloading, and it didn't
work.

My client is, however, about 500 miles away and I do not want to
have to travel there just to see whether or not this will be a 
problem.

Is this feasable? (That the font can be downloaded from a Mac and
not a PC). If so, is there anything that I can do for them, like
converting from Mac format to PC format? Has anyone done anything
like this before?

As I understand it, a PostScript font is merely a PS program that
describes the shape of the characters. Presumably there is some
sort of encrypting process, so that  fonts don't get modified and
stolen and so on. Is this correct, or likely?

Any replies (e-mail or posting) would be much appreciated.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 Paul Nash			 Flagship Wide Area Networks (Pty) Ltd
  paul@frcs.UUCP			  ...!ddsw1!proxima!frcs!paul

woody@chinacat.Unicom.COM (Woody Baker @ Eagle Signal) (09/17/90)

In article <64@frcs.UUCP>, paul@frcs.UUCP (Paul Nash) writes:
> 
> A client is planning to purchase some soft fonts for a PostScript
> printer (Qume ScripTen). The supplier (who knows it all, of course :-)
> says that as the fonts are for a Mac, they cannot be downloaded
> 
> Is this feasable? (That the font can be downloaded from a Mac and
> not a PC). If so, is there anything that I can do for them, like

It depends.  Adobe fonts do come in 2 flavors.  A PC flavor and a MAC
flavor.  Why this was done beats me.  At anyrate, rather than being a
straight text file on the MAC, the file is broken up into blocks
of data, each of which has a header.  I suspect that this was done to
make it difficult for a MAC font to be used on anything other than a MAC,
but that is just conjecture.  At anyrate, there is a document over on the
Adobe file server, that deals with this problem.   I believe it is
something like "supporting downloaded fonts".  It details the format
of the font file for both the MAC and PC.  Now, all the PC fonts
that I've seen have been plain jane ascii fonts.  It should be fairly
easy to let the MAC do all the work, but using the font downloader (send
ps I think) and let it parse out the font.  Then perhaps use the
cmd K to get it captured to a file as a true ascii font.  For other
peoples fonts, I don't think there is a problem. At least Cassidy
and Greene, and Century Software fonts are straight ASCII files.



> As I understand it, a PostScript font is merely a PS program that
> describes the shape of the characters. Presumably there is some
> sort of encrypting process, so that  fonts don't get modified and
Actualy that has all been documented in the Type 1 Font spec book now.

Cheers
Woody

> 

paul@frcs.UUCP (Paul Nash) (09/17/90)

A while back I wrote:

>A client is planning to purchase some soft fonts for a PostScript
>printer (Qume ScripTen). The supplier (who knows it all, of course :-)
>says that as the fonts are for a Mac, they cannot be downloaded
>from an IBM PClone.

A while later, Robert Elliott of Embossed Graphics replied (for which,
BTW, I am eternally grateful):

>Macs:  all data is stored in POST resources of one file (in the System
>Folder usually), and the eexec portion of the font is stored as full
>8bit characters rather than hex.  The Mac OS converts all this to an
>ASCII file on the fly when it sends it to the printer.

>There is a Mac program called unAdobe which will convert the Mac
>format into a standard ASCII file, which you could then send from
>any computer (UNIX, PCs, etc.)

Now I have but one problem -- I need to get hold of a copy of unAdobe
and a Mac. The Mac is not too bad -- one of the local DTP places will
let me use their -- but where can I get ``unAdobe''. Does anyone out
there have a copy that they are will to uuencode & mail to me? I am
assuming that it is public domain, and I know nothing about Mac-uuencode
(if such a beast exists). The machine that it will have to run on is a 
vanilla Mac II, not a hacker's machine, so it would not have compilers,
clever tools, &c.

If unAdobe is a commercial product, where do I get it?

For these and more, many thanks.

>-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> Paul Nash			 Flagship Wide Area Networks (Pty) Ltd
>  paul@frcs.UUCP			  ...!ddsw1!proxima!frcs!paul
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 Paul Nash			 Flagship Wide Area Networks (Pty) Ltd
  paul@frcs.UUCP			  ...!ddsw1!proxima!frcs!paul

paul@frcs.UUCP (Paul Nash) (09/17/90)

A while back I wrote:

>A client is planning to purchase some soft fonts for a PostScript
>printer (Qume ScripTen). The supplier (who knows it all, of course :-)
>says that as the fonts are for a Mac, they cannot be downloaded
>from an IBM PClone.

A while later, Robert Elliott of Embossed Graphics replied (for which,
BTW, I am eternally grateful):

>Macs:  all data is stored in POST resources of one file (in the System
>Folder usually), and the eexec portion of the font is stored as full
>8bit characters rather than hex.  The Mac OS converts all this to an
>ASCII file on the fly when it sends it to the printer.

>There is a Mac program called unAdobe which will convert the Mac
>format into a standard ASCII file, which you could then send from
>any computer (UNIX, PCs, etc.)

Now I have but one problem -- I need to get hold of a copy of unAdobe
and a Mac. The Mac is not too bad -- one of the local DTP places will
let me use their -- but where can I get ``unAdobe''. Does anyone out
there have a copy that they are will to uuencode & mail to me? I am
assuming that it is public domain, and I know nothing about Mac-uuencode
(if such a beast exists). The machine that it will have to run on is a 
vanilla Mac II, not a hacker's machine, so it would not have compilers,
clever tools, &c.

If unAdobe is a commercial product, where do I get it?

For these and more, many thanks.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 Paul Nash			 Flagship Wide Area Networks (Pty) Ltd
  paul@frcs.UUCP			  ...!ddsw1!proxima!frcs!paul

jv@mh.nl (Johan Vromans) (09/26/90)

>>>There is a Mac program called unAdobe which will convert the Mac
>>>format into a standard ASCII file, which you could then send from
>>>any computer (UNIX, PCs, etc.)

Impressive. 

I obtained good results the following way:
 - create a document using the desired fonts;
 - create a PostScript file using the Apple/F key in the print dialog;
 - cut the font descriptions out of the PostScript file.

Easy.

	Johan
-- 
Johan Vromans				       jv@mh.nl via internet backbones
Multihouse Automatisering bv		       uucp: ..!{uunet,hp4nl}!mh.nl!jv
Doesburgweg 7, 2803 PL Gouda, The Netherlands  phone/fax: +31 1820 62911/62500
------------------------ "Arms are made for hugging" -------------------------

shiva@well.sf.ca.us (Kenneth Porter) (09/29/90)

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 <stdio.h>
#include <stdlib.h>
#include <string.h>
 
/* 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 <PFB file> <PFA file>
[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<count; i++) {
        c = fgetc(bin);
        if (feof(bin)) return(EOF);
        fprintf(txt,"%02X",c);
        if ((i & 0x1F) == 0x1F) fputc('\n',txt);
    }
    if ((i & 0x1F) != 0x1F) fputc('\n',txt);
    return(0);
}
 
FILE *srcopen(char *name)
{
    return(fileopen(name,"rb","read"));
}
 
FILE *dstopen(char *name)
{
    return(fileopen(name,"wt","write"));
}
 
FILE *fileopen(char *name, char *mode, char *humanmode)
{
    FILE *file;
 
    file = fopen(name,mode);
    if (!file) {
        fprintf(stderr,"Failed to open %s for %s: %s\n",
            name,humanmode,strerror(errno));
        exit(1);
    }
    return(file);
}
 
unsigned long fgetl(FILE *f)
{
    unsigned long low, high;
 
    low = (unsigned) getw(f);
    high = (unsigned) getw(f);
    return(low+(high<<16));
}
 
char FontTest1[] =
"% Test for existence of font, abort if present.\n"
"% This won't work on a printer with a hard disk!\n"
"/str 32 string def\n";
 
char FontName[128];
 
char FontTest2[] =
" dup FontDirectory exch known\n"
"{ str cvs print ( is already loaded!\\n) print flush quit }\n"
"{ (loading font ) print str cvs print (\\n) print flush }\n"
"ifelse\n";
 
void ExitServer(char *tempfile,char *dstfile)
{
    FILE *tmp, *pfa;
    static char linebuf[128];
 
    pfa = dstopen(dstfile);
    fputs(ExitServerString,pfa);
    if (FontName[0]) {
        fputs(FontTest1,pfa);
        fputs(FontName,pfa);
        fputs(FontTest2,pfa);
    }
    tmp = srcopen(tempfile);
    fgets(linebuf,sizeof linebuf,tmp);
    while (!feof(tmp)) {
        fputs(linebuf,pfa);
        fgets(linebuf,sizeof linebuf,tmp);
    }
    fclose(tmp);
    unlink(tempfile);
    fclose(pfa);
}
 
char FontNameKey[] = "/FontName";
#define FNKL (sizeof FontNameKey - 1)   /* strlen(FontNameKey) */
 
void CheckFontName(char *linebuf)
{
    char *lp, *dp;
 
    if (!strncmp(FontNameKey,linebuf,FNKL)) {
        lp = &linebuf[FNKL];
        while (*lp == ' ') lp++;
        dp = FontName;
        while (*lp != ' ' && *lp != 0) *dp++ = *lp++;
        *dp = 0;
    }
}
 
void banner(void)
{
    printf("ABF Decompressor\n");
    printf("(c)1990 Kenneth Porter, all rights reserved\n");
}

P.S. I think the usage line got truncated in upload; the end should
read "...,argv[0]);".