1 |
– |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* text.c - functions for text patterns and mixtures. |
9 |
– |
* |
10 |
– |
* 11/12/86 |
6 |
|
*/ |
7 |
|
|
8 |
< |
#include "ray.h" |
8 |
> |
#include "copyright.h" |
9 |
|
|
10 |
+ |
#include "ray.h" |
11 |
+ |
#include "paths.h" |
12 |
|
#include "otypes.h" |
13 |
< |
|
13 |
> |
#include "rtotypes.h" |
14 |
|
#include "font.h" |
15 |
|
|
16 |
|
/* |
42 |
|
* [spacing] |
43 |
|
* |
44 |
|
* Colortext is identical, except colors are given rather than |
45 |
< |
* brightnesses. Mixtext has foreground and background modifiers: |
45 |
> |
* brightnesses. |
46 |
|
* |
47 |
+ |
* Mixtext has foreground and background modifiers: |
48 |
+ |
* |
49 |
|
* modifier mixtext id |
50 |
|
* 4+ foremod backmod fontfile text.. |
51 |
|
* 0 |
76 |
|
TLINE tl; /* line list */ |
77 |
|
} TEXT; |
78 |
|
|
79 |
< |
extern char *getlibpath(); |
79 |
> |
static TLINE * tlalloc(char *s); |
80 |
> |
static TEXT * gettext(OBJREC *tm); |
81 |
> |
static int intext(FVECT p, OBJREC *m); |
82 |
> |
static int inglyph(double x, double y, GLYPH *gl); |
83 |
|
|
82 |
– |
extern char *fgetword(); |
84 |
|
|
85 |
< |
TEXT *gettext(); |
86 |
< |
|
87 |
< |
TLINE *tlalloc(); |
88 |
< |
|
89 |
< |
|
89 |
< |
text(m, r) |
90 |
< |
register OBJREC *m; |
91 |
< |
RAY *r; |
85 |
> |
int |
86 |
> |
do_text( |
87 |
> |
OBJREC *m, |
88 |
> |
RAY *r |
89 |
> |
) |
90 |
|
{ |
91 |
|
FVECT v; |
92 |
|
int foreground; |
103 |
|
char *modname = m->oargs.sarg[foreground ? 0 : 1]; |
104 |
|
if (!strcmp(modname, VOIDID)) |
105 |
|
omod = OVOID; |
106 |
< |
else if ((omod = modifier(modname)) == OVOID) { |
106 |
> |
else if ((omod = lastmod(objndx(m), modname)) == OVOID) { |
107 |
|
sprintf(errmsg, "undefined modifier \"%s\"", modname); |
108 |
|
objerror(m, USER, errmsg); |
109 |
|
} |
112 |
|
objerror(m, USER, "inappropriate modifier"); |
113 |
|
return(1); |
114 |
|
} |
115 |
< |
} |
118 |
< |
if (m->otype == PAT_BTEXT) { |
115 |
> |
} else if (m->otype == PAT_BTEXT) { |
116 |
|
if (foreground) |
117 |
|
scalecolor(r->pcol, m->oargs.farg[9]); |
118 |
|
else |
133 |
|
} |
134 |
|
|
135 |
|
|
136 |
< |
TLINE * |
137 |
< |
tlalloc(s) /* allocate and assign text line */ |
138 |
< |
char *s; |
136 |
> |
static TLINE * |
137 |
> |
tlalloc( /* allocate and assign text line */ |
138 |
> |
char *s |
139 |
> |
) |
140 |
|
{ |
141 |
< |
extern char *strcpy(); |
142 |
< |
register int siz; |
145 |
< |
register TLINE *tl; |
141 |
> |
int siz; |
142 |
> |
TLINE *tl; |
143 |
|
|
144 |
|
siz = strlen(s) + 1; |
145 |
|
if ((tl=(TLINE *)malloc(sizeof(TLINE)+siz)) == NULL || |
151 |
|
} |
152 |
|
|
153 |
|
|
154 |
< |
TEXT * |
155 |
< |
gettext(tm) /* get text structure for material */ |
156 |
< |
register OBJREC *tm; |
154 |
> |
static TEXT * |
155 |
> |
gettext( /* get text structure for material */ |
156 |
> |
OBJREC *tm |
157 |
> |
) |
158 |
|
{ |
159 |
|
#define R (tm->oargs.farg+3) |
160 |
|
#define D (tm->oargs.farg+6) |
163 |
– |
extern char *strcpy(); |
161 |
|
FVECT DxR; |
162 |
|
double d; |
163 |
|
FILE *fp; |
164 |
|
char linbuf[512]; |
165 |
|
TEXT *t; |
166 |
< |
register int i; |
167 |
< |
register TLINE *tlp; |
168 |
< |
register char *s; |
166 |
> |
int i; |
167 |
> |
TLINE *tlp; |
168 |
> |
char *s; |
169 |
|
|
170 |
|
if ((t = (TEXT *)tm->os) != NULL) |
171 |
|
return(t); |
177 |
|
/* compute vectors */ |
178 |
|
fcross(DxR, D, R); |
179 |
|
fcross(t->right, DxR, D); |
180 |
< |
d = DOT(D,D)/DOT(t->right,t->right); |
180 |
> |
d = DOT(t->right,t->right); |
181 |
> |
if (d <= FTINY*FTINY*FTINY*FTINY) |
182 |
> |
objerror(tm, USER, "illegal motion vector"); |
183 |
> |
d = DOT(D,D)/d; |
184 |
|
for (i = 0; i < 3; i++) |
185 |
|
t->right[i] *= d; |
186 |
|
fcross(t->down, R, DxR); |
201 |
|
tlp = tlp->next; |
202 |
|
} else { /* text file */ |
203 |
|
if ((s = getpath(tm->oargs.sarg[tndx(tm)], |
204 |
< |
getlibpath(), R_OK)) == NULL) { |
204 |
> |
getrlibpath(), R_OK)) == NULL) { |
205 |
|
sprintf(errmsg, "cannot find text file \"%s\"", |
206 |
|
tm->oargs.sarg[tndx(tm)]); |
207 |
< |
error(USER, errmsg); |
207 |
> |
error(SYSTEM, errmsg); |
208 |
|
} |
209 |
|
if ((fp = fopen(s, "r")) == NULL) { |
210 |
|
sprintf(errmsg, "cannot open text file \"%s\"", s); |
222 |
|
tlp->next = NULL; |
223 |
|
/* get the font */ |
224 |
|
t->f = getfont(tm->oargs.sarg[fndx(tm)]); |
225 |
+ |
if (!t->f) |
226 |
+ |
objerror(tm, USER, "font load error"); |
227 |
|
/* compute character spacing */ |
228 |
|
i = sndx(tm); |
229 |
|
d = i < tm->oargs.nfargs ? tm->oargs.farg[i] : 0.0; |
247 |
|
} |
248 |
|
|
249 |
|
|
250 |
< |
freetext(m) /* free text structures associated with m */ |
251 |
< |
OBJREC *m; |
250 |
> |
void |
251 |
> |
freetext( /* free text structures associated with m */ |
252 |
> |
OBJREC *m |
253 |
> |
) |
254 |
|
{ |
255 |
< |
register TEXT *tp; |
256 |
< |
register TLINE *tlp; |
255 |
> |
TEXT *tp; |
256 |
> |
TLINE *tlp; |
257 |
|
|
258 |
|
tp = (TEXT *)m->os; |
259 |
|
if (tp == NULL) |
260 |
|
return; |
261 |
|
while ((tlp = tp->tl.next) != NULL) { |
262 |
|
tp->tl.next = tlp->next; |
263 |
< |
free((char *)tlp->spc); |
264 |
< |
free((char *)tlp); |
263 |
> |
free((void *)tlp->spc); |
264 |
> |
free((void *)tlp); |
265 |
|
} |
266 |
< |
free((char *)tp); |
266 |
> |
freefont(tp->f); /* release font reference */ |
267 |
> |
free((void *)tp); |
268 |
|
m->os = NULL; |
269 |
|
} |
270 |
|
|
271 |
|
|
272 |
< |
intext(p, m) /* check to see if p is in text glyph */ |
273 |
< |
FVECT p; |
274 |
< |
OBJREC *m; |
272 |
> |
static int |
273 |
> |
intext( /* check to see if p is in text glyph */ |
274 |
> |
FVECT p, |
275 |
> |
OBJREC *m |
276 |
> |
) |
277 |
|
{ |
278 |
< |
register TEXT *tp; |
279 |
< |
register TLINE *tlp; |
278 |
> |
TEXT *tp; |
279 |
> |
TLINE *tlp; |
280 |
|
FVECT v; |
281 |
|
double y, x; |
282 |
< |
register int i, h; |
282 |
> |
int i, h; |
283 |
|
/* first, compute position in text */ |
284 |
|
tp = gettext(m); |
285 |
|
v[0] = p[0] - m->oargs.farg[0]; |
311 |
|
} |
312 |
|
|
313 |
|
|
314 |
< |
inglyph(x, y, gl) /* (x,y) within font glyph gl? */ |
315 |
< |
double x, y; /* real coordinates in range [0,255) */ |
316 |
< |
register GLYPH *gl; |
314 |
> |
static int |
315 |
> |
inglyph( /* (x,y) within font glyph gl? */ |
316 |
> |
double x, /* real coordinates in range [0,255) */ |
317 |
> |
double y, |
318 |
> |
GLYPH *gl |
319 |
> |
) |
320 |
|
{ |
321 |
|
int n, ncross; |
322 |
|
int xlb, ylb; |
323 |
|
int tv; |
324 |
< |
register GORD *p0, *p1; |
324 |
> |
GORD *p0, *p1; |
325 |
|
|
326 |
|
if (gl == NULL) |
327 |
|
return(0); |
339 |
|
/* positive x axis cross test */ |
340 |
|
while (n--) { |
341 |
|
if ((p0[1]<<1 > ylb) ^ (p1[1]<<1 > ylb)) { |
342 |
< |
tv = p0[0]<<1 > xlb | (p1[0]<<1 > xlb) << 1; |
342 |
> |
tv = (p0[0]<<1 > xlb) | ((p1[0]<<1 > xlb) << 1); |
343 |
|
if (tv == 03) |
344 |
|
ncross++; |
345 |
|
else if (tv) |