|
|
1.1 root 1: #include "tdef.h"
2: #include "fns.h"
3: #include "ext.h"
4:
5: /*
6: * troff10.c
7: *
8: * typesetter interface
9: */
10:
11: int vpos = 0; /* absolute vertical position on page */
12: int hpos = 0; /* ditto horizontal */
13:
14: extern Font fonts[MAXFONTS+1];
15:
16: int Inch;
17: int Hor;
18: int Vert;
19: int Unitwidth;
20: int nfonts;
21:
22:
23:
24: void t_ptinit(void)
25: {
26: int i;
27: char buf[100], *p;
28:
29: hmot = t_hmot;
30: makem = t_makem;
31: setabs = t_setabs;
32: setch = t_setch;
33: sethl = t_sethl;
34: setht = t_setht;
35: setslant = t_setslant;
36: vmot = t_vmot;
37: xlss = t_xlss;
38: findft = t_findft;
39: width = t_width;
40: mchbits = t_mchbits;
41: ptlead = t_ptlead;
42: ptout = t_ptout;
43: ptpause = t_ptpause;
44: setfont = t_setfont;
45: setps = t_setps;
46: setwd = t_setwd;
47:
48: /* open table for device, */
49: /* read in resolution, size info, font info, etc., set params */
50: if (termtab[0] == 0)
51: strcpy(termtab, FONTDIR);
52: if (fontdir[0] == 0)
53: strcpy(fontdir, FONTDIR);
54: if (devname[0] == 0)
55: strcpy(devname, TDEVNAME);
56: hyf = 1;
57: lg = 1;
58:
59: sprintf(buf, "/dev%s/DESC", devname);
60: strcat(termtab, buf);
61: if (getdesc(termtab) < 0) {
62: ERROR "can't open DESC file %s", termtab WARN;
63: done3(1);
64: }
65: if (!ascii) {
66: OUT "x T %s\n", devname PUT;
67: OUT "x res %d %d %d\n", Inch, Hor, Vert PUT;
68: OUT "x init\n" PUT;
69: }
70: for (i = 1; i <= nfonts; i++)
71: setfp(i, fontlab[i], (char *) 0, 0);
72: sps = EM/3; /* space size */
73: ics = EM; /* insertion character space */
74: for (i = 0; i < NTAB && DTAB * (i + 1) < TABMASK; i++)
75: tabtab[i] = DTAB * (i + 1);
76: pl = 11 * INCH; /* paper length */
77: po = PO; /* page offset */
78: spacesz = SS;
79: lss = lss1 = VS;
80: ll = ll1 = lt = lt1 = LL;
81: t_specnames(); /* install names like "hyphen", etc. */
82: }
83:
84: void t_specnames(void)
85: {
86: int i;
87:
88: for (i = 0; spnames[i].n; i++)
89: *spnames[i].n = chindex(spnames[i].v);
90: }
91:
92: void t_ptout(Tchar i)
93: {
94: int dv;
95: Tchar *k;
96: int temp, a, b;
97:
98: if (cbits(i) != '\n') {
99: if (olinep >= oline + OLNSIZE) {
100: ERROR "Output line overflow." WARN;
101: done(2);
102: }
103: *olinep++ = i;
104: return;
105: }
106: if (olinep == oline) {
107: lead += lss;
108: return;
109: }
110:
111: hpos = po; /* ??? */
112: esc = 0; /* ??? */
113: ptesc(); /* the problem is to get back to the left end of the line */
114: dv = 0;
115: for (k = oline; k < olinep; k++) {
116: if (ismot(*k) && isvmot(*k)) {
117: temp = absmot(*k);
118: if (isnmot(*k))
119: temp = -temp;
120: dv += temp;
121: }
122: }
123: if (dv) {
124: vflag++;
125: *olinep++ = makem(-dv);
126: vflag = 0;
127: }
128:
129: b = dip->blss + lss;
130: lead += dip->blss + lss;
131: dip->blss = 0;
132: for (k = oline; k < olinep; )
133: k += ptout0(k); /* now passing a pointer! */
134: olinep = oline;
135: lead += dip->alss;
136: a = dip->alss;
137: dip->alss = 0;
138: /*
139: OUT "x xxx end of line: hpos=%d, vpos=%d\n", hpos, vpos PUT;
140: */
141: OUT "n%d %d\n", b, a PUT; /* be nice to chuck */
142: }
143:
144: int ptout0(Tchar *pi)
145: {
146: int j, k, w;
147: int z, dx, dy, dx2, dy2, n;
148: Tchar i;
149: int outsize; /* size of object being printed */
150:
151: outsize = 1; /* default */
152: i = *pi;
153: k = cbits(i);
154: if (ismot(i)) {
155: j = absmot(i);
156: if (isnmot(i))
157: j = -j;
158: if (isvmot(i))
159: lead += j;
160: else
161: esc += j;
162: return(outsize);
163: }
164: if (k == CHARHT) {
165: if (xpts != mpts)
166: ptps();
167: OUT "x H %d\n", sbits(i) PUT;
168: return(outsize);
169: }
170: if (k == SLANT) {
171: OUT "x S %d\n", sfbits(i)-180 PUT;
172: return(outsize);
173: }
174: if (k == WORDSP) {
175: oput('w');
176: return(outsize);
177: }
178: if (sfbits(i) == oldbits) {
179: xfont = pfont;
180: xpts = ppts;
181: } else
182: xbits(i, 2);
183: if (k == XON) {
184: extern int xon;
185: ptflush(); /* guarantee that everything is out */
186: if (esc)
187: ptesc();
188: if (xfont != mfont)
189: ptfont();
190: if (xpts != mpts)
191: ptps();
192: if (lead)
193: ptlead();
194: OUT "x X " PUT;
195: xon++;
196: for (j = 1; cbits(pi[j]) != XOFF; j++)
197: outascii(pi[j]);
198: oput('\n');
199: xon--;
200: return j+1;
201: }
202: if (k < 040 && k != DRAWFCN)
203: return(outsize);
204: j = z = 0;
205: if (k != DRAWFCN) {
206: if (widcache[k].fontpts == (xfont<<8) + xpts && !setwdf) {
207: w = widcache[k].width;
208: bd = 0;
209: cs = 0;
210: } else
211: w = getcw(k);
212: if (cs) {
213: if (bd)
214: w += (bd - 1) * HOR;
215: j = (cs - w) / 2;
216: w = cs - j;
217: if (bd)
218: w -= (bd - 1) * HOR;
219: }
220: if (iszbit(i)) {
221: if (cs)
222: w = -j;
223: else
224: w = 0;
225: z = 1;
226: }
227: }
228: esc += j;
229: if (xfont != mfont)
230: ptfont();
231: if (xpts != mpts)
232: ptps();
233: if (lead)
234: ptlead();
235: /* put out the real character here */
236: if (k == DRAWFCN) {
237: if (esc)
238: ptesc();
239: w = 0;
240: dx = absmot(pi[3]);
241: if (isnmot(pi[3]))
242: dx = -dx;
243: dy = absmot(pi[4]);
244: if (isnmot(pi[4]))
245: dy = -dy;
246: switch (cbits(pi[1])) {
247: case DRAWCIRCLE: /* circle */
248: OUT "D%c %d\n", DRAWCIRCLE, dx PUT; /* dx is diameter */
249: hpos += dx;
250: break;
251: case DRAWELLIPSE:
252: OUT "D%c %d %d\n", DRAWELLIPSE, dx, dy PUT;
253: hpos += dx;
254: break;
255: case DRAWBUILD:
256: k = cbits(pi[2]);
257: OUT "D%c %d ", DRAWBUILD, dx PUT;
258: if (k < ALPHABET)
259: OUT "%c\n", k PUT;
260: else
261: OUT "%s\n", chnames[k - ALPHABET] PUT;
262: hpos += dx;
263: break;
264: case DRAWLINE: /* line */
265: k = cbits(pi[2]);
266: OUT "D%c %d %d ", DRAWLINE, dx, dy PUT;
267: if (k < ALPHABET)
268: OUT "%c\n", k PUT;
269: else
270: OUT "%s\n", chnames[k - ALPHABET] PUT;
271: hpos += dx;
272: vpos += dy;
273: break;
274: case DRAWARC: /* arc */
275: dx2 = absmot(pi[5]);
276: if (isnmot(pi[5]))
277: dx2 = -dx2;
278: dy2 = absmot(pi[6]);
279: if (isnmot(pi[6]))
280: dy2 = -dy2;
281: OUT "D%c %d %d %d %d\n", DRAWARC,
282: dx, dy, dx2, dy2 PUT;
283: hpos += dx + dx2;
284: vpos += dy + dy2;
285: break;
286:
287: case 's': /* using 's' internally to avoid .tr ~ */
288: pi[1] = '~';
289: case DRAWSPLINE: /* spline */
290: default: /* something else; copy it like spline */
291: OUT "D%c %d %d", cbits(pi[1]), dx, dy PUT;
292: hpos += dx;
293: vpos += dy;
294: if (cbits(pi[3]) == DRAWFCN || cbits(pi[4]) == DRAWFCN) {
295: /* it was somehow defective */
296: OUT "\n" PUT;
297: break;
298: }
299: for (n = 5; cbits(pi[n]) != DRAWFCN; n += 2) {
300: dx = absmot(pi[n]);
301: if (isnmot(pi[n]))
302: dx = -dx;
303: dy = absmot(pi[n+1]);
304: if (isnmot(pi[n+1]))
305: dy = -dy;
306: OUT " %d %d", dx, dy PUT;
307: hpos += dx;
308: vpos += dy;
309: }
310: OUT "\n" PUT;
311: break;
312: }
313: for (n = 3; cbits(pi[n]) != DRAWFCN; n++)
314: ;
315: outsize = n + 1;
316: } else if (k < ALPHABET) {
317: /* try to go faster and compress output */
318: /* by printing nnc for small positive motion followed by c */
319: /* kludgery; have to make sure set all the vars too */
320: if (esc > 0 && esc < 100) {
321: oput(esc / 10 + '0');
322: oput(esc % 10 + '0');
323: oput(k);
324: hpos += esc;
325: esc = 0;
326: } else {
327: if (esc)
328: ptesc();
329: oput('c');
330: oput(k);
331: oput('\n');
332: }
333: } else {
334: if (esc)
335: ptesc();
336: if (chnames[k-ALPHABET][0] == '#') /* DOESN'T WORK: name not nec #dnn */
337: OUT "N%s\n", &chnames[k-ALPHABET][1] PUT;
338: else
339: OUT "C%s\n", chnames[k - ALPHABET] PUT;
340: }
341: if (bd) {
342: bd -= HOR;
343: if (esc += bd)
344: ptesc();
345: if (k < ALPHABET) {
346: OUT "c%c\n", k PUT;
347: } else if (chnames[k-ALPHABET][0] == '#') { /* DOESN'T WORK: name not nec #dnn */
348: OUT "N%s\n", &chnames[k-ALPHABET][1] PUT;
349: } else
350: OUT "C%s\n", chnames[k - ALPHABET] PUT;
351: if (z)
352: esc -= bd;
353: }
354: esc += w;
355: return(outsize);
356: }
357:
358: void ptflush(void) /* get us to a clean output state */
359: {
360: if (TROFF) {
361: /* ptesc(); but always H, no h */
362: hpos += esc;
363: OUT "\nH%d\n", hpos PUT;
364: esc = 0;
365: ptps();
366: ptfont();
367: ptlead();
368: }
369: }
370:
371: void ptps(void)
372: {
373: int i, j, k;
374:
375: i = xpts;
376: for (j = 0; i > (k = pstab[j]); j++)
377: if (!k) {
378: k = pstab[--j];
379: break;
380: }
381: OUT "s%d\n", k PUT; /* really should put out string rep of size */
382: mpts = i;
383: }
384:
385: void ptfont(void)
386: {
387: mfont = xfont;
388: if (xfont > nfonts) {
389: ptfpcmd(0, fonts[xfont].longname, 0); /* Put the desired font in the
390: * fontcache of the filter */
391: OUT "f0\n" PUT; /* make sure that it gets noticed */
392: } else
393: OUT "f%d\n", xfont PUT;
394: }
395:
396: void ptfpcmd(int f, char *s, char *longname)
397: {
398: if (ascii)
399: return;
400: if (f > nfonts) /* a bit risky? */
401: f = 0;
402: if (longname) {
403: OUT "x font %d %s %s\n", f, s, longname PUT;
404: } else {
405: OUT "x font %d %s\n", f, s PUT;
406: }
407: /* OUT "f%d\n", xfont PUT; /* need this for buggy version of adobe transcript */
408: /* which apparently believes that x font means */
409: /* to set the font, not just the position. */
410: }
411:
412: void t_ptlead(void)
413: {
414: vpos += lead;
415: if (!ascii)
416: OUT "V%d\n", vpos PUT;
417: lead = 0;
418: }
419:
420: void ptesc(void)
421: {
422: hpos += esc;
423: if (esc > 0) {
424: oput('h');
425: if (esc>=10 && esc<100) {
426: oput(esc/10 + '0');
427: oput(esc%10 + '0');
428: } else
429: OUT "%d", esc PUT;
430: } else
431: OUT "H%d\n", hpos PUT;
432: esc = 0;
433: }
434:
435: void ptpage(int n) /* called at end of each output page, we hope */
436: {
437: int i;
438:
439: if (NROFF)
440: return;
441: ptlead();
442: vpos = 0;
443: if (ascii)
444: return;
445: OUT "p%d\n", n PUT; /* new page */
446: for (i = 0; i <= nfonts; i++)
447: if (fontlab[i]) {
448: if (fonts[i].truename)
449: OUT "x font %d %s %s\n", i, fonts[i].longname, fonts[i].truename PUT;
450: else
451: OUT "x font %d %s\n", i, fonts[i].longname PUT;
452: }
453: ptps();
454: ptfont();
455: }
456:
457: void pttrailer(void)
458: {
459: if (TROFF)
460: OUT "x trailer\n" PUT;
461: }
462:
463: void ptstop(void)
464: {
465: if (TROFF)
466: OUT "x stop\n" PUT;
467: }
468:
469: void t_ptpause(void)
470: {
471: if (ascii)
472: return;
473: ptlead();
474: vpos = 0;
475: pttrailer();
476: ptlead();
477: OUT "x pause\n" PUT;
478: flusho();
479: mpts = mfont = 0;
480: ptesc();
481: esc = po;
482: hpos = vpos = 0; /* probably in wrong place */
483: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.