Blob


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