home *** CD-ROM | disk | FTP | other *** search
- /* Copyright 1985, 1986, 1987, 1988 Chris Lewis
- All Rights Reserved
-
- Permission to copy and further distribute is freely given provided
- this copyright notice remains intact and that this software is not
- sold for profit.
-
- Project: Generic Troff drivers
- Module: lj.c
- Author: Chris Lewis
- Specs: LaserJet driver, hacked from ps.c and lcat.c
- (Gosh, this is a lot simpler than lcat's stuff.
- Thank PostScript for getting my brain in order.)
-
- Font downloading is supported, but untested as
- yet.
- Font downloading is not supported yet, however
- all of the font selection stuff is. Therefore,
- this stuff will actually work if all of the
- fonts have been previously downloaded...
- However, the LJ considers different point sizes
- to be different fonts, so don't expect much....
-
- Macro "DOWNLOAD" is used to denote places and
- some coding for font downloading.
-
- Without font downloading, this is LJ compatible.
- Font downloading will require a LJ+, LJ500+ or
- LJ II.
-
- This code has not been tested - however, it is
- a derivitive of the original lcat software, so
- it may actually do things right. Chances are,
- any errors are in some of the escape sequence
- details. Eg: the stroke-weight parameter may
- need tweaking.
-
- Only standardFont bears any resemblance to what it
- should. symbolFont is still PostScript.
-
- The tables have been moved from this file to
- ljtables.c
- */
-
- #include "defs.h"
-
- #if defined(LJ) || defined(LK)
- #include "lj.h"
-
- #define MAXFONT 50
-
- #ifndef SVR3
- #ifndef lint
- static char SCCSid[] = "@(#)lj.c: 1.7 Copyright 89/06/14 17:40:23 Chris Lewis";
- #endif
- #else
- #ident "@(#)lj.c: 1.7 Copyright 89/06/14 17:40:23 Chris Lewis" /*(SVR3)*/
- #endif
-
- #define USED 1
- #define BUILTIN 2
- struct ljFts {
- char *troffName;
- char *fontSeq;
- char *ascName;
- int flags;
- } ljFts[MAXFONT+1];
-
- struct ljFts *t2ljf[8];
-
- /* Used for characters not in Roman8 Character set */
- #define NOPE "\0374"
- ljPage() {
- printf("\033&l0H");
- pagePending = 1;
- }
-
- static
- doPageStart(e) {
- currentPage++;
- pagePending = 0;
- }
-
- static int lastFont = (-1), lastPoints = (-1);
- static
- putoct(s)
- char *s; {
- int d;
- if (strlen(s) < 3) {
- fprintf(stderr, "%s: octal sequence in fonts.l[kj] bad\n", progname);
- exit(1);
- }
- d = (*s - '0') * 64 + (*(s+1) - '0') * 8 + *(s+2) - '0';
- putchar(d);
- }
-
- ljSetFont(font, points)
- int font, points; {
-
- if (lastPoints != points || font != lastFont) {
- register char *p;
- #ifdef DOWNLOAD
- if (!(ljFts[font].flags&(USED|BUILTIN))) {
- char buf[512];
- FILE *fontfile;
- int count;
- sprintf(buf, "%s/%s.%s.%d", LIBDIR, be->bename,
- ljFts[font].troffName, points);
- if ((fontfile = fopen(buf, "r")) == NULL) {
- fprintf(stderr, "%s: Cannot open fontfile %s\n", progname,
- buf);
- } else {
- while(0 > (count = fread(buf, sizeof(char), 512, fontfile)))
- fwrite(buf, sizeof(char), count, stdout);
- fclose(fontfile);
- }
- }
- #endif
- ljFts[font].flags |= USED;
- for (p = ljFts[font].fontSeq; *p; p++) {
- if (*p == '\\') {
- putoct(p+1);
- p+=3;
- } else
- putchar(*p);
- }
- printf("\033(s%dV", points);
- lastPoints = points;
- lastFont = font;
- }
-
- }
-
- ljChar(x, y, font, points, troffChar)
- int x, y, font, points, troffChar; {
- static double lasty = (-1);
- register double nx = TROFF2LJX(x), ny = TROFF2LJY(y);
- register struct troff2befont *rp;
- register char *sequence = "a";
- double xad, yad;
- if (pagePending) {
- lasty = lastFont = lastPoints = (-1);
- doPageStart();
- }
-
- DEBUGPRINTF("x,y=%d,%d; font=%d, points=%d, tc=%d\n",
- x, y, font, points, troffChar);
-
- if (font == 3) {
- rp = &be->besymfont[troffChar];
- } else {
- rp = &be->bestdfont[troffChar];
- }
-
- switch(rp->t2b_font) {
- /* Only fonts with "U" are subject to font translation */
- case U:
- if (font == 3)
- font = 0; /* Special chars are Courier */
- else {
- DEBUGPRINTF("ljSetChar %d->%s (%s)\n", font,
- t2ljf[font]->troffName,
- t2ljf[font]->ascName);
- font = t2ljf[font] - ljFts;
- }
- break;
- case S:
- font = 3;
- break;
- case D:
- break;
- default:
- /* Typically used when the main fonts don't have the
- character desired. Eg: right-hand is in the
- ZapfDingbats font */
- font = rp->t2b_font;
- break;
- }
-
- sequence = rp->t2b_charseq;
-
- if (!sequence) {
- fprintf(stderr, "No coding for %d\n", troffChar);
- return;
- }
-
- /* We're committed now */
-
- points *= rp->t2b_scale;
- xad = points * rp->t2b_xc;
- yad = points * rp->t2b_yc;
- ljSetFont(font, points);
-
- /* We won't output fractions */
- #define XYS "\033&a%.0fh%.0fV%s"
- #define XS "\033&a%.0fH%s"
-
- if (lasty != ny) {
- printf(XYS, nx+xad, ny+yad, sequence);
- lasty = ny;
- } else
- printf(XS, nx+xad, sequence);
- }
-
- static
- loadfontdefs(f)
- FILE *f; {
- struct ljFts *p = ljFts;
- extern char *malloc();
- int flags;
- char rbuf[512], nbuf[512], ljbuf[512], seqbuf[512];
- while(fgets(rbuf, sizeof(rbuf), f)) {
- if (rbuf[0] == '#')
- continue;
- switch(sscanf(rbuf, "%s%s%s%d", nbuf, ljbuf, seqbuf, &flags)) {
- default:
- break;
- case 4:
- if (nbuf[0] == '#')
- break;
- if (p - ljFts >= MAXFONT) {
- fprintf(stderr, "Too many font definitions in %s\n",
- be->bename);
- exit(1);
- }
- p->troffName = malloc(strlen(nbuf) + 1);
- strcpy(p->troffName, nbuf);
- p->ascName = malloc(strlen(ljbuf) + 1);
- strcpy(p->ascName, ljbuf);
- p->fontSeq = malloc(strlen(seqbuf) + 1);
- strcpy(p->fontSeq, seqbuf);
- p->flags = flags;
- p++;
- }
- }
- #ifdef DEBUG
- for (p = ljFts; p->troffName; p++)
- DEBUGPRINTF("%s -> %s, seq: %s\n", p->troffName, p->ascName, p->fontSeq);
- #endif
- }
-
- ljProlog() {
- extern char *getlogin(), *ctime();
- char *buf2[15];
- FILE *library;
- int c;
- long curtime;
-
- currentPage = 0;
- pagePending = 1;
-
- for (c = 0; c < 8; c++)
- t2ljf[c] = &ljFts[c];
-
- sprintf(buf2, "%s.%s", LJFONTS, be->bename);
-
- if ((library = fopen(buf2, "r")) == NULL) {
- char buffer[512];
- sprintf(buffer, "%s/%s", LIBDIR, buf2);
- if ((library = fopen(buffer, "r")) == NULL) {
- fprintf(stderr, "Cannot open %s font definitions %s\n",
- LJFONTS, buffer);
- exit(1);
- }
- }
-
- loadfontdefs(library);
- fclose(library);
-
- sprintf(buf2, "%s.%s", LJLIB, be->bename);
-
- if ((library = fopen(buf2, "r")) == NULL) {
- char buffer[512];
- sprintf(buffer, "%s/%s", LIBDIR, buf2);
- if ((library = fopen(buffer, "r")) == NULL) {
- fprintf(stderr, "Cannot open %s\n", buffer);
- exit(1);
- }
- }
-
- printf("\033E\033&k2G"); /* reset printer, set CR=CR,LF=CRLF,FF=CRFF */
- printf("\033&l6d66p0o0e66f0L");/* letter size, portrait, no perf skip */
- printf("\0339"); /* reset side margins */
- printf("\033&a0r0C"); /* move cursor to 0,0 */
-
- ljXlate(library);
- fclose(library);
- }
-
- ljEpilog() {
- }
-
- ljFontSel(from, to)
- char from, *to; {
- #ifdef DEBUG
- register int i;
- register struct ljFts *p;
- #endif
- DEBUGPRINTF("ljFontSel: %c -> %s\n", from, to);
- if (from < '1' || from > '8') {
- fprintf(stderr, "Bad arguments to ljFontSel: %c %s\n", from, to);
- return;
- }
-
- for (p = ljFts; p->troffName; p++)
- if (strcmp(p->troffName, to) == 0) {
- t2ljf[from - '1'] = p;
- break;
- }
- if (!p->troffName) {
- fprintf(stderr, "Could not translate font %c (%s)\n", from, to);
- }
- #ifdef DEBUG
- for (i = 0; i < 8; i++)
- DEBUGPRINTF("Font %d->%s\n", i+1, t2ljf[i]->ascName);
- #endif
- }
-
- /* Copy the library file to the standard output, stripping
- %line\n
- %%%<something> is a metadirective
- and converting \nnn and \xnn as you go.
- Strip out line termination.
- */
-
- ljXlate(library)
- FILE *library; {
- char buf[4];
- int c, i;
- c = getc(library);
- while(!feof(library)) {
-
- nextchar:
-
- switch(c) {
- case '%':
- /* strip from percent sign to end of line */
- /* If line is %%%<something> pass onto interp */
- if (((c = getc(library)) == '%') &&
- ((c = getc(library)) == '%')) {
- char buf2[4];
- sprintf(buf2, ".%s", be->bename);
- fgets(buf, strlen(buf), library);
- interp(buf, ljXlate, buf2);
- break;
- }
- while ((c = getc(library)) != EOF && c != '\n');
- break;
- case '\n': /* throw away real newlines. */
- break;
- case '\\':
- c = getc(library);
- if (c == 'x' || c == 'X') {
- i = 0;
- while(1) {
- c = getc(library);
-
- if (c == EOF || !((c >= '0' && c <= '9') ||
- (c >= 'A' && c <= 'F') ||
- (c >= 'a' && c <= 'f')))
- goto nextchar;
-
- buf[i++] = c;
- if (i == 2) {
- buf[i] = '\0';
- sscanf(buf, "%x", &i);
- putchar(i);
- i = 0;
- }
- }
- } else {
- buf[0] = c;
- i = 1;
- while(1) {
- c = getc(library);
- if (c == EOF || c < '0' || c > '7')
- goto nextchar;
- buf[i++] = c;
- if (i == 3) {
- buf[i] = '\0';
- sscanf(buf, "%o", &i);
- putchar(i);
- i = 0;
- }
- }
- }
- /* NOTREACHED */
-
- case ' ': case '\t':
- break;
-
- case EOF:
- fprintf(stderr, "%s: Unexpected eof on ljlib\n", progname);
- break;
-
- default:
- putchar(c);
- }
- c = getc(library);
- }
- }
- #endif
-