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 static double prevh = 0;
12 static double prevw = 0;
13 Attr *ap;
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 }
98 obj*
99 troffgen(char *s) /* save away a string of troff commands */
101 savetext(CENTER, s); /* use the existing text mechanism */
102 return makenode(TROFF, 0);
105 void
106 savetext(int t, char *s) /* record text elements for current object */
108 if (ntext >= ntextlist)
109 text = (Text *) grow((char *) text, "text", ntextlist += 200, sizeof(Text));
110 text[ntext].t_type = t;
111 text[ntext].t_val = s;
112 dprintf("saving %d text %s at %d\n", t, s, ntext);
113 ntext++;