|
|
1.1 root 1: /* Copyright (c) 1990 AT&T */
2: /* All Rights Reserved */
3:
4: /* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T */
5: /* The copyright notice above does not evidence any */
6: /* actual or intended publication of such source code. */
7:
8: /* @(#)picasso:picgen.c 1.0 */
9: #include "picasso.h"
10: #include "y.tab.h"
11:
12: obj *picgen()
13: {
14: static double prevht = HT;
15: static double prevwid = WID; /* golden mean, sort of */
16: static char *prevname = "";
17:
18: char *checkeps();
19: struct objattr obat;
20: double x0, y0, x1, y1, xwith, ywith;
21: char *epsname;
22: int i, at, with;
23: obj *p, *ppos;
24: Attr *ap;
25:
26: epsname = NULL;
27: obat.a_ht = 0;
28: obat.a_wid = 0;
29: obat.a_layer = (int)getfval("curlayer");
30: obat.a_flags = EDGED;
31: obat.a_weight = obat.a_lcolor = obat.a_pcolor = obat.a_tcolor = -1;
32: obat.a_dashpat.a = (float *)0;
33: set_text();
34: at = with = xwith = ywith = 0;
35: for (i = 0; i < nattr; i++) {
36: ap = &attr[i];
37: switch (ap->a_type) {
38: default:
39: miscattrs(ap, &obat);
40: break;
41: case SAME:
42: obat.a_ht = prevht;
43: obat.a_wid = prevwid;
44: epsname = prevname;
45: break;
46: case WITH:
47: with = ap->a_val.i; /* corner */
48: break;
49: case AT:
50: ppos = ap->a_val.o;
51: curx = Xformx(ppos, 1, ppos->o_x, ppos->o_y);
52: cury = Xformy(ppos, 0, ppos->o_x, ppos->o_y);
53: at++;
54: break;
55: }
56: }
57: /*
58: * The first text string should be used as the name of an
59: * Encapsulated PostScript file. If missing, or if not an
60: * EPSF, it's an error.
61: */
62: if ((epsname = checkeps(&obat, epsname)) == NULL)
63: return NULL;
64: if (with) {
65: switch (with) {
66: case NORTH: ywith = -obat.a_ht/2; break;
67: case SOUTH: ywith = obat.a_ht/2; break;
68: case EAST: xwith = -obat.a_wid/2; break;
69: case WEST: xwith = obat.a_wid/2; break;
70: case NE: xwith = -obat.a_wid/2;
71: ywith = -obat.a_ht/2; break;
72: case SE: xwith = -obat.a_wid/2;
73: ywith = obat.a_ht/2; break;
74: case NW: xwith = obat.a_wid/2;
75: ywith = -obat.a_ht/2; break;
76: case SW: xwith = obat.a_wid/2;
77: ywith = obat.a_ht/2; break;
78: case CENTER:
79: case START:
80: case END: break;
81: default: xwith = -obat.a_wid/2 * xdelta[with%8];
82: ywith = -obat.a_ht/2 * ydelta[with%8]; break;
83: }
84: curx += xwith;
85: cury += ywith;
86: }
87: if (!at) {
88: if (isright(hvmode))
89: curx += obat.a_wid/2;
90: else if (isleft(hvmode))
91: curx -= obat.a_wid/2;
92: else if (isup(hvmode))
93: cury += obat.a_ht/2;
94: else
95: cury -= obat.a_ht/2;
96: }
97: p = makenode(PSFILE, N_VAL+1, obat.a_layer);
98: p->o_val[N_VAL-1].p = epsname;
99: p->o_val[N_VAL].f = 0.; /* rounded corners, yet */
100: p->o_wid = obat.a_wid;
101: p->o_ht = obat.a_ht;
102: x0 = curx - obat.a_wid/2;
103: y0 = cury - obat.a_ht/2;
104: x1 = curx + obat.a_wid/2;
105: y1 = cury + obat.a_ht/2;
106: primattrs(p,&obat);
107: text_bounds(p);
108: track_bounds(x0-p->o_weight/2, y0-p->o_weight/2,
109: x1+p->o_weight/2, y1+p->o_weight/2);
110: if (isright(hvmode))
111: curx = x1;
112: else if (isleft(hvmode))
113: curx = x0;
114: else if (isup(hvmode))
115: cury = y1;
116: else
117: cury = y0;
118: prevht = obat.a_ht;
119: prevwid = obat.a_wid;
120: prevname = epsname;
121: return(p);
122: }
123:
124: char *
125: checkeps(obat, tname)
126: struct objattr *obat;
127: char *tname;
128: {
129: int urx, ury, llx, lly;
130: char buf[128];
131: FILE *fp;
132:
133: if (tname != NULL)
134: return tname;
135: if (ntext1 == ntext) { /* nostrings */
136: yyerror("no EPS file named");
137: return NULL;
138: }
139: tname = text[ntext1].t_val;
140: if ((fp = fopen(tname, "r")) == NULL) {
141: yyerror("can't read EPS file %s", tname);
142: return NULL;
143: }
144: ntext1++; /* filename is NOT one of the label strings */
145: llx = lly == - (urx = ury = -65535);
146: while (fgets(buf, 128, fp) != NULL) {
147: if (strncmp(buf, "%%BoundingBox:", 14) != 0)
148: continue;
149: llx = lly == - (urx = ury = -65535);
150: if (sscanf(buf+14, "%d %d %d %d", &llx, &lly, &urx, &ury) > 2)
151: break;
152: }
153: fclose(fp);
154: /* NOTE: if no BoundingBox comment was found, size will be 0x0 */
155: /* unless height and width were set explicitly */
156: if (urx < llx)
157: urx = llx;
158: if (ury < lly)
159: ury = lly;
160: if (obat->a_wid == 0 && obat->a_ht == 0) {
161: obat->a_wid = (double) (urx - llx) / pgscale;
162: obat->a_ht = (double) (ury - lly) / pgscale;
163: }
164: else if (obat->a_wid == 0 && ury - lly != 0)
165: obat->a_wid = obat->a_ht * (urx - llx) / (ury - lly);
166: else if (obat->a_ht == 0 && urx - llx != 0)
167: obat->a_ht = obat->a_wid * (ury - lly) / (urx - llx);
168: if (obat->a_wid == 0)
169: obat->a_wid = getfval("boxwid");
170: if (obat->a_ht == 0)
171: obat->a_ht = getfval("boxht");
172: return tname;
173: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.