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