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