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: dt.c
- Author: Chris Lewis
- Specs: Ditroff driver
- */
-
- #include "defs.h"
-
- #ifdef DT
- #include "dt.h"
-
- int currentPage = 0;
-
- #ifndef SVR3
- #ifndef lint
- static char SCCSid[] = "@(#)dt.c: 1.5 Copyright 89/07/04 16:59:46 Chris Lewis";
- #endif
- #else
- #ident "@(#)dt.c: 1.5 Copyright 89/07/04 16:59:46 Chris Lewis" /*(SVR3)*/
- #endif
-
- #define MAXFONT 50
-
- #define USED 01
-
- struct dtFts {
- char *troffName;
- char *ascName;
- int flags;
- } dtFts[MAXFONT+1];
-
- struct dtFts *t2dtf[8];
-
- struct troff2befont dtStdFont[108] = {
-
- /* +-------------------------------- Troff character number
- |
- | +--------------------------- U: standard fonts
- | | S: symbol font
- | | D: draw macro
- | | n: new font
- | |
- | | +------------------------ X-shift (scaled by point)
- | | | Note: positive is right.
- | | |
- | | | +--------------------- Y-shift (scaled by point)
- | | | | Note: positive is up.
- | | | |
- | | | | +------------------ Point scale factor
- | | | | |
- | | | | | +-------------- Sequence
- | | | | | |
- | | | | | | Printable sequence title
- | | | | | | |
- | | | | | | |
- v v v v v v v */
- /* 1*/ {U, 0, 0, 1, "h", "h"},
- /* 2*/ {U, 0, 0, 1, "t", "t"},
- /* 3*/ {U, 0, 0, 1, "n", "n"},
- /* 4*/ {U, 0, 0, 1, "m", "m"},
- /* 5*/ {U, 0, 0, 1, "l", "l"},
- /* 6*/ {U, 0, 0, 1, "i", "i"},
- /* 7*/ {U, 0, 0, 1, "z", "z"},
- /* 8*/ {U, 0, 0, 1, "s", "s"},
- /* 9*/ {U, 0, 0, 1, "d", "d"},
- /* 10*/ {U, 0, 0, 1, "b", "b"},
- /* 11*/ {U, 0, 0, 1, "x", "x"},
- /* 12*/ {U, 0, 0, 1, "f", "f"},
- /* 13*/ {U, 0, 0, 1, "j", "j"},
- /* 14*/ {U, 0, 0, 1, "u", "u"},
- /* 15*/ {U, 0, 0, 1, "k", "k"},
- /* 16*/ {U, 0, 0, 1, NOCODE, "unassigned"},
- /* 17*/ {U, 0, 0, 1, "p", "p"},
- /* 18*/ {U, 0, 0, 1, "em", "3/4 em"},
- /* 19*/ {U, 0, 0, 1, ";", ";"},
- /* 20*/ {U, 0, 0, 1, NOCODE, "unassigned"},
- /* 21*/ {U, 0, 0, 1, "a", "a"},
- /* 22*/ {U, 0, 0, 1, "ru", "horizontal rule"},
- /* 23*/ {U, 0, 0, 1, "c", "c"},
- /* 24*/ {U, 0, 0, 1, "`", "` open"},
- /* 25*/ {U, 0, 0, 1, "e", "e"},
- /* 26*/ {U, 0, 0, 1, "'", "' close"},
- /* 27*/ {U, 0, 0, 1, "o", "o"},
- /* 28*/ {U, 0, 0, 1, "14", "1/4"},
- /* 29*/ {U, 0, 0, 1, "r", "r"},
- /* 30*/ {U, 0, 0, 1, "12", "1/2"},
- /* 31*/ {U, 0, 0, 1, "v", "v"},
- /* 32*/ {U, 0, 0, 1, "hy", "- hyphen"},
- /* 33*/ {U, 0, 0, 1, "w", "w"},
- /* 34*/ {U, 0, 0, 1, "q", "q"},
- /* 35*/ {U, 0, 0, 1, "/", "/"},
- /* 36*/ {U, 0, 0, 1, ".", "."},
- /* 37*/ {U, 0, 0, 1, "g", "g"},
- /* 38*/ {U, 0, 0, 1, "34", "3/4"},
- /* 39*/ {U, 0, 0, 1, ",", ","},
- /* 40*/ {U, 0, 0, 1, "&", "&"},
- /* 41*/ {U, 0, 0, 1, "y", "y"},
- /* 42*/ {U, 0, 0, 1, NOCODE, "unassigned"},
- /* 43*/ {U, 0, 0, 1, "%", "%"},
- /* 44*/ {U, 0, 0, 1, NOCODE, "unassigned"},
- /* 45*/ {U, 0, 0, 1, "Q", "Q"},
- /* 46*/ {U, 0, 0, 1, "T", "T"},
- /* 47*/ {U, 0, 0, 1, "O", "O"},
- /* 48*/ {U, 0, 0, 1, "H", "H"},
- /* 49*/ {U, 0, 0, 1, "N", "N"},
- /* 50*/ {U, 0, 0, 1, "M", "M"},
- /* 51*/ {U, 0, 0, 1, "L", "L"},
- /* 52*/ {U, 0, 0, 1, "R", "R"},
- /* 53*/ {U, 0, 0, 1, "G", "G"},
- /* 54*/ {U, 0, 0, 1, "I", "I"},
- /* 55*/ {U, 0, 0, 1, "P", "P"},
- /* 56*/ {U, 0, 0, 1, "C", "C"},
- /* 57*/ {U, 0, 0, 1, "V", "V"},
- /* 58*/ {U, 0, 0, 1, "E", "E"},
- /* 59*/ {U, 0, 0, 1, "Z", "Z"},
- /* 60*/ {U, 0, 0, 1, "D", "D"},
- /* 61*/ {U, 0, 0, 1, "B", "B"},
- /* 62*/ {U, 0, 0, 1, "S", "S"},
- /* 63*/ {U, 0, 0, 1, "Y", "Y"},
- /*from here on are actually code 1-45, upper half of font */
- /* 64*/ {U, 0, 0, 1, "F", "F"},
- /* 65*/ {U, 0, 0, 1, "X", "X"},
- /* 66*/ {U, 0, 0, 1, "A", "A"},
- /* 67*/ {U, 0, 0, 1, "W", "W"},
- /* 68*/ {U, 0, 0, 1, "J", "J"},
- /* 69*/ {U, 0, 0, 1, "U", "U"},
- /* 70*/ {U, 0, 0, 1, "K", "K"},
- /* 71*/ {U, 0, 0, 1, "0", "0"},
- /* 72*/ {U, 0, 0, 1, "1", "1"},
- /* 73*/ {U, 0, 0, 1, "2", "2"},
- /* 74*/ {U, 0, 0, 1, "3", "3"},
- /* 75*/ {U, 0, 0, 1, "4", "4"},
- /* 76*/ {U, 0, 0, 1, "5", "5"},
- /* 77*/ {U, 0, 0, 1, "6", "6"},
- /* 78*/ {U, 0, 0, 1, "7", "7"},
- /* 79*/ {U, 0, 0, 1, "8", "8"},
- /* 80*/ {U, 0, 0, 1, "9", "9"},
- /* 81*/ {U, 0, 0, 1, "*", "*"},
- /* 82*/ {U, 0, 0, 1, "-", "minus"},
- /* 83*/ {U, 0, 0, 1, "fi", "fi"},
- /* 84*/ {U, 0, 0, 1, "fl", "fl"},
- /* 85*/ {U, 0, 0, 1, "ff", "ff"},
- /* 86*/ {U, 0, 0, 1, "ct", "cent sign"},
- /* 87*/ {U, 0, 0, 1, "Fl", "ffl"},
- /* 88*/ {U, 0, 0, 1, "Fi", "ffi"},
- /* 89*/ {U, 0, 0, 1, "(", "("},
- /* 90*/ {U, 0, 0, 1, ")", ")"},
- /* 91*/ {U, 0, 0, 1, "[", "["},
- /* 92*/ {U, 0, 0, 1, "]", "]"},
- /* 93*/ {U, 0, 0, 1, "de", "degree"},
- /* 94*/ {U, 0, 0, 1, "dg", "dagger"},
- /* 95*/ {U, 0, 0, 1, "=", "="},
- /* 96*/ {U, 0, 0, 1, "rg", "registered"},
- /* 97*/ {U, 0, 0, 1, ":", ":"},
- /* 98*/ {U, 0, 0, 1, "+", "+"},
- /* 99*/ {U, 0, 0, 1, NOCODE, "unassigned"},
- /*100*/ {U, 0, 0, 1, "!", "!"},
- /*101*/ {U, 0, 0, 1, "bu", "bullet"},
- /*102*/ {U, 0, 0, 1, "?", "?"},
- /*103*/ {U, 0, 0, 1, "fm", "foot mark (minute)"},
- /*104*/ {U, 0, 0, 1, "|", "|"},
- /*105*/ {U, 0, 0, 1, NOCODE, "unassigned"},
- /*106*/ {U, 0, 0, 1, "co", "copyright"},
- /*107*/ {U, 0, 0, 1, "sq", "square"},
- /*108*/ {U, 0, 0, 1, "$", "$"}
- };
-
- struct troff2befont dtSymFont[] = {
- /* +-------------------------------- Troff character number
- |
- | +--------------------------- U: standard fonts
- | | S: symbol font
- | | D: draw macro
- | |
- | | +------------------------ X-shift (scaled by point)
- | | | Note: positive is right.
- | | |
- | | | +--------------------- Y-shift (scaled by point)
- | | | | Note: positive is up.
- | | | |
- | | | | +------------------ Point scale factor
- | | | | |
- | | | | | +-------------- Sequence
- | | | | | |
- | | | | | | Printable sequence title
- | | | | | | |
- | | | | | | |
- v v v v v v v */
- /* 1*/ {S, 0, 0, 1, "*q", "psi"},
- /* 2*/ {S, 0, 0, 1, "*h", "theta"},
- /* 3*/ {S, 0, 0, 1, "*n", "nu"},
- /* 4*/ {S, 0, 0, 1, "*m", "mu"},
- /* 5*/ {S, 0, 0, 1, "*l", "lambda"},
- /* 6*/ {S, 0, 0, 1, "*i", "iota"},
- /* 7*/ {S, 0, 0, 1, "*z", "zeta"},
- /* 8*/ {S, 0, 0, 1, "*s", "sigma"},
- /* 9*/ {S, 0, 0, 1, "*d", "delta"},
- /* 10*/ {S, 0, 0, 1, "*b", "beta"},
- /* 11*/ {S, 0, 0, 1, "*c", "xi"},
- /* 12*/ {S, 0, 0, 1, "*y", "eta"},
- /* 13*/ {S, 0, 0, 1, "*f", "phi"},
- /* 14*/ {S, 0, 0, 1, "*u", "upsilon"},
- /* 15*/ {S, 0, 0, 1, "*k", "kappa"},
- /* 16*/ {S, 0, 0, 1, NOCODE, "unassigned"},
- /* 17*/ {S, 0, 0, 1, "*p", "pi"},
- /* 18*/ {S, 0, 0, 1, "@", "@"},
- /* 19*/ {S, 0, 0, 1, "da", "down arrow"},
- /* 20*/ {S, 0, 0, 1, NOCODE, "unassigned"},
- /* 21*/ {S, 0, 0, 1, "*a", "alpha"},
- /* 22*/ {S, 0, 0, 1, "or", "or (was star)"},
- /* 23*/ {S, 0, 0, 1, "*x", "chi"},
- /* 24*/ {U, 0, 0, 1, "\"", "double quote"},
- /* 25*/ {S, 0, 0, 1, "*e", "epsilon"},
- /* 26*/ {S, 0, 0, 1, "eq", "equation equal"},
- /* 27*/ {S, 0, 0, 1, "*o", "omicron"},
- /* 28*/ {S, 0, 0, 1, "<-", "left arrow"},
- /* 29*/ {S, 0, 0, 1, "*r", "rho"},
- /* 30*/ {S, 0, 0, 1, "ua", "up arrow"},
- /* 31*/ {S, 0, 0, 1, "*t", "tau"},
- /* 32*/ {S, 0, 0, 1, "ul", "underline"},
- /* 33*/ {U, 0, 0, 1, "\\", "back slash"},
- /* 34*/ {S, 0, 0, 1, "*Q", "Psi"},
- /* 35*/ {S, 0, 0, 1, "?", "bell system sign"},
- /* 36*/ {S, 0, 0, 1, "if", "infinity"},
- /* 37*/ {S, 0, 0, 1, "*g", "gamma"},
- /* 38*/ {S, 0, 0, 1, "ip", "improper superset"},
- /* 39*/ {S, 0, 0, 1, "pt", "proportional to"},
- /* 40*/ {S, 0, 0, 1, "rh", "right hand"},
- /* 41*/ {S, 0, 0, 1, "*w", "omega"},
- /* 42*/ {S, 0, 0, 1, NOCODE, "unassigned"},
- /* 43*/ {S, 0, 0, 1, "gr", "gradient"},
- /* 44*/ {S, 0, 0, 1, NOCODE, "unassigned"},
- /* 45*/ {S, 0, 0, 1, "*F", "Phi"},
- /* 46*/ {S, 0, 0, 1, "*H", "Theta"},
- /* 47*/ {S, 0, 0, 1, "*W", "Omega"},
- /* 48*/ {S, 0, 0, 1, "cu", "union"},
- /* 49*/ {S, 0, 0, 1, "rn", "root en"},
- /* 50*/ {S, 0, 0, 1, "ts", "terminal sigma (was root em)"},
- /* 51*/ {S, 0, 0, 1, "*L", "Lambda"},
- /* 52*/ {S, 0, 0, 1, "mi", "equation minus"},
- /* 53*/ {S, 0, 0, 1, "*G", "Gamma"},
- /* 54*/ {S, 0, 0, 1, "is", "integral sign"},
- /* 55*/ {S, 0, 0, 1, "*P", "Pi"},
- /* 56*/ {S, 0, 0, 1, "sb", "subset of"},
- /* 57*/ {S, 0, 0, 1, "sp", "superset of"},
- /* 58*/ {S, 0, 0, 1, "ap", "approximates"},
- /* 59*/ {S, 0, 0, 1, "pd", "partial derivative"},
- /* 60*/ {S, 0, 0, 1, "*D", "Delta"},
- /* 61*/ {S, 0, 0, 1, "sr", "square root"},
- /* 62*/ {S, 0, 0, 1, "*S", "Sigma"},
- /* 63*/ {S, 0, 0, 1, "~=", "approx ="},
- /* 64*/ {S, 0, 0, 1, ">", ">"},
- /* 65*/ {S, 0, 0, 1, "*C", "Xi"},
- /* 66*/ {S, 0, 0, 1, "<", "<"},
- /* 67*/ {S, 0, 0, 1, "/", "slash"},
- /* 68*/ {S, 0, 0, 1, "ca", "intersect"},
- /* 69*/ {S, 0, 0, 1, "*U", "Upsilon"},
- /* 70*/ {S, 0, 0, 1, "no", "logical not"},
- /* 71*/ {S, 0, 0, 1, "rc", "right ceiling"},
- /* 72*/ {S, 0, 0, 1, "lt", "left top brace"},
- /* 73*/ {S, 0, 0, 1, "bv", "bold vertical"},
- /* 74*/ {S, 0, 0, 1, "lk", "left ctr brace"},
- /* 75*/ {S, 0, 0, 1, "lb", "left bot brace"},
- /* 76*/ {S, 0, 0, 1, "rt", "right top brace"},
- /* 77*/ {S, 0, 0, 1, "rk", "right ctr brace"},
- /* 78*/ {S, 0, 0, 1, "rb", "right bot brace"},
- /* 79*/ {S, 0, 0, 1, "rf", "right floor"},
- /* 80*/ {S, 0, 0, 1, "lf", "left floor"},
- /* 81*/ {S, 0, 0, 1, "lc", "left ceiling"},
- /* 82*/ {S, 0, 0, 1, "mu", "multiply"},
- /* 83*/ {S, 0, 0, 1, "di", "divide"},
- /* 84*/ {S, 0, 0, 1, "+-", "plus-minus"},
- /* 85*/ {S, 0, 0, 1, "<=", "<="},
- /* 86*/ {S, 0, 0, 1, ">=", ">="},
- /* 87*/ {S, 0, 0, 1, "==", "identically equal"},
- /* 88*/ {S, 0, 0, 1, "!=", "not equal"},
- /* 89*/ {S, 0, 0, 1, "{", "{"},
- /* 90*/ {S, 0, 0, 1, "}", "}"},
- /* 91*/ {U, 0, 0, 1, "aa", "acute accent"},
- /* 92*/ {U, 0, 0, 1, "ga", "grave accent"},
- /* 93*/ {S, 0, 0, 1, "^", "^"},
- /* 94*/ {S, 0, 0, 1, "#", "#"},
- /* 95*/ {S, 0, 0, 1, "lh", "left hand"},
- /* 96*/ {S, 0, 0, 1, "mo", "member of"},
- /* 97*/ {U, 0, 0, 1, "~", "~"},
- /* 98*/ {S, 0, 0, 1, "es", "empty set"},
- /* 99*/ {S, 0, 0, 1, NOCODE, "unassigned"},
- /*100*/ {U, 0, 0, 1, "dd", "dbl dagger"},
- /*101*/ {S, 0, 0, 1, "br", "box rule (was parallel sign)"},
- /*102*/ {S, 0, 0, 1, "**", "math * "},
- /*103*/ {S, 0, 0, 1, "ib", "improper subset"},
- /*104*/ {S, 0, 0, 1, "ci", "circle"},
- /*105*/ {S, 0, 0, 1, NOCODE, "unassigned"},
- /*106*/ {S, 0, 0, 1, "pl", "equation plus"},
- /*107*/ {S, 0, 0, 1, "->", "right arrow"},
- /*108*/ {U, 0, 0, 1, "sc", "section"}
- };
-
- dtPage() {
- pagePending = 1;
- }
-
- static
- doPageStart(e) {
- currentPage++;
- pagePending = 0;
- printf("p%d\n", currentPage);
- }
-
- static int lastFont = (-1), lastPoints = (-1);
-
- dtSetFont(font, points)
- int font, points; {
- if (lastPoints != points || font != lastFont) {
- if (!(dtFts[font].flags)&USED)
- printf("x font %d %s\n", font+1, dtFts[font].troffName);
- dtFts[font].flags |= USED;
- printf("f%d\n", font+1);
- printf("s%d\n", points);
- lastPoints = points;
- lastFont = font;
- }
- }
-
- dtChar(x, y, font, points, troffChar)
- int x, y, font, points, troffChar; {
- static double lasty = (-1);
- register double nx = TROFF2DTX(x), ny = TROFF2DTY(y);
- register struct troff2befont *rp;
- register char *sequence = "a";
- 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("dtSetChar %d->%s (%s)\n", font,
- t2dtf[font]->troffName,
- t2dtf[font]->ascName);
- font = t2dtf[font] - dtFts;
- }
- 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;
- nx += points * rp->t2b_xc;
- ny += points * rp->t2b_yc;
- dtSetFont(font, points);
- #ifdef NOTYET
- if (rp->t2b_font == D)
- printf("H%d\nV%d\nc%s\n", (int) nx, (int) ny, sequence);
- else {
- #endif
- printf("H%d\n", (int) nx);
- if (lasty != ny) {
- printf("V%d\n", (int) ny);
- lasty = ny;
- }
- if (sequence[1])
- printf("C%s\n", sequence);
- else
- printf("c%s\n", sequence);
- #ifdef NOTYET
- }
- #endif
- }
-
- dtProlog() {
- extern char *getlogin(), *ctime();
- extern char *strchr();
- extern char nodename[];
- extern char *device;
- char buf2[512];
- char buffer[512];
- FILE *library;
- int c;
- long curtime;
-
- currentPage = 0;
- pagePending = 1;
-
- for (c = 0; c < 8; c++)
- t2dtf[c] = &dtFts[c];
-
- sprintf(buf2, "%s.%s", DTFONTS, be->bename);
-
- if ((library = fopen(buf2, "r")) == NULL) {
- sprintf(buffer, "%s/%s", LIBDIR, buf2);
- if ((library = fopen(buffer, "r")) == NULL) {
- fprintf(stderr, "Cannot open PostScript font definitions %s\n",
- buffer);
- exit(1);
- }
- }
-
- loadfontdefs(library);
- fclose(library);
-
- time(&curtime);
- strcpy(buffer, ctime(&curtime));
- *strchr(buffer, '\n') = '\0';
-
- getnodename();
-
- printf("#Title: (stdin)\n");
- printf("#Creator: %s %s %s\n", getlogin(), progname, T2VERSION);
- printf("#CreationDate: %s\n", buffer);
- printf("#For: %s\n", getlogin());
- printf("#Pages: (atend)\n");
- printf("#DocumentFonts: (atend)\n");
- printf("#EndComments\n");
- printf("x T %s\n", device);
- printf("x res %d %d %d\n", DTRESOLUTION, 1, 1);
- printf("x init\n");
-
- }
-
- dtEpilog() {
- printf("x trailer\n");
- printf("x stop\n");
- }
-
- dtFontSel(from, to)
- char from, *to; {
- #ifdef DEBUG
- register int i;
- register struct dtFts *p;
- #endif
- DEBUGPRINTF("dtFontSel: %c -> %s\n", from, to);
- if (from < '1' || from > '8') {
- fprintf(stderr, "Bad arguments to dtFontSel: %c %s\n", from, to);
- return;
- }
-
- for (p = dtFts; p->troffName; p++)
- if (strcmp(p->troffName, to) == 0) {
- t2dtf[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, t2dtf[i]->ascName);
- #endif
- }
-
- /*struct troff2befont *
- dtGetFontTables(which)
- int which; {
- return(which? symbolFont: standardFont);
- }*/
-
- static
- loadfontdefs(f)
- FILE *f; {
- struct dtFts *p = dtFts;
- extern char *malloc();
- int flags;
- char rbuf[512], nbuf[512], dtbuf[512];
- while(fgets(rbuf, sizeof(rbuf), f)) {
- if (rbuf[0] == '#')
- continue;
- switch(sscanf(rbuf, "%s%s", nbuf, dtbuf)) {
- default:
- break;
- case 2:
- if (nbuf[0] == '#')
- break;
- if (p - dtFts >= 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(dtbuf) + 1);
- strcpy(p->ascName, dtbuf);
- p->flags = 0;
- p++;
- }
- }
- #ifdef DEBUG
- for (p = dtFts; p->troffName; p++)
- DEBUGPRINTF("%s -> %s\n", p->troffName, p->ascName);
- #endif
- }
- #endif /* DT */
-