/* * bradfont.c - converts BRADFORD .BIN fonts into source form * * Author: Roger Burrows * Version: 1.0 * Date: 26 September 1986 * * * Reads a .BIN file produced by BRADCON and converts it back into the * corresponding source, in a form suitable for input to BRADCON. If * you're not familiar with this terminology, see "Background" for * further details. * * * Syntax: * bradfont fontid * where * fontid is a single-character alphanumeric font identifier * * * Example: * bradfont 9 * reads file FONT9.BIN on the current default drive and creates a file * FONT9B also on the current default drive. * * * Modification history: * v1.0 86.ix.26 original source * * * Background * ---------- * Bradford is a program that produces near-letter-quality print output * on standard dot-matrix printers. The program is copyrighted by the * author: * Aaron Contorer * Concom Enterprises * 1521 Central Avenue * Deerfield, IL 60015 * U.S.A. * but may be used and copied freely (the manual is not free, but may be * obtained from the author for a reasonable fee). Bradford may print * in one or more special fonts whose letter shapes are defined in a * special format in .BIN files; these files are also supplied by the * author of Bradford. * The author has also provided a conversion program, BRADCON, that * converts a source file in a human-readable text format into the * corresponding .BIN format. The only source-format file that has * been distributed by the author is the source for FONT1.BIN. */ #include #define VERSION "1.0" #define INFILE "FONT%s.BIN" /* format of input file name */ #define OUTFILE "FONT%sB" /* format of output file name */ #define MAGIC1 95 /* value of first word in input file */ #define MAGIC2 21 /* value of second word in input file */ #define NUMCHARS 95 /* # characters described in input file */ /* (probably always same as MAGIC1) */ #define CHARSIZE 18 /* # bytes to describe each char in input */ #define CHARFILL 3 /* # bytes between each char in input */ /* (probably MAGIC2 = CHARSIZE+CHARFILL) */ #define LINESIZE (CHARSIZE/2) /* max size of o/p line (excl newline, null) */ #define BYTESIZE 8 /* # bits per byte */ #define MARK 'x' /* marks a dot in text output */ #define SPACE ' ' /* marks a space in text output */ char in[NUMCHARS][CHARSIZE]; /* input data for entire font */ char out[BYTESIZE][CHARSIZE]; /* output data for one character */ char line[LINESIZE+2]; /* output line gets built here */ char mask[BYTESIZE]; /* bit masks to examine each byte */ main(argc,argv) int argc; char **argv; { int i, j, k; char infile[20], inbuf[BUFSIZ]; char outfile[20], outbuf[BUFSIZ]; initialise(argc,argv[1]); /* check arg, set up mask[] */ sprintf(infile,INFILE,argv[1]); /* open input */ if (fopen(infile,inbuf) == ERROR) error("can't open input file %s\n",infile); else if ((getw(inbuf) != MAGIC1) || (getw(inbuf) != MAGIC2)) error("input file %s doesn't seem to be a font file\n",infile); printf("reading input file %s\n",infile); for (i = 0; i < NUMCHARS; i++) /* read in entire font */ readdata(infile,inbuf,&in[i][0]); fclose(inbuf); /* close input */ sprintf(outfile,OUTFILE,argv[1]); /* open output */ if (fcreat(outfile,outbuf) == ERROR) error("can't create output file %s\n",outfile); printf("writing output file %s\n",outfile); for (i = 0; i < NUMCHARS; i++) { for (j = 0; j < CHARSIZE; j++) { /* sourcify (?) */ for (k = 0; k < BYTESIZE; k++) { if (in[i][j] & mask[k]) out[k][j] = MARK; else out[k][j] = SPACE; } } writedata(outfile,outbuf,&out[0][0]); /* & write */ } if (putc(CPMEOF,outbuf) == ERROR) /* cp/m likes ctl-z */ error("error writing output file %s\n",outfile); fflush(outbuf); fclose(outbuf); printf("done\n"); } /* * issue error message & exit */ error(fmt,str) char *fmt, *str; { printf(fmt,str); exit(); } /* * initialise stuff */ initialise(argc,p) int argc; char *p; { int i; printf("bradfont v%s: binary to source conversion for bradford fonts\n", VERSION); if (argc != 2) /* validate parameter */ usage(); if (strlen(p) != 1) usage(); if (!isdigit(*p) && !isalpha(*p)) usage(); for (i = 0; i < BYTESIZE; i++) /* set up mask (speedier ?) */ mask[i] = 0x80 >> i; } /* * read a font character */ readdata(infile,inbuf,in) char *infile, *inbuf, *in; { int i, c; for (i = 0; i < (CHARSIZE+CHARFILL); i++) { /* read data */ if ((c = getc(inbuf)) == ERROR) error("input file %s is too short\n",infile); if (i < CHARSIZE) /* skip filler */ *in++ = c; } } /* * issue a usage message & exit */ usage() { printf("usage: bradfont fontid\n"); exit(); } /* * write a font character */ writedata(outfile,outbuf,out) char *outfile, *outbuf, out[BYTESIZE][CHARSIZE]; { int i; for (i = 0; i < BYTESIZE; i++) { /* write interleaved lines */ writeline(outfile,outbuf,out[i]); writeline(outfile,outbuf,out[i]+LINESIZE); } } /* * write a font line */ writeline(outfile,outbuf,p) char *outfile, *outbuf, *p; { int i; char *q, *x; for (i = 0, x = q = line; i < LINESIZE; i++) { if ((*q++ = *p++) != SPACE) /* if a non-SPACE, save */ x = q; /* ptr to next posn */ } *x++ = '\n'; *x = '\0'; if (fputs(line,outbuf) == ERROR) error("error writing output file %s\n",outfile); }