|
|
1.1 root 1: #include <stdio.h>
2: #include "pic.h"
3: #include "y.tab.h"
4:
5: obj *textgen()
6: {
7: int i, type, sub, nstr, at, with, hset;
8: float xwith, ywith, h, w, x0, y0, x1, y1;
9: obj *p, *ppos;
10: static float prevh = 0;
11: static float prevw = 0;
12: Attr *ap;
13:
14: sub = CENTER;
15: at = with = nstr = hset = 0;
16: h = getfval("textht");
17: w = getfval("textwid");
18: for (i = 0; i < nattr; i++) {
19: ap = &attr[i];
20: switch (ap->a_type) {
21: case HEIGHT:
22: h = ap->a_val.f;
23: hset++;
24: break;
25: case WIDTH:
26: w = ap->a_val.f;
27: break;
28: case WITH:
29: with = ap->a_val.i;
30: break;
31: case AT:
32: ppos = ap->a_val.o;
33: curx = ppos->o_x;
34: cury = ppos->o_y;
35: at++;
36: break;
37: case TEXTATTR:
38: sub = ap->a_sub;
39: if (ap->a_val.p == NULL) /* an isolated modifier */
40: text[ntext-1].t_type = sub;
41: else {
42: savetext(sub, ap->a_val.p);
43: nstr++;
44: }
45: break;
46: }
47: }
48: if (hset == 0) /* no explicit ht cmd */
49: h *= nstr;
50: if (with) {
51: xwith = ywith = 0.0;
52: switch (with) {
53: case NORTH: ywith = -h / 2; break;
54: case SOUTH: ywith = h / 2; break;
55: case EAST: xwith = -w / 2; break;
56: case WEST: xwith = w / 2; break;
57: case NE: xwith = -w / 2; ywith = -h / 2; break;
58: case SE: xwith = -w / 2; ywith = h / 2; break;
59: case NW: xwith = w / 2; ywith = -h / 2; break;
60: case SW: xwith = w / 2; ywith = h / 2; break;
61: }
62: curx += xwith;
63: cury += ywith;
64: }
65: if (!at) {
66: if (isright(hvmode))
67: curx += w / 2;
68: else if (isleft(hvmode))
69: curx -= w / 2;
70: else if (isup(hvmode))
71: cury += h / 2;
72: else
73: cury -= h / 2;
74: }
75: x0 = curx - w / 2;
76: y0 = cury - h / 2;
77: x1 = curx + w / 2;
78: y1 = cury + h / 2;
79: extreme(x0, y0);
80: extreme(x1, y1);
81: dprintf("Text h %g w %g at %g,%g\n", h, w, curx, cury);
82: p = makenode(TEXT, 2);
83: p->o_val[0] = w;
84: p->o_val[1] = h;
85: if (isright(hvmode))
86: curx = x1;
87: else if (isleft(hvmode))
88: curx = x0;
89: else if (isup(hvmode))
90: cury = y1;
91: else
92: cury = y0;
93: prevh = h;
94: prevw = w;
95: return(p);
96: }
97:
98: obj *troffgen(s) /* save away a string of troff commands */
99: YYSTYPE s;
100: {
101: savetext(CENTER, s.p); /* use the existing text mechanism */
102: return makenode(TROFF, 0);
103: }
104:
105: savetext(t, s) /* record text elements for current object */
106: int t;
107: char *s;
108: {
109: if (ntext >= ntextlist)
110: text = (Text *) grow((char *) text, "text", ntextlist += 200, sizeof(Text));
111: text[ntext].t_type = t;
112: text[ntext].t_val = s;
113: dprintf("saving %d text %s at %d\n", t, s, ntext);
114: ntext++;
115: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.