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 "copyright.h" |
9 |
+ |
|
10 |
|
#include "ray.h" |
11 |
|
|
12 |
+ |
#include "paths.h" |
13 |
+ |
|
14 |
|
#include "otypes.h" |
15 |
|
|
16 |
|
#include "font.h" |
44 |
|
* [spacing] |
45 |
|
* |
46 |
|
* Colortext is identical, except colors are given rather than |
47 |
< |
* brightnesses. Mixtext has foreground and background modifiers: |
47 |
> |
* brightnesses. |
48 |
|
* |
49 |
+ |
* Mixtext has foreground and background modifiers: |
50 |
+ |
* |
51 |
|
* modifier mixtext id |
52 |
|
* 4+ foremod backmod fontfile text.. |
53 |
|
* 0 |
78 |
|
TLINE tl; /* line list */ |
79 |
|
} TEXT; |
80 |
|
|
80 |
– |
extern char *libpath; |
81 |
– |
|
82 |
– |
extern char *fgetword(); |
83 |
– |
|
81 |
|
TEXT *gettext(); |
82 |
|
|
83 |
|
TLINE *tlalloc(); |
84 |
|
|
85 |
|
|
86 |
< |
text(m, r) |
86 |
> |
do_text(m, r) |
87 |
|
register OBJREC *m; |
88 |
|
RAY *r; |
89 |
|
{ |
102 |
|
char *modname = m->oargs.sarg[foreground ? 0 : 1]; |
103 |
|
if (!strcmp(modname, VOIDID)) |
104 |
|
omod = OVOID; |
105 |
< |
else if ((omod = modifier(modname)) == OVOID) { |
105 |
> |
else if ((omod = lastmod(objndx(m), modname)) == OVOID) { |
106 |
|
sprintf(errmsg, "undefined modifier \"%s\"", modname); |
107 |
|
objerror(m, USER, errmsg); |
108 |
|
} |
109 |
< |
raytexture(r, omod); |
109 |
> |
if (rayshade(r, omod)) { |
110 |
> |
if (m->omod != OVOID) |
111 |
> |
objerror(m, USER, "inappropriate modifier"); |
112 |
> |
return(1); |
113 |
> |
} |
114 |
|
} else if (m->otype == PAT_BTEXT) { |
115 |
|
if (foreground) |
116 |
|
scalecolor(r->pcol, m->oargs.farg[9]); |
128 |
|
m->oargs.farg[14]); |
129 |
|
multcolor(r->pcol, cval); |
130 |
|
} |
131 |
+ |
return(0); |
132 |
|
} |
133 |
|
|
134 |
|
|
136 |
|
tlalloc(s) /* allocate and assign text line */ |
137 |
|
char *s; |
138 |
|
{ |
137 |
– |
extern char *strcpy(); |
139 |
|
register int siz; |
140 |
|
register TLINE *tl; |
141 |
|
|
143 |
|
if ((tl=(TLINE *)malloc(sizeof(TLINE)+siz)) == NULL || |
144 |
|
(tl->spc=(short *)malloc(siz*sizeof(short))) == NULL) |
145 |
|
error(SYSTEM, "out of memory in tlalloc"); |
145 |
– |
tl->spc = NULL; |
146 |
|
tl->next = NULL; |
147 |
|
strcpy(TLSTR(tl), s); |
148 |
|
return(tl); |
155 |
|
{ |
156 |
|
#define R (tm->oargs.farg+3) |
157 |
|
#define D (tm->oargs.farg+6) |
158 |
– |
extern char *strcpy(), *fgets(); |
158 |
|
FVECT DxR; |
159 |
|
double d; |
160 |
|
FILE *fp; |
170 |
|
if (tm->oargs.nsargs - tndx(tm) < 1 || tm->oargs.nfargs < sndx(tm)) |
171 |
|
objerror(tm, USER, "bad # arguments"); |
172 |
|
if ((t = (TEXT *)malloc(sizeof(TEXT))) == NULL) |
173 |
< |
goto memerr; |
173 |
> |
error(SYSTEM, "out of memory in gettext"); |
174 |
|
/* compute vectors */ |
175 |
|
fcross(DxR, D, R); |
176 |
|
fcross(t->right, DxR, D); |
177 |
< |
d = DOT(D,D)/DOT(t->right,t->right); |
177 |
> |
d = DOT(t->right,t->right); |
178 |
> |
if (d <= FTINY*FTINY*FTINY*FTINY) |
179 |
> |
objerror(tm, USER, "illegal motion vector"); |
180 |
> |
d = DOT(D,D)/d; |
181 |
|
for (i = 0; i < 3; i++) |
182 |
|
t->right[i] *= d; |
183 |
|
fcross(t->down, R, DxR); |
198 |
|
tlp = tlp->next; |
199 |
|
} else { /* text file */ |
200 |
|
if ((s = getpath(tm->oargs.sarg[tndx(tm)], |
201 |
< |
libpath, R_OK)) == NULL) { |
201 |
> |
getrlibpath(), R_OK)) == NULL) { |
202 |
|
sprintf(errmsg, "cannot find text file \"%s\"", |
203 |
|
tm->oargs.sarg[tndx(tm)]); |
204 |
|
error(USER, errmsg); |
222 |
|
/* compute character spacing */ |
223 |
|
i = sndx(tm); |
224 |
|
d = i < tm->oargs.nfargs ? tm->oargs.farg[i] : 0.0; |
225 |
< |
i = d * 256.0; |
225 |
> |
i = d * 255.0; |
226 |
|
t->tl.width = 0; |
227 |
|
for (tlp = t->tl.next; tlp != NULL; tlp = tlp->next) { |
226 |
– |
if ((tlp->spc = (short *)malloc( |
227 |
– |
(strlen(TLSTR(tlp))+1)*sizeof(short))) == NULL) |
228 |
– |
goto memerr; |
228 |
|
if (i < 0) |
229 |
|
tlp->width = squeeztext(tlp->spc, TLSTR(tlp), t->f, -i); |
230 |
|
else if (i > 0) |
237 |
|
/* we're done */ |
238 |
|
tm->os = (char *)t; |
239 |
|
return(t); |
241 |
– |
memerr: |
242 |
– |
error(SYSTEM, "out of memory in gettext"); |
240 |
|
#undef R |
241 |
|
#undef D |
242 |
|
} |
253 |
|
return; |
254 |
|
while ((tlp = tp->tl.next) != NULL) { |
255 |
|
tp->tl.next = tlp->next; |
256 |
< |
free((char *)tlp->spc); |
257 |
< |
free((char *)tlp); |
256 |
> |
free((void *)tlp->spc); |
257 |
> |
free((void *)tlp); |
258 |
|
} |
259 |
< |
free((char *)tp); |
259 |
> |
freefont(tp->f); /* release font reference */ |
260 |
> |
free((void *)tp); |
261 |
|
m->os = NULL; |
262 |
|
} |
263 |
|
|
279 |
|
x = DOT(v, tp->right); |
280 |
|
i = sndx(m); |
281 |
|
if (i < m->oargs.nfargs) |
282 |
< |
x *= tp->f->mwidth + 256.*fabs(m->oargs.farg[i]); |
282 |
> |
x *= tp->f->mwidth + 255.*fabs(m->oargs.farg[i]); |
283 |
|
else |
284 |
< |
x *= 256.; |
284 |
> |
x *= 255.; |
285 |
|
h = x; |
286 |
|
i = y = DOT(v, tp->down); |
287 |
|
if (x < 0.0 || y < 0.0) |
288 |
|
return(0); |
289 |
|
x -= (double)h; |
290 |
< |
y = ((i+1) - y)*256.; |
290 |
> |
y = ((i+1) - y)*255.; |
291 |
|
/* find the line position */ |
292 |
|
for (tlp = tp->tl.next; tlp != NULL; tlp = tlp->next) |
293 |
|
if (--i < 0) |
295 |
|
if (tlp == NULL || h >= tlp->width) |
296 |
|
return(0); |
297 |
|
for (i = 0; (h -= tlp->spc[i]) >= 0; i++) |
298 |
< |
if (h < 256 && inglyph(h+x, y, |
298 |
> |
if (h < 255 && inglyph(h+x, y, |
299 |
|
tp->f->fg[TLSTR(tlp)[i]&0xff])) |
300 |
|
return(1); |
301 |
|
return(0); |
303 |
|
|
304 |
|
|
305 |
|
inglyph(x, y, gl) /* (x,y) within font glyph gl? */ |
306 |
< |
double x, y; /* real coordinates in range [0,256) */ |
306 |
> |
double x, y; /* real coordinates in range [0,255) */ |
307 |
|
register GLYPH *gl; |
308 |
|
{ |
309 |
|
int n, ncross; |
327 |
|
/* positive x axis cross test */ |
328 |
|
while (n--) { |
329 |
|
if ((p0[1]<<1 > ylb) ^ (p1[1]<<1 > ylb)) { |
330 |
< |
tv = p0[0]<<1 > xlb | (p1[0]<<1 > xlb) << 1; |
330 |
> |
tv = (p0[0]<<1 > xlb) | ((p1[0]<<1 > xlb) << 1); |
331 |
|
if (tv == 03) |
332 |
|
ncross++; |
333 |
|
else if (tv) |