home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright 1989, 1990, 1991 Chris Lewis
- All Rights Reserved
-
- Permission to copy and further distribute is freely given provided
- this copyright notice remains intact, that this software is not
- sold for profit, that credit is given, and that sources will be made
- available on request.
-
- This software is a subset of Psroff 3.0. See the LICENSE file
- in Psroff 3.0 for more details, or contact:
-
- Chris Lewis
- Box 124
- Dunrobin, Ontario
- Canada K0A 1T0
- (613) 832-0541
-
- Function: interprets HPLJ sequences.
- */
-
- #ifndef lint
- static char SCCSID[] =
- "@(#)hpp.c %I% Copyright %E% %U%";
- #endif
-
- #include "hptopbm.h"
-
- #define XSIZE (RITE_MARGIN+8)*30
- #define YSIZE (PAGE_LEN*50)+50
-
- #define dbprintf(x) if (verbose) printf x
- #define ESCAPE 0x1b
-
- #define TRANSFER 1
- #define TRANSPARENT 2
- #define FONTHEADER 3
- #define DOWNLOAD 4
-
- #define ABSOLUTE 0
- #define RELATIVE 1
-
- #define MAC_BUFSIZE 4096
-
- #ifdef FAXPAK
- struct FAXCONFIG fc;
- int blah = 0;
- #endif
-
- union t {
- char a[2];
- short b;
- };
- int smallend;
-
- typedef int(*FUNC)();
-
- int firstchar = 0;
- int lastchar = 0xff;
- int lastschar;
- int lastfontid = -1;
- int verbose = 0;
- int plotch = 0;
- int rast = 0, rast_org = 0;
- int characteristic = 1;
- int ps_symset = 0;
- int dotted = 0;
- int pbmpage = 0;
- int movetype = 0;
- int mac_ctr = 0;
- int need_mac_end_call = 0;
- int have_auto_macro = -1;
- int builtin = -1;
-
- int ps_pointsize = 10;
- int ps_style = 1;
- int ps_stroke = 0;
- int ps_tface = 5;
- int ps_spacing = 0;
- int genps = 0;
-
- FILE *out = (FILE *) NULL;
- FILE *txtout = (FILE *) NULL;
- FILE *infp = (FILE *) NULL;
- char *PGM;
- extern int errno;
-
- char pbmname[256], pbmtname[256];
- uchar McBuffer[MAC_BUFSIZE], *CurMc, *CurMc_Ptr, *CurMc_End, *rs_get_macro();
-
- double curX = 0, curY = 0;
-
- short pts[] = {6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 28, 36, 4, 4};
-
- void exit();
-
- int (*getchar_func)();
- int getc_only(), /* get input from file */
- getc_copy(), /* get it from file AND copy to macro */
- mgetc(), /* get it from stashed away macro */
- auto_getc(); /* same, but exec on every page */
-
- char *fchcont[] = {
- "Delete all fonts",
- "Delete all temporary fonts",
- "Delete last font ID specified",
- "Delete last font ID and char code",
- "Make Temp font",
- "Make Perm font",
- "Copy/Assign",
- NULL
- };
-
- char *spcont[] = {
- "Fixed",
- "Proportional",
- NULL
- };
-
- char *stcont[] = {
- "Upright",
- "Italic",
- NULL
- };
-
- char *tfcont[] = {
- "Line Printer",
- "Pica",
- "Elite",
- "Courier",
- "Helvetica",
- "Times Roman",
- "Gothic",
- "Script",
- "Prestige Elite",
- "Caslon",
- "Orator",
- NULL
- };
-
- char *sgcont[] = {
- "Left-most position",
- "Current Cursor",
- NULL
- };
-
- char *pscont[] = {
- "Disable",
- "Enable",
- NULL
- };
-
-
- int movex(),movey(), papinctrl(), movedx(), movedy();
- int spset(), psset(), styset(), strset(), tfset();
- int macro_id(), macro_ctl();
- int rs_lpi(), rs_plen(), rs_mtop(),
- create_fnthdr(), rs_dpi(), rs_graphxy(),
- rs_pitch(), rs_tlen(), rs_mleft(), rs_mright(),
- rs_vmi(), rs_row(), rs_col(), rs_ul(), rs_thru(),
- rs_hmi(), rs_lterm(), rs_setpitch(),
- rs_fc_ctl(), rs_stack(), rs_hsize(), rs_hdsize(),
- rs_vsize(), rs_vdsize(), rs_pid(), rs_prnpat();
-
- struct intlist {
- char *code;
- char *name;
- char **parmnames;
- FUNC exec;
- FUNC rastfunc;
- } intlist[] = {
-
- /* code name parnam exec rastfunc */
-
- {"&lO", "Orientation" /* don't want to go into landscaping */ },
- {"(sP", "Primary Spacing", spcont, spset },
- {"(sH", "Primary Pitch", NULL, NULL, rs_pitch },
- {"(sV", "Primary Point Size", NULL, psset },
- {"(sS", "Primary Style", stcont, styset },
- {"(sB", "Primary Stroke", NULL, strset },
- {"(sT", "Primary Typeface", tfcont, tfset },
- {")sP", "Secondary Spacing", spcont, spset },
- {")sH", "Secondary Pitch" },
- {")sV", "Secondary Point Size" },
- {")sS", "Secondary Style", stcont },
- {")sB", "Secondary Stroke" },
- {")sT", "Secondary Typeface" },
- {"&lP", "Page Length", NULL, NULL, rs_plen },
- {"&lE", "Top Margin", NULL, NULL, rs_mtop },
- {"&lF", "Text Length", NULL, NULL, rs_tlen },
- {"&aL", "Left Margin", NULL, NULL, rs_mleft },
- {"&aM", "Right Margin", NULL, NULL, rs_mright },
- {"&lC", "Motion Index", NULL, NULL, rs_vmi },
- {"&lD", "Lines/Inch", NULL, NULL, rs_lpi },
- {"*tR", "Resolution", NULL, NULL, rs_dpi },
- {"*rA", "Start Graphics", sgcont, NULL, rs_graphxy },
- {"*bW", "Transfer" },
- {"*rB", "End Graphics" },
- {"&aR", "Move to Row", NULL, NULL, rs_row },
- {"&aC", "Move to Column", NULL, NULL, rs_col },
- {"&aH", "Move to Column (Decipoints)",NULL,movedx },
- {"&aV", "Move to Row (Decipoints)",NULL,movedy },
- {"&dD", "Underline on", NULL, NULL, rs_ul },
- {"&d@", "Underline off", NULL, NULL, rs_ul },
- {"&pX", "Transparent Print", NULL, NULL, rs_thru },
- {"&lL", "Perf Skip", pscont },
- {"&kH", "HMI", NULL, NULL, rs_hmi },
- {"&kS", "Font Pitch", NULL, NULL, rs_setpitch },
- {"&kG", "Line Termination", NULL, NULL, rs_lterm },
- {"&sC", "Line Wrap" },
- {"&lX", "Number of Copies" },
- {"&lH", "Paper Input Control", NULL, papinctrl },
- {"*pX", "Horizontal cursor (dots)",NULL,movex },
- {"*pY", "Vertical cursor (dots)",NULL, movey },
- {"*cD", "Font ID" },
- {"*cE", "Character Code" },
- {"*cF", "Font/Char control", fchcont,NULL, rs_fc_ctl },
- {")sW", "Create Font Header" },
- {"(sW", "Download Character" },
- {"&fY", "Macro ID", NULL, NULL, macro_id },
- {"&fX", "Macro control", NULL, NULL, macro_ctl },
- {"&fS", "Push/Pop", NULL, NULL, rs_stack },
- {"*cA", "Horizontal Rule/Pattern Size",NULL,NULL, rs_hsize },
- {"*cH", "Horizontal Rule/Pattern Size",NULL,NULL, rs_hdsize },
- {"*cB", "Vertical Rule/Pattern Size",NULL,NULL, rs_vsize },
- {"*cV", "Vertical Rule/Pattern Size",NULL,NULL, rs_vdsize },
- {"*cP", "Print Rule/Pattern" ,NULL, NULL, rs_prnpat },
- {"*cG", "Grey scale/pattern id",NULL, NULL, rs_pid },
- {"&lT", "Job offset control" },
- {NULL,NULL}
- };
-
- union {
- struct fontdesc b_fd;
- struct download b_dl;
- char b_buffer[2048];
- } buffer;
-
- #ifndef lint
- die(va_alist)
- va_dcl {
- va_list args;
- char *fmt;
- int e;
-
- e = errno; /* save him just in case */
- va_start(args);
- fmt = va_arg(args, char *);
- #ifndef LOG
- if (e)
- fprintf(stderr,"%s: {%02d} ", PGM, errno);
- else fprintf(stderr,"%s: ",PGM);
- vfprintf(stderr, fmt, args);
- #else
- if (e)
- printf("%s: {%02d} ", PGM, errno);
- else printf("%s: ",PGM);
- vprintf(fmt, args);
- #endif
- va_end(args);
- exit(e);
- }
- #else
- /*VARARGS*/
- die(){}
- #endif
-
- getc_only() {
- return(getc(infp));
- }
-
- getc_copy() {
- int c;
-
- if ((c = getc(infp)) != EOF) {
- McBuffer[mac_ctr++] = c;
- if (mac_ctr == MAC_BUFSIZE) {
- mac_download(MAC_BUFSIZE, McBuffer);
- mac_ctr = 0;
- }
- }
- return(c);
- }
-
- mgetc() {
- int c;
-
- c = *CurMc_Ptr++;
- if (CurMc_Ptr == CurMc_End) {
- getchar_func = getc_only;
- if (need_mac_end_call) {
- rs_call_macro(RESTORE);
- need_mac_end_call = FALSE;
- }
- }
- return(c);
- }
-
- auto_getc() {
- if (CurMc_Ptr == CurMc_End)
- return(EOF);
- return(*CurMc_Ptr++);
- }
-
- readhex(len)
- int len; {
- while(len--)
- (void)(*getchar_func)();
- }
-
- interp(prefix, anchor, number, suffix)
- char prefix, anchor, suffix;
- double number; {
- int multi;
- register int i;
- char lookup[4];
-
- dbprintf(("ESC%c%c%g%c\n", prefix, anchor, number, suffix));
-
- if (islower(suffix))
- suffix = toupper(suffix);
-
- sprintf(lookup, "%c%c%c", prefix, anchor, suffix);
- for (i = 0; intlist[i].code; i++) {
- if (0 == strcmp(intlist[i].code, lookup)) {
- dbprintf(("%s:", intlist[i].name));
- if (intlist[i].parmnames) {
- int j, ii;
- ii = (int)number;
- for (j = 0; j < ii; j++)
- if (!intlist[i].parmnames[j])
- break;
-
- if (intlist[i].parmnames[j])
- dbprintf((" %s\n", intlist[i].parmnames[j]));
- else
- dbprintf((" %d\n", (int) number));
- }
- else
- dbprintf ((" %g\n", number));
-
- if (intlist[i].exec)
- (*intlist[i].exec)(number);
- if (rast && intlist[i].rastfunc)
- (*intlist[i].rastfunc)(number);
- break;
- }
- }
-
- multi = 0;
- /* For parsing variable length ones */
- switch(prefix) {
- case '*':
- if (anchor == 'b' && suffix == 'W')
- multi = TRANSFER;
- break;
- case '&':
- if (anchor == 'p' && suffix == 'X')
- multi = TRANSPARENT;
- break;
- case ')':
- if (anchor == 's' && suffix == 'W')
- multi = FONTHEADER;
- break;
- case '(':
- if (anchor == 's' && suffix == 'W')
- multi = DOWNLOAD;
- break;
- }
-
- if (prefix == '*' && anchor == 'c' && suffix == 'E')
- lastschar = number;
-
- if (prefix == '*' && anchor == 'c' && suffix == 'D')
- lastfontid = number;
- if (multi)
- readdesc(multi, (int) number);
- }
-
- short canon(v)
- short v; {
- if (smallend)
- return(((v & 0xff) << 8) | ((v&0xff00) >> 8));
- return(v);
- }
-
- readdesc(type, bytecount)
- int type; int bytecount; {
- int points;
- char *typeface;
- char *style;
- char filename[1000];
-
- switch(type) {
-
- default:
- readhex(bytecount);
- break;
- case DOWNLOAD:
- if (fread((char *) &buffer, 1, bytecount, infp) != bytecount)
- die("fread error in readdesc\n");
-
- if ((!rast) && (builtin < 0)) {
- sprintf(filename, BINFILE, lastfontid);
- if (out)
- fclose(out);
- if ((out = fopen(filename, "a")) == NULL)
- die("can't open %s\n", filename);
-
- sprintf(filename, DESCFILE, lastfontid);
- if (txtout)
- fclose(txtout);
- if ((txtout = fopen(filename, "a")) == NULL)
- die("can't open %s\n", filename);
- }
-
- if (lastschar >= firstchar && lastschar <= lastchar) {
- if (txtout) {
- fprintf(txtout, "Character: %c\n", lastschar);
- fprintf(txtout, " orientation: %d\n",
- buffer.b_dl.dl_orientation);
- fprintf(txtout, " leftoffset: %d\n",
- canon(buffer.b_dl.dl_leftoffset));
- fprintf(txtout, " topoffset: %d\n",
- canon(buffer.b_dl.dl_topoffset));
- fprintf(txtout, " charwidth: %d\n",
- canon(buffer.b_dl.dl_charwidth));
- fprintf(txtout, " charheight: %d\n",
- canon(buffer.b_dl.dl_charheight));
- fprintf(txtout, " deltax: %d\n",
- canon(buffer.b_dl.dl_deltax));
- #ifdef PLOT
- if (plotch)
- plotchars(txtout, &buffer.b_dl);
- #endif
- }
- }
-
- if ((!rast) && out) {
- fprintf(out, "\033*c%dE", lastschar);
- fprintf(out, "\033(s%dW", bytecount);
- if (fwrite((char *) &buffer, 1, bytecount, out) != bytecount)
- die("fwrite error in readdesc\n");
- }
- if (rast)
- char_download(lastschar,lastfontid,
- (int)canon(buffer.b_dl.dl_leftoffset),
- (int)canon(buffer.b_dl.dl_topoffset),
- (int)canon(buffer.b_dl.dl_charwidth),
- (int)canon(buffer.b_dl.dl_charheight),
- (int)canon(buffer.b_dl.dl_deltax),
- (uchar*)&buffer);
- break;
-
- case FONTHEADER:
- if (txtout)
- fclose(txtout);
- if (out)
- fclose(out);
-
- if (fread((char *) &buffer, 1, bytecount, infp) != bytecount)
- die("fread error in readdesc");
-
- points = (double) canon(buffer.b_fd.fd_height) * 72 / 4 / 300 + .5;
-
- switch(buffer.b_fd.fd_typeface) {
-
- case 0: typeface = "Line Printer"; break;
- case 1: typeface = "Pica"; break;
- case 2: typeface = "Elite"; break;
- case 3: typeface = "Courier"; break;
- case 4: typeface = "Helvetica"; break;
- case 5: typeface = "Times-Roman"; break;
- case 6: typeface = "Gothic"; break;
- case 7: typeface = "Script"; break;
- case 8: typeface = "Prestige"; break;
- case 9: typeface = "Caslon"; break;
- case 10: typeface = "Orator"; break;
- default: typeface = " ";
- sprintf(typeface, "T%d", buffer.b_fd.fd_typeface);
- break;
- }
- switch(buffer.b_fd.fd_style) {
-
- case 0: style = "Upright"; break;
- case 1: style = "Italic"; break;
-
- }
-
- if ((!rast) && (builtin < 0)) {
-
- sprintf(filename, BINFILE, lastfontid);
- if ((out = fopen(filename, "w")) == NULL)
- die("can't open %s\n", filename);
-
- sprintf(filename, DESCFILE, lastfontid);
- if ((txtout = fopen(filename, "w")) == NULL)
- die("can't open %s\n", filename);
-
- fprintf(out, "\033)s%dW", bytecount);
- if (fwrite((char *) &buffer, 1, bytecount, out) != bytecount)
- die("fwrite error in readdesc\n");
-
- if (txtout) {
- fprintf(txtout, "Height: %d\n", canon(buffer.b_fd.fd_height));
- fprintf(txtout, " Points (rounded): %d\n", points);
- fprintf(txtout, " Points (floating): %.2f\n",
- (double) canon(buffer.b_fd.fd_height) * 72 / 4 / 300);
- fprintf(txtout, "Pitch: %d\n", canon(buffer.b_fd.fd_pitch));
- fprintf(txtout, " Pitch (chars/inch): %d\n",
- 4 * 300 / canon(buffer.b_fd.fd_pitch));
- if (buffer.b_fd.fd_fixedprop)
- fprintf(txtout, "Proportional width font\n");
- else fprintf(txtout, "Fixed width font\n");
- fprintf(txtout, "Stroke weight: %d\n", buffer.b_fd.fd_weight);
- fprintf(txtout, "Style: %d; (%s)\n", buffer.b_fd.fd_style,
- style);
- fprintf(txtout, "Typeface: %d; (%s)\n", buffer.b_fd.fd_typeface,
- typeface);
- fprintf(txtout, "Symset: %04x; (%d%c)\n",
- canon(buffer.b_fd.fd_symset),
- canon(buffer.b_fd.fd_symset) >> 5,
- (canon(buffer.b_fd.fd_symset) & 0x1f) + 'A' - 1);
-
- fprintf(txtout, "Type: %x\n", buffer.b_fd.fd_type);
- fprintf(txtout, "Base: %d\n", canon(buffer.b_fd.fd_base));
- fprintf(txtout, "Cellwidth: %d\n", canon(buffer.b_fd.fd_cellwidth));
- fprintf(txtout, "Cellheight: %d\n", canon(buffer.b_fd.fd_cellheight));
- fprintf(txtout, "Orientation: %d\n", buffer.b_fd.fd_orientation);
- fprintf(txtout, "Height: %d\n", canon(buffer.b_fd.fd_height));
- }
- } else { /* convert to dots moved per char */
- create_fnthdr(
- (int)buffer.b_fd.fd_orientation,
- (int)canon(buffer.b_fd.fd_symset),
- (int)buffer.b_fd.fd_fixedprop,
- (int)canon(buffer.b_fd.fd_pitch),
- (int)buffer.b_fd.fd_style,
- (int)buffer.b_fd.fd_weight,
- (int)buffer.b_fd.fd_typeface,
- ((double) canon(buffer.b_fd.fd_height) * 72 / 4 / 300));
- }
- break;
- case TRANSFER:
- if (fread((char *) &buffer, 1, bytecount, infp) != bytecount)
- die("fread error in readdesc\n");
- if (rast)
- rs_pix((uchar*)&buffer, bytecount);
- }
- }
-
- /* We've got ESC<prefix><anchor>
- * read number/suffix pairs
- */
- multisequence(prefix, anchor)
- char prefix, anchor;
- {
- int c, neg, seendot;
- double v;
-
- for (;;) {
- v = 0;
- seendot = 0;
- neg = 1;
- movetype = ABSOLUTE;
- while (isdigit(c = (*getchar_func)()) ||
- (c == '.') || (c == '-') || (c == '+')) {
-
- if (c == '+') {
- movetype = RELATIVE;
- continue;
- }
-
- if (c == '.') {
- seendot = 10;
- continue;
- }
-
- if (c == '-') {
- neg *= -1;
- movetype = RELATIVE;
- continue;
- }
-
- if (seendot) {
- v += (double) (c - '0') / seendot;
- seendot *= 10;
- }
- else
- v = v * 10 + c - '0';
-
- }
- v *= neg;
- interp(prefix, anchor, v, c);
- if (!islower(c))
- break;
- }
- movetype = ABSOLUTE;
- }
-
- readescape() {
- int c, v;
-
- c = (*getchar_func)();
- switch(c) {
- case '9':
- dbprintf(("Clear Margins\n"));
- if (rast)
- lr_default();
- return;
- case '=':
- dbprintf(("Half linefeed\n"));
- if (rast)
- half_linefeed();
- return;
- case 'E':
- dbprintf(("Reset\n"));
- if (rast_org) {
- if (pbmpage)
- pbmeject(TRUE);
- else pbmnewpage(TRUE);
- clearfonts(TEMPORARY);
- rs_del_macros(TEMPORARY,0);
- getchar_func = getc_only;
- }
- return;
- case 'z':
- dbprintf(("Self test\n"));
- return;
- case 'Y':
- dbprintf(("Display functions on\n"));
- return;
- case 'Z':
- dbprintf(("Display functions off\n"));
- return;
- case ')':
- c = (*getchar_func)();
- if (isdigit(c)) {
- v = 0;
- while(isdigit(c)) {
- v = v * 10 + c - '0';
- c = (*getchar_func)();
- }
- switch(c) {
- case 'X':
- dbprintf(("Secondary font %d\n", v));
- if (rast)
- rs_font(v,SECONDARY);
- break;
- case '@':
- dbprintf(("Secondary font value %d\n", v));
- break;
- default:
- dbprintf(("HUH ESC)%d%c\n", v, c));
- }
- return;
- }
- multisequence(')', c);
- return;
- case '(':
- c = (*getchar_func)();
- if (isdigit(c) || (c == 'X' || c == '@')) {
- v = 0;
- while(isdigit(c)) {
- v = v * 10 + c - '0';
- c = (*getchar_func)();
- }
- switch(c) {
- case 'X':
- dbprintf(("Primary font %d\n", v));
- if (rast)
- rs_font(v,PRIMARY);
- if (genps)
- ps_font(v, pts[v&0xf]);
- break;
- case '@':
- dbprintf(("Primary font value %d\n", v));
- break;
- default:
- dbprintf(("Symbol set: %d%c\n", v, c));
- if (rast)
- rs_symset(v*32+c-64);
- ps_symset = c;
- }
- return;
- }
- multisequence('(', c);
- return;
- case '&':
- c = (*getchar_func)();
- multisequence('&', c);
- return;
- case '*':
- c = (*getchar_func)();
- multisequence('*', c);
- return;
- default:
- dbprintf(("Huh? %02x\n", c));
- return;
- }
- }
-
- main(argc, argv)
- int argc; char **argv; {
- int c;
-
- int resdone = 0;
-
- extern char *optarg;
- extern int optind;
-
- #if !defined(BIGEND) && !defined(SMALLEND)
- union t ta;
- ta.a[0] = 0x01;
- ta.a[1] = 0x02;
- smallend = ((ta.b&0xff) == 0x01);
- #endif
-
- errno = 0;
- if ((PGM = strrchr(argv[0], '/')) != NULL)
- ++PGM;
- else PGM = argv[0];
-
- #ifdef FAXPAK
- if (read_defaults(&fc) || read_config(&fc))
- exit(1);
- #endif
-
- getchar_func = getc_only;
- infp = stdin;
-
- pbmname[0] = '\0';
- while((c = getopt(argc, argv, "r:d:pvcV")) != EOF)
- switch(c) {
- #ifdef PS
- case 'p':
- genps++;
- break;
- #endif
- case 'v':
- verbose++;
- break;
- case 'V':
- printf("%s\n", VERSION);
- exit(0);
- case 'c':
- plotch++;
- break;
- case 'd': {
- double x, y;
-
- switch (sscanf(optarg, "%f,%f", &x, &y)) {
- case 0:
- fprintf(stderr, "%s: bad -d option %s\n", PGM, optarg);
- exit(1);
- case 1:
- y = x;
- case 2:
- rs_rastsize(x, x);
- break;
- }
-
- resdone++;
-
- break;
- }
- case 'r':
- rast_org = ++rast;
- strcpy(pbmname, optarg);
- break;
- case '?':
- fprintf(stderr, "usage: hpinterp [-dx[,y]][-p][-v][-c][-rpbm]< file\n");
- exit(1);
- }
-
- if (!resdone) {
-
- if (!strcmp(PGM, "hp2hifax"))
- rs_rastsize( 204.15, 195.58);
- else if (!strcmp(PGM, "hp2lofax"))
- rs_rastsize( 204.15, 97.79);
- else if (!strcmp(PGM, "hp2sun"))
- rs_rastsize( 84.0, 84.0);
- else if (!strcmp(PGM, "hp2e24"))
- rs_rastsize( 180.0, 180.0);
- else
- rs_rastsize( 300.0, 300.0); /* be prepared just in case */
- }
-
- if (rast) {
- if (pbmname[0] == '\0')
- die("need an output file name\n");
- make_bitmap(XSIZE,YSIZE);
- }
-
- if (genps)
- ps_init();
- hptoany(); /* to allow recursion */
-
- if (out)
- fclose(out);
- if (txtout)
- fclose(txtout);
- if (rast && dotted)
- pbmeject(FALSE);
- if (genps)
- ps_endemit();
- exit(0);
- /*NOTREACHED*/
- }
-
- hptoany() {
- int c;
-
- while ((c = (*getchar_func)()) != EOF) {
- if (c == ESCAPE)
- readescape();
- else {
-
- if (isprint(c)) {
- dbprintf(("Char: %c\n", c));
- } else {
- dbprintf(("Char: 0x%02x\n", c));
- }
-
- if (rast) {
- if (c == '\n')
- movetype = RELATIVE;
-
- if (c == '\f')
- pbmeject(TRUE);
- else prt_hpchr(c);
- movetype = ABSOLUTE;
- }
- if (genps)
- ps_emitchar(c);
- }
- }
- }
-
- movex(num)
- double num; {
- curX = num;
- if (rast)
- rs_X(curX);
- if (genps)
- ps_endemit();
- }
-
- movey(num)
- double num; {
- curY = num;
- if (rast)
- rs_Y(curY,FALSE);
- if (genps)
- ps_endemit();
- }
-
- movedx(num)
- double num; {
- curX = num * 300.0 / 720.0;
- if (rast)
- rs_X(curX);
- if (genps)
- ps_endemit();
- }
-
- movedy(num)
- double num; {
- curY = num * 300.0 / 720.0;
- if (rast)
- rs_Y(curY,TRUE);
- if (genps)
- ps_endemit();
- }
-
- papinctrl(num)
- double num; {
- if (num == 0) {
- if (rast)
- pbmeject(TRUE);
- if (genps) {
- ps_endemit();
- printf("showpage\n");
- }
- }
- }
-
- spset(num)
- double num; {
- ps_spacing = num;
- characteristic = 1;
- if (rast)
- rs_spacing((int)num);
- if (genps)
- ps_endemit();
- }
-
- psset(num)
- double num; {
- characteristic = 1;
- ps_pointsize = num;
- if (rast)
- rs_points(num);
- if (genps)
- ps_endemit();
- }
-
- styset(num)
- double num; {
- characteristic = 1;
- ps_style = num;
- if (rast)
- rs_style((int)num);
- if (genps)
- ps_endemit();
- }
-
- strset(num)
- double num;
- {
- characteristic = 1;
- ps_stroke = num;
- if (rast)
- rs_stroke((int)num);
- if (genps)
- ps_endemit();
- }
-
- tfset(num)
- double num; {
- characteristic = 1;
- ps_tface = num;
- if (rast)
- rs_typeface((int)num);
- if (genps)
- ps_endemit();
- }
-
- macro_id(n)
- double n; {
- if (rast)
- rs_macro_id(n);
- }
-
- macro_ctl(n)
- double n; {
- int len;
-
- if (!rast_org)
- return;
-
- switch((int)n) {
- case 0: rast = 0;
- getchar_func = getc_copy;
- mac_ctr = 0;
- rs_mac_startdef();
- break;
- case 1: rast = rast_org;
- getchar_func = getc_only;
- if (mac_ctr)
- mac_download(mac_ctr, McBuffer);
- rs_mac_enddef();
- break;
- case 2: CurMc = CurMc_Ptr = rs_get_macro(&len);
- if (len > 0)
- {
- getchar_func = mgetc;
- CurMc_End = CurMc + len;
- }
- break;
- case 3: CurMc = CurMc_Ptr = rs_get_macro(&len);
- if (len > 0) {
- getchar_func = mgetc;
- CurMc_End = CurMc + len;
- rs_call_macro(SAVE);
- need_mac_end_call = TRUE;
- }
- break;
- case 4: have_auto_macro = rs_auto_enable(TRUE); break;
- case 5: have_auto_macro = rs_auto_enable(FALSE);break;
- case 6: rs_del_macros(TEMPORARY,PERMANENT); break;
- case 7: rs_del_macros(TEMPORARY,FALSE); break;
- case 8: rs_del_macro(); break;
- case 9: rs_makemtype(TEMPORARY); break;
- case 10:rs_makemtype(PERMANENT); break;
- }
- }
-
- pbmeject(newpage)
- int newpage; {
- int olddot;
-
- olddot = dotted;
- if (dotted) {
- if (!pbmpage)
- pbmnewpage(TRUE);
- end_bitmap(pbmtname);
- }
- if (newpage)
- pbmnewpage(olddot);
- }
-
- pbmnewpage(inc)
- int inc; {
- int (*old_func)();
-
- sprintf(pbmtname,"%s.%d",pbmname,pbmpage);
- pbmpage += inc;
- if (have_auto_macro > -1) {
- old_func = getchar_func;
- getchar_func = auto_getc;
- rs_auto();
- getchar_func = old_func;
- }
- }
-
- loadbuiltin(fontname)
- char *fontname; {
- char fname[256];
- static FILE *fload, *old_infp;
- static int (*old_func)();
-
- #ifdef FAXPAK
- sprintf(fname, "%s/hplib/%s", fc.faxlib, fontname);
- #else
- sprintf(fname, BUILTINDIR, LIBDIR, fontname);
- #endif
- if ((fload = fopen(fname, "r")) == NULL)
- die("have some difficulty opening %s\n",fname);
- old_infp = infp;
- old_func = getchar_func;
- getchar_func = getc_only;
- infp = fload;
- hptoany(); /* load the font */
- fclose(fload);
- infp = old_infp;
- getchar_func = old_func;
- }
-
- #ifdef PLOT
- plotchars(f, dl)
- struct download *dl;
- FILE *f; {
- short x, y, bx, by, bytes, byteindex, bitindex, bit;
- uchar *data;
-
- data = (uchar *)dl;
- data += sizeof(struct download);
- bytes = (canon(dl->dl_charwidth) + 7) / 8;
- for (y = 0; y < canon(dl->dl_charheight); y++) {
- fprintf(f, " ");
- for (x = 0; x < (canon(dl->dl_charwidth) + canon(dl->dl_leftoffset));
- x++) {
- bx = x - canon(dl->dl_leftoffset);
- by = y;
- if (bx >= 0) {
- byteindex = bytes * by + bx / 8;
- bitindex = (7 - (bx % 8));
- if (data[byteindex] & (1 << bitindex))
- bit = 'X';
- else
- bit = ' ';
- } else
- bit = ' ';
- if (x == 0 && y == canon(dl->dl_topoffset))
- bit = '+';
- if (bit == ' ' && y == canon(dl->dl_topoffset))
- bit = '=';
- fputc(bit, f);
- }
- fputc('\n',f);
- }
- }
- #endif
-
- /* Postscript driver */
-
- ps_font(v, p)
- int v, p; {
- ps_endemit();
- characteristic = 0;
- printf("/f%d findfont %d scalefont setfont\n", v, p);
- }
-
- ps_init() {
- printf("/M { moveto } def\n");
- printf("/S { show } def\n");
- }
-
- int emitting = 0;
-
- #define TMS "Times-Roman", "Times-Italic", "Times-Bold", "Times-BoldItalic"
- #define COUR "Courier", "Courier-Oblique", "Courier-Bold",\
- "Courier-BoldOblique"
- #define HELV "Helvetica", "Helvetica-Oblique", "Helvetica-Bold",\
- "Helvetica-BoldOblique"
-
- #define LAST 7
-
- char *fonts[LAST][4] = {{COUR}, {COUR}, {COUR}, {COUR},
- {HELV}, {TMS}, {COUR}};
-
- selchar() {
- int idx = 0;
- char *p;
-
- #ifdef NEVER
- printf("ps_pointsize: %d\n", ps_pointsize);
- printf("ps_style: %d\n", ps_style);
- printf("ps_stroke: %d\n", ps_stroke);
- printf("ps_symset: %d\n", ps_symset);
- printf("ps_tface: %d\n", ps_tface);
- printf("ps_spacing: %d\n", ps_spacing);
- #endif
- if (ps_tface == 4101) /* CG Roman on LJ III */
- ps_tface = 5;
- if (ps_tface == 4148) /* CG Univers (Helvetica like) Roman on LJ III */
- ps_tface = 4;
- if (ps_tface >= LAST || ps_tface < 0)
- ps_tface = 3;
- idx = 0;
- if (ps_stroke > 0)
- idx = 2;
- if (ps_style != 0)
- idx++;
- if (ps_symset == 'M')
- p = "Symbol";
- else p = fonts[ps_tface][idx];
- printf("/%s findfont %d scalefont setfont\n", p, ps_pointsize);
- characteristic = 0;
- }
-
- ps_emitchar(c)
- int c; {
- if (!genps)
- return;
-
- if (characteristic)
- selchar();
-
- if (!emitting)
- printf("%g %g M(", curX * 72 / 300, (72 * 11) - (curY * 72 / 300));
-
- emitting = 1;
-
- switch(c) {
- case '(':
- case ')':
- case '\\':
- printf("\\%c", c);
- break;
- default:
- if (c > ' ' && c < 0x7e)
- printf("%c", c);
- else printf("\\%03o", c&0xff);
- break;
- }
- }
-
- ps_endemit() {
- if (emitting)
- printf(")S\n");
- emitting = 0;
- }
-
- #ifdef SELDOM /* not used */
- printhex(buf, n)
- char *buf; int n; {
- int i;
-
- dbprintf(("SEQ:"));
- for (i = 0; i < n; i++) {
- if (isprint(buf[i]))
- putchar(buf[i]);
- else {
- dbprintf(("\\%02x", buf[i]));
- }
- }
- dbprintf(("\n"));
- }
- #endif
-
-