🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.postscript
Article #7796

Re: Downloading Adobe fonts

#7796
From: jimi
Date: Tue, 10 Jan 1989 19:14
319 lines
7406 bytes
In article <755@ssp15.idca.tds.philips.nl>, jos@idca.tds.PHILIPS.nl (Jos Vos) writes:
> Is somebody having a simple program (to be used on UNIX) to download
> Adobe fonts to a PostScript printer?
> I've got a nice (?? :-) MS-Dos diskette with an MS-Dos application,
> but I want that application run on UNIX.
> 
> We already traced the PC-to-printer channel, and I assume I can find
> out how it is done (most of the font file is sent in hex, some parts
> are sent as-they-are), but it's always easier to get a ready-to-use
> program.

Here is a program that "`unpacks` IBM PC-format Adobe PostScript fonts
into a downloadable form" on UNIX systems.

Input is *___.PFB files from Adobe distribution diskettes; output is
fonts that are ready to be downloaded.

Usage: unfont [ -v ] [ files ]

	-v	Prints execution information on the standard error.

Example usage (unpacks IBM PC version of Adobe's Palatino Roman):

	unfont POR_____.PFB > PalatinoR.down

N.B. Be sure to delete my signature at the end of this posting.

__________________________________CUT_HERE______________________________________
/*
 * NOTICE
 *
 * Copyright 1988, 1989 by h-three Systems Corporation.
 *
 * Permission is hereby granted for this software's free reproduction
 * and modification for non-commercial purposes, provided that this
 * notice is retained. Commercial enterprises may give away copies
 * as part of their products provided that they do so without charge,
 * that they retain this notice, and that they acknowledge the source
 * of the software.
 *
 *	PostScript is a registered trademark of Adobe Systems Incorporated.
 *	IBM is a registered trademark of International Business Machines
 *	  Corporation.
 *
 *	h-three Systems Corporation
 *	100 Park Drive Suite 204/ P.O. Box 12557
 *	Research Triangle Park, NC  27709
 */

#ifdef NOWHAT
static char *sccsid = "%W% - %E%";
#endif

/*
 * unfont.c
 *
 * usage: unfont [ -v ] [ files ]
 *	-v 	Prints execution information on the standard error.
 *
 * Unpacks IBM PC-format PostScript fonts into a downloadable form.
 *
 */

char *USAGE = "\
usage: unfont [ -? ] [ -v ]  [files ]\n\
	-?	Prints this message.\n\
	-v 	Prints execution information on the standard error.\n\
";

#include <stdio.h>
#include <fcntl.h>
#include <ctype.h>
#include <varargs.h>

#define OK	0
#define FAILURE (-1)
#define Failed(x)	((x) == FAILURE)
#define TRUE	1
#define FALSE	0
typedef char bool;
#define STREQ(a,b)	(strcmp(a,b) == 0)

FILE *fp;

/*
 * used to convert nibbles (n0 is least sig) to ascii-hex
 */

#define N0(c)	    hexbyt[((c) & 0x000f)]
#define N1(c)	    N0((c) >> 4)

char hexbyt[] = "0123456789ABCDEF";

/*
 * vars controlled by command line options
 */

bool verbose = FALSE;			/* be verbose */

extern char *optarg;			/* getopt(3) control vars */
extern int optind;
extern int errno;

char *infile;

char *progname;				/* for error() */

char *strchr(), *strrchr();
long stol(), getparm();

int mygetc();
void dounfont();
long getcount();
void bintohex();

main(argc, argv)
int argc;
char **argv;
{
    register int c;
    bool showusage = FALSE;			/* usage error? */

    /*
     * figure out invocation leaf-name
     */

    if ((progname = strrchr(argv[0], '/')) == (char *) NULL)
	progname = argv[0];
    else
	progname++;

    argv[0] = progname;				/* for getopt err reporting */

    /*
     *	Check options and arguments.
     */

    progname = argv[0];
    while ((c = getopt(argc, argv, "v")) != EOF)
	switch (c)
	{
	    case 'v':				/* toggle verbose */
		verbose = ! verbose;
		break;

	    case '?':
		showusage = TRUE;
	}

    if (showusage)
    {
	(void) fprintf(stderr, "%s", USAGE);
	exit(1);
    }

/* unfont stuff		*/

    if (argv[optind])
    {
        for ( ; argv[optind]; optind++)
	{
	    if (!(fp = fopen(argv[optind], "r"))) {
		error(0, "can't open input file '%s'", argv[optind]);	
		continue;
	    }

	    infile = argv[optind];
	    dounfont();
	    close(fp);
	}
    }
    else
    {
	infile = "<stdin>";
	fp = stdin;
        dounfont();
    }
    exit(0);
}

long getcount();

void 
dounfont()
{
    register int c; 
    register int ch;
             long count;
    register int i;

    for (;;)
    {
	if ((c = mygetc()) != 0x80) {
		error(0, "not a proper font data segment '%s'", infile);
		error(0, "foobar char is 0x%x", c);
		exit(1);
	}
	c = mygetc();
	switch (c) {
	case 1:		
		/* get count, output count bytes to stdout	*/
		count = getcount();
		if (verbose)
		    fprintf(stderr, "case1 count is %ld\n", count);
		for (i=0; i<count; i++)
    			putchar(mygetc());
		break;
	case 2:		
		/* get count, convert count bytes to hex, output	*/
		/* to stdout						*/
		count = getcount();
		if (verbose)
		    fprintf(stderr, "case2 count is %ld\n", count);
		bintohex(count);
		break;
	case 3:		
		/* reached EOF; next file, please 			*/
		if (verbose)
		    fprintf(stderr, "logical eof encountered\n");
		return;

	default:
		error(0, "not a valid segment type '%s'", infile);	
		return;
	}
    }
}

/* 
 * getc for error-checking	
 */

int
mygetc()
{
	int ch;
    	if ((ch = getc(fp)) == -1) {
	    error(-1, "unexpected eof on input in '%s'", infile);
	    exit(1);
	}
    	return(ch);
}

/*
 * get count of bytes from segment header
 */

long
getcount()
{
	int i;
	long count = 0;

    	for (i=0; i<4; i++)
       		count += ((long) mygetc()) << (i * 8);
	return(count);
}

/* 
 * convert binary to ASCII hex and write it to stdout
 */

void
bintohex(count)
long count;
{
	int ch;
	long i;

	for (i=0; i<count; i++) {
	        if ((i % 30) == 0)
		    putchar('\n');
   		ch = mygetc();
    		putchar(N1(ch));
    		putchar(N0(ch));
	}
}

/* end of unfont stuff

/*
 * error(errn, arglist)
 *	report an error to stderr using printf(3) conventions.
 *	Any output is preceded by '<progname>: '
 *	If 'errn' is non-zero, it is assumed to be an 'errno' and its
 *	associated error message is appended to the output.
 */

/*VARARGS*/
error(errn, va_alist)
int errn;
va_dcl
{
    va_list arglist;
    register char *format;
    extern char *sys_errlist[];
    extern int sys_nerr;
    extern int errno;

    if (errn == -1)			    /* use errno if -1 */
	errn = errno;

    va_start(arglist);
    format = va_arg(arglist, char *);
    (void) fprintf(stderr, "%s: ", progname);
    (void) vfprintf(stderr, format, arglist);
    va_end(arglist);

    if (errn)
	if ((errn > 0) && (errn <= sys_nerr))
	    (void) fprintf(stderr, " (%s)\n", sys_errlist[errn]);
	else
	    (void) fprintf(stderr, " (unknown errno=%d)\n", errn);
    else
	(void) fprintf(stderr, "\n");
}
-- 
Jim Ingram	          uunet!h-three!jimi | jimi%h-three@uunet.uu.net
h-three Systems Corporation   P.O. Box 12557 RTP NC 27709   919 549 8334
Technical Details
Message-ID: <515@h-three.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!ames!xanth!mcnc!rti!h-three!jimi
References: <755@ssp15.idca.tds.philips.nl>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!ames!xanth!mcnc!rti!h-three!jimi
From: jimi@h-three.UUCP (jimi)
Newsgroups: comp.lang.postscript
Subject: Re: Downloading Adobe fonts
Summary: here is a font unpacking program
Message-ID: <515@h-three.UUCP>
Date: 10 Jan 89 19:14:27 GMT
References: <755@ssp15.idca.tds.philips.nl>
Organization: h-three Systems, Research Triangle Park,  NC
Lines: 319