1 |
– |
/* Copyright (c) 1990 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 |
+ |
#include "rtotypes.h" |
14 |
+ |
#include "font.h" |
15 |
|
|
16 |
|
/* |
17 |
|
* A text pattern is specified as the text (a file or line), |
22 |
|
* modifier brighttext id |
23 |
|
* 2 fontfile textfile |
24 |
|
* 0 |
25 |
< |
* 11 |
25 |
> |
* 11+ |
26 |
|
* Ax Ay Az |
27 |
|
* Rx Ry Rz |
28 |
|
* Dx Dy Dz |
29 |
|
* foreground background |
30 |
+ |
* [spacing] |
31 |
|
* |
32 |
|
* For a single line, we use: |
33 |
|
* |
34 |
|
* modifier brighttext id |
35 |
|
* N+2 fontfile . This is a line with N words... |
36 |
|
* 0 |
37 |
< |
* 11 |
37 |
> |
* 11+ |
38 |
|
* Ax Ay Az |
39 |
|
* Rx Ry Rz |
40 |
|
* Dx Dy Dz |
41 |
|
* foreground background |
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 |
52 |
< |
* 9 |
52 |
> |
* 9+ |
53 |
|
* Ax Ay Az |
54 |
|
* Rx Ry Rz |
55 |
|
* Dx Dy Dz |
56 |
+ |
* [spacing] |
57 |
|
*/ |
58 |
|
|
59 |
|
#define fndx(m) ((m)->otype==MIX_TEXT ? 2 : 0) |
60 |
|
#define tndx(m) ((m)->otype==MIX_TEXT ? 3 : 1) |
61 |
+ |
#define sndx(m) ((m)->otype==PAT_BTEXT ? 11 : \ |
62 |
+ |
(m)->otype==PAT_CTEXT ? 15 : 9) |
63 |
|
|
64 |
< |
extern char *libpath; /* library search path */ |
64 |
> |
typedef struct tline { |
65 |
> |
struct tline *next; /* pointer to next line */ |
66 |
> |
short *spc; /* character spacing */ |
67 |
> |
int width; /* total line width */ |
68 |
> |
/* followed by the string */ |
69 |
> |
} TLINE; |
70 |
|
|
71 |
< |
typedef unsigned char GLYPH; |
71 |
> |
#define TLSTR(l) ((char *)((l)+1)) |
72 |
|
|
73 |
< |
typedef struct font { |
74 |
< |
GLYPH *fg[256]; /* font glyphs */ |
75 |
< |
char *name; /* font file name */ |
76 |
< |
struct font *next; /* next font in list */ |
77 |
< |
} FONT; |
73 |
> |
typedef struct { |
74 |
> |
FVECT right, down; /* right and down unit vectors */ |
75 |
> |
FONT *f; /* our font */ |
76 |
> |
TLINE tl; /* line list */ |
77 |
> |
} TEXT; |
78 |
|
|
79 |
< |
extern GLYPH *getglyph(); |
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 |
|
|
70 |
– |
extern FONT *getfont(); |
84 |
|
|
85 |
< |
static FONT *fontlist = NULL; /* our font list */ |
86 |
< |
|
87 |
< |
|
88 |
< |
text(m, r) |
89 |
< |
register OBJREC *m; |
77 |
< |
RAY *r; |
85 |
> |
int |
86 |
> |
do_text( |
87 |
> |
OBJREC *m, |
88 |
> |
RAY *r |
89 |
> |
) |
90 |
|
{ |
91 |
< |
double v[3], y, x; |
80 |
< |
int col, lno; |
91 |
> |
FVECT v; |
92 |
|
int foreground; |
93 |
< |
GLYPH *g; |
83 |
< |
register double *ap; |
84 |
< |
|
85 |
< |
if (m->oargs.nsargs - tndx(m) < 1 || |
86 |
< |
m->oargs.nfargs != (m->otype == PAT_BTEXT ? 11 : |
87 |
< |
m->otype == PAT_CTEXT ? 15 : 9)) |
88 |
< |
objerror(m, USER, "bad # arguments"); |
89 |
< |
|
90 |
< |
/* first, discover position in text */ |
91 |
< |
ap = m->oargs.farg; |
93 |
> |
/* get transformed position */ |
94 |
|
if (r->rox != NULL) |
95 |
|
multp3(v, r->rop, r->rox->b.xfm); |
96 |
|
else |
97 |
|
VCOPY(v, r->rop); |
98 |
< |
v[0] -= ap[0]; |
99 |
< |
v[1] -= ap[1]; |
98 |
< |
v[2] -= ap[2]; |
99 |
< |
col = x = DOT(v, ap+3) / DOT(ap+3, ap+3); |
100 |
< |
lno = y = DOT(v, ap+6) / DOT(ap+6, ap+6); |
101 |
< |
x -= col; |
102 |
< |
y = (lno+1) - y; |
103 |
< |
/* get the font character, check it */ |
104 |
< |
if ((g = getglyph(m, lno, col)) == NULL) |
105 |
< |
foreground = 0; |
106 |
< |
else |
107 |
< |
foreground = inglyph(x, y, g); |
98 |
> |
/* check if we are within a text glyph */ |
99 |
> |
foreground = intext(v, m); |
100 |
|
/* modify */ |
101 |
|
if (m->otype == MIX_TEXT) { |
102 |
|
OBJECT omod; |
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 |
|
} |
110 |
< |
raymixture(r, omod, OVOID, 1.0); |
110 |
> |
if (rayshade(r, omod)) { |
111 |
> |
if (m->omod != OVOID) |
112 |
> |
objerror(m, USER, "inappropriate modifier"); |
113 |
> |
return(1); |
114 |
> |
} |
115 |
|
} else if (m->otype == PAT_BTEXT) { |
116 |
< |
if (foreground) |
117 |
< |
scalecolor(r->pcol, ap[9]); |
118 |
< |
else |
119 |
< |
scalecolor(r->pcol, ap[10]); |
116 |
> |
if (foreground) { |
117 |
> |
scalescolor(r->pcol, m->oargs.farg[9]); |
118 |
> |
} else { |
119 |
> |
scalescolor(r->pcol, m->oargs.farg[10]); |
120 |
> |
} |
121 |
|
} else { /* PAT_CTEXT */ |
122 |
< |
COLOR cval; |
122 |
> |
SCOLOR scval; |
123 |
|
if (foreground) |
124 |
< |
setcolor(cval, ap[9], ap[10], ap[11]); |
124 |
> |
setscolor(scval, m->oargs.farg[9], |
125 |
> |
m->oargs.farg[10], |
126 |
> |
m->oargs.farg[11]); |
127 |
|
else |
128 |
< |
setcolor(cval, ap[12], ap[13], ap[14]); |
129 |
< |
multcolor(r->pcol, cval); |
128 |
> |
setscolor(scval, m->oargs.farg[12], |
129 |
> |
m->oargs.farg[13], |
130 |
> |
m->oargs.farg[14]); |
131 |
> |
smultscolor(r->pcol, scval); |
132 |
|
} |
133 |
+ |
return(0); |
134 |
|
} |
135 |
|
|
136 |
|
|
137 |
< |
GLYPH * |
138 |
< |
getglyph(tm, lno, col) /* get a glyph from a text description */ |
139 |
< |
register OBJREC *tm; |
140 |
< |
int lno; |
139 |
< |
int col; |
137 |
> |
static TLINE * |
138 |
> |
tlalloc( /* allocate and assign text line */ |
139 |
> |
char *s |
140 |
> |
) |
141 |
|
{ |
142 |
< |
extern char *strcpy(), *fgets(); |
143 |
< |
FILE *fp; |
143 |
< |
char linbuf[512]; |
144 |
< |
register int i; |
145 |
< |
register char **txt; |
146 |
< |
register char *s; |
142 |
> |
int siz; |
143 |
> |
TLINE *tl; |
144 |
|
|
145 |
< |
if (lno < 0 || col < 0) |
146 |
< |
return(NULL); |
147 |
< |
if (tm->os == NULL) { |
148 |
< |
txt = (char **)malloc(2*sizeof(char **)); |
149 |
< |
if (txt == NULL) |
150 |
< |
goto memerr; |
151 |
< |
if (tm->oargs.nsargs - tndx(tm) > 1) { /* single line */ |
155 |
< |
s = linbuf; |
156 |
< |
for (i = tndx(tm)+1; i < tm->oargs.nsargs; i++) { |
157 |
< |
strcpy(s, tm->oargs.sarg[i]); |
158 |
< |
s += strlen(s); |
159 |
< |
*s++ = ' '; |
160 |
< |
} |
161 |
< |
*--s = '\0'; |
162 |
< |
txt[0] = savqstr(linbuf); |
163 |
< |
txt[1] = NULL; |
164 |
< |
} else { /* text file */ |
165 |
< |
if ((s = getpath(tm->oargs.sarg[tndx(tm)], |
166 |
< |
libpath, R_OK)) == NULL) { |
167 |
< |
sprintf(errmsg, "cannot find text file \"%s\"", |
168 |
< |
tm->oargs.sarg[tndx(tm)]); |
169 |
< |
error(USER, errmsg); |
170 |
< |
} |
171 |
< |
if ((fp = fopen(s, "r")) == NULL) { |
172 |
< |
sprintf(errmsg, "cannot open text file \"%s\"", |
173 |
< |
s); |
174 |
< |
error(SYSTEM, errmsg); |
175 |
< |
} |
176 |
< |
for (i=0; fgets(linbuf,sizeof(linbuf),fp)!=NULL; i++) { |
177 |
< |
s = linbuf + strlen(linbuf) - 1; |
178 |
< |
if (*s == '\n') |
179 |
< |
*s = '\0'; |
180 |
< |
txt=(char **)realloc(txt,(i+2)*sizeof(char **)); |
181 |
< |
if (txt == NULL) |
182 |
< |
goto memerr; |
183 |
< |
txt[i] = savqstr(linbuf); |
184 |
< |
} |
185 |
< |
txt[i] = NULL; |
186 |
< |
fclose(fp); |
187 |
< |
} |
188 |
< |
tm->os = (char *)txt; |
189 |
< |
} |
190 |
< |
txt = (char **)tm->os; |
191 |
< |
for (i = 0; i < lno; i++) |
192 |
< |
if (txt[i] == NULL) |
193 |
< |
break; |
194 |
< |
if ((s = txt[i]) == NULL || col >= strlen(s)) |
195 |
< |
return(NULL); |
196 |
< |
else |
197 |
< |
return(getfont(tm->oargs.sarg[fndx(tm)])->fg[s[col]]); |
198 |
< |
memerr: |
199 |
< |
error(SYSTEM, "out of memory in getglyph"); |
145 |
> |
siz = strlen(s) + 1; |
146 |
> |
if ((tl=(TLINE *)malloc(sizeof(TLINE)+siz)) == NULL || |
147 |
> |
(tl->spc=(short *)malloc(siz*sizeof(short))) == NULL) |
148 |
> |
error(SYSTEM, "out of memory in tlalloc"); |
149 |
> |
tl->next = NULL; |
150 |
> |
strcpy(TLSTR(tl), s); |
151 |
> |
return(tl); |
152 |
|
} |
153 |
|
|
154 |
|
|
155 |
< |
FONT * |
156 |
< |
getfont(fname) /* return font fname */ |
157 |
< |
char *fname; |
155 |
> |
static TEXT * |
156 |
> |
gettext( /* get text structure for material */ |
157 |
> |
OBJREC *tm |
158 |
> |
) |
159 |
|
{ |
160 |
+ |
#define R (tm->oargs.farg+3) |
161 |
+ |
#define D (tm->oargs.farg+6) |
162 |
+ |
FVECT DxR; |
163 |
+ |
double d; |
164 |
|
FILE *fp; |
165 |
< |
char *pathname, *err; |
166 |
< |
int gn, ngv, gv; |
167 |
< |
register GLYPH *g; |
168 |
< |
register FONT *f; |
165 |
> |
char linbuf[512]; |
166 |
> |
TEXT *t; |
167 |
> |
int i; |
168 |
> |
TLINE *tlp; |
169 |
> |
char *s; |
170 |
|
|
171 |
< |
for (f = fontlist; f != NULL; f = f->next) |
172 |
< |
if (!strcmp(f->name, fname)) |
173 |
< |
return(f); |
174 |
< |
/* load the font file */ |
175 |
< |
if ((pathname = getpath(fname, libpath, R_OK)) == NULL) { |
176 |
< |
sprintf(errmsg, "cannot find font file \"%s\"", fname); |
177 |
< |
error(USER, errmsg); |
178 |
< |
} |
179 |
< |
f = (FONT *)calloc(1, sizeof(FONT)); |
180 |
< |
if (f == NULL) |
181 |
< |
goto memerr; |
182 |
< |
f->name = savestr(fname); |
183 |
< |
if ((fp = fopen(pathname, "r")) == NULL) { |
184 |
< |
sprintf(errmsg, "cannot open font file \"%s\"", |
185 |
< |
pathname); |
186 |
< |
error(SYSTEM, errmsg); |
187 |
< |
} |
188 |
< |
while (fscanf(fp, "%d", &gn) == 1) { /* get each glyph */ |
189 |
< |
if (gn < 0 || gn > 255) { |
190 |
< |
err = "illegal"; |
191 |
< |
goto fonterr; |
171 |
> |
if ((t = (TEXT *)tm->os) != NULL) |
172 |
> |
return(t); |
173 |
> |
/* check arguments */ |
174 |
> |
if (tm->oargs.nsargs - tndx(tm) < 1 || tm->oargs.nfargs < sndx(tm)) |
175 |
> |
objerror(tm, USER, "bad # arguments"); |
176 |
> |
if ((t = (TEXT *)malloc(sizeof(TEXT))) == NULL) |
177 |
> |
error(SYSTEM, "out of memory in gettext"); |
178 |
> |
/* compute vectors */ |
179 |
> |
fcross(DxR, D, R); |
180 |
> |
fcross(t->right, DxR, D); |
181 |
> |
d = DOT(t->right,t->right); |
182 |
> |
if (d <= FTINY*FTINY*FTINY*FTINY) |
183 |
> |
objerror(tm, USER, "illegal motion vector"); |
184 |
> |
d = DOT(D,D)/d; |
185 |
> |
for (i = 0; i < 3; i++) |
186 |
> |
t->right[i] *= d; |
187 |
> |
fcross(t->down, R, DxR); |
188 |
> |
d = DOT(R,R)/DOT(t->down,t->down); |
189 |
> |
for (i = 0; i < 3; i++) |
190 |
> |
t->down[i] *= d; |
191 |
> |
/* get text */ |
192 |
> |
tlp = &t->tl; |
193 |
> |
if (tm->oargs.nsargs - tndx(tm) > 1) { /* single line */ |
194 |
> |
s = linbuf; |
195 |
> |
for (i = tndx(tm)+1; i < tm->oargs.nsargs; i++) { |
196 |
> |
strcpy(s, tm->oargs.sarg[i]); |
197 |
> |
s += strlen(s); |
198 |
> |
*s++ = ' '; |
199 |
|
} |
200 |
< |
if (f->fg[gn] != NULL) { |
201 |
< |
err = "duplicate"; |
202 |
< |
goto fonterr; |
200 |
> |
*--s = '\0'; |
201 |
> |
tlp->next = tlalloc(linbuf); |
202 |
> |
tlp = tlp->next; |
203 |
> |
} else { /* text file */ |
204 |
> |
if ((s = getpath(tm->oargs.sarg[tndx(tm)], |
205 |
> |
getrlibpath(), R_OK)) == NULL) { |
206 |
> |
sprintf(errmsg, "cannot find text file \"%s\"", |
207 |
> |
tm->oargs.sarg[tndx(tm)]); |
208 |
> |
error(SYSTEM, errmsg); |
209 |
|
} |
210 |
< |
if (fscanf(fp, "%d", &ngv) != 1 || |
211 |
< |
ngv < 0 || ngv > 255) { |
212 |
< |
err = "bad # vertices for"; |
242 |
< |
goto fonterr; |
210 |
> |
if ((fp = fopen(s, "r")) == NULL) { |
211 |
> |
sprintf(errmsg, "cannot open text file \"%s\"", s); |
212 |
> |
error(SYSTEM, errmsg); |
213 |
|
} |
214 |
< |
g = (GLYPH *)malloc((2*ngv+1)*sizeof(GLYPH)); |
215 |
< |
if (g == NULL) |
216 |
< |
goto memerr; |
217 |
< |
f->fg[gn] = g; |
218 |
< |
*g++ = ngv; |
219 |
< |
ngv *= 2; |
250 |
< |
while (ngv--) { |
251 |
< |
if (fscanf(fp, "%d", &gv) != 1 || |
252 |
< |
gv < 0 || gv > 255) { |
253 |
< |
err = "bad vertex for"; |
254 |
< |
goto fonterr; |
255 |
< |
} |
256 |
< |
*g++ = gv; |
214 |
> |
while (fgets(linbuf, sizeof(linbuf), fp) != NULL) { |
215 |
> |
s = linbuf + strlen(linbuf) - 1; |
216 |
> |
if (*s == '\n') |
217 |
> |
*s = '\0'; |
218 |
> |
tlp->next = tlalloc(linbuf); |
219 |
> |
tlp = tlp->next; |
220 |
|
} |
221 |
+ |
fclose(fp); |
222 |
|
} |
223 |
< |
fclose(fp); |
224 |
< |
f->next = fontlist; |
225 |
< |
return(fontlist = f); |
226 |
< |
fonterr: |
227 |
< |
sprintf(errmsg, "%s character (%d) in font file \"%s\"", |
228 |
< |
err, gn, pathname); |
229 |
< |
error(USER, errmsg); |
230 |
< |
memerr: |
231 |
< |
error(SYSTEM, "out of memory in fontglyph"); |
223 |
> |
tlp->next = NULL; |
224 |
> |
/* get the font */ |
225 |
> |
t->f = getfont(tm->oargs.sarg[fndx(tm)]); |
226 |
> |
if (!t->f) |
227 |
> |
objerror(tm, USER, "font load error"); |
228 |
> |
/* compute character spacing */ |
229 |
> |
i = sndx(tm); |
230 |
> |
d = i < tm->oargs.nfargs ? tm->oargs.farg[i] : 0.0; |
231 |
> |
i = d * 255.0; |
232 |
> |
t->tl.width = 0; |
233 |
> |
for (tlp = t->tl.next; tlp != NULL; tlp = tlp->next) { |
234 |
> |
if (i < 0) |
235 |
> |
tlp->width = squeeztext(tlp->spc, TLSTR(tlp), t->f, -i); |
236 |
> |
else if (i > 0) |
237 |
> |
tlp->width = proptext(tlp->spc, TLSTR(tlp), t->f, i, 3); |
238 |
> |
else |
239 |
> |
tlp->width = uniftext(tlp->spc, TLSTR(tlp), t->f); |
240 |
> |
if (tlp->width > t->tl.width) |
241 |
> |
t->tl.width = tlp->width; |
242 |
> |
} |
243 |
> |
/* we're done */ |
244 |
> |
tm->os = (char *)t; |
245 |
> |
return(t); |
246 |
> |
#undef R |
247 |
> |
#undef D |
248 |
|
} |
249 |
|
|
250 |
|
|
251 |
< |
inglyph(x, y, gl) /* (x,y) within font glyph gl? */ |
252 |
< |
double x, y; |
253 |
< |
GLYPH *gl; |
251 |
> |
void |
252 |
> |
freetext( /* free text structures associated with m */ |
253 |
> |
OBJREC *m |
254 |
> |
) |
255 |
|
{ |
256 |
+ |
TEXT *tp; |
257 |
+ |
TLINE *tlp; |
258 |
+ |
|
259 |
+ |
tp = (TEXT *)m->os; |
260 |
+ |
if (tp == NULL) |
261 |
+ |
return; |
262 |
+ |
while ((tlp = tp->tl.next) != NULL) { |
263 |
+ |
tp->tl.next = tlp->next; |
264 |
+ |
free((void *)tlp->spc); |
265 |
+ |
free((void *)tlp); |
266 |
+ |
} |
267 |
+ |
freefont(tp->f); /* release font reference */ |
268 |
+ |
free((void *)tp); |
269 |
+ |
m->os = NULL; |
270 |
+ |
} |
271 |
+ |
|
272 |
+ |
|
273 |
+ |
static int |
274 |
+ |
intext( /* check to see if p is in text glyph */ |
275 |
+ |
FVECT p, |
276 |
+ |
OBJREC *m |
277 |
+ |
) |
278 |
+ |
{ |
279 |
+ |
TEXT *tp; |
280 |
+ |
TLINE *tlp; |
281 |
+ |
FVECT v; |
282 |
+ |
double y, x; |
283 |
+ |
int i, h; |
284 |
+ |
/* first, compute position in text */ |
285 |
+ |
tp = gettext(m); |
286 |
+ |
v[0] = p[0] - m->oargs.farg[0]; |
287 |
+ |
v[1] = p[1] - m->oargs.farg[1]; |
288 |
+ |
v[2] = p[2] - m->oargs.farg[2]; |
289 |
+ |
x = DOT(v, tp->right); |
290 |
+ |
i = sndx(m); |
291 |
+ |
if (i < m->oargs.nfargs) |
292 |
+ |
x *= tp->f->mwidth + 255.*fabs(m->oargs.farg[i]); |
293 |
+ |
else |
294 |
+ |
x *= 255.; |
295 |
+ |
h = x; |
296 |
+ |
i = y = DOT(v, tp->down); |
297 |
+ |
if (x < 0.0 || y < 0.0) |
298 |
+ |
return(0); |
299 |
+ |
x -= (double)h; |
300 |
+ |
y = ((i+1) - y)*255.; |
301 |
+ |
/* find the line position */ |
302 |
+ |
for (tlp = tp->tl.next; tlp != NULL; tlp = tlp->next) |
303 |
+ |
if (--i < 0) |
304 |
+ |
break; |
305 |
+ |
if (tlp == NULL || h >= tlp->width) |
306 |
+ |
return(0); |
307 |
+ |
for (i = 0; (h -= tlp->spc[i]) >= 0; i++) |
308 |
+ |
if (h < 255 && inglyph(h+x, y, |
309 |
+ |
tp->f->fg[TLSTR(tlp)[i]&0xff])) |
310 |
+ |
return(1); |
311 |
+ |
return(0); |
312 |
+ |
} |
313 |
+ |
|
314 |
+ |
|
315 |
+ |
static int |
316 |
+ |
inglyph( /* (x,y) within font glyph gl? */ |
317 |
+ |
double x, /* real coordinates in range [0,255) */ |
318 |
+ |
double y, |
319 |
+ |
GLYPH *gl |
320 |
+ |
) |
321 |
+ |
{ |
322 |
|
int n, ncross; |
323 |
|
int xlb, ylb; |
324 |
< |
register GLYPH *p0, *p1; |
324 |
> |
int tv; |
325 |
> |
GORD *p0, *p1; |
326 |
|
|
327 |
< |
if (x < 0.0 || y < 0.0) |
327 |
> |
if (gl == NULL) |
328 |
|
return(0); |
329 |
< |
x *= 256.0; /* get glyph coordinates */ |
330 |
< |
y *= 256.0; |
331 |
< |
xlb = x + 0.5; |
332 |
< |
ylb = y + 0.5; |
333 |
< |
n = *gl++; /* get # of vertices */ |
334 |
< |
p0 = gl + 2*(n-1); /* connect last to first */ |
335 |
< |
p1 = gl; |
329 |
> |
xlb = x; |
330 |
> |
ylb = y; |
331 |
> |
if (gl->left > xlb || gl->right <= xlb || /* check extent */ |
332 |
> |
gl->bottom > ylb || gl->top <= ylb) |
333 |
> |
return(0); |
334 |
> |
xlb = xlb<<1 | 1; /* add 1/2 to test points... */ |
335 |
> |
ylb = ylb<<1 | 1; /* ...so no equal comparisons */ |
336 |
> |
n = gl->nverts; /* get # of vertices */ |
337 |
> |
p0 = gvlist(gl) + 2*(n-1); /* connect last to first */ |
338 |
> |
p1 = gvlist(gl); |
339 |
|
ncross = 0; |
340 |
|
/* positive x axis cross test */ |
341 |
|
while (n--) { |
342 |
< |
if ((p0[1] > ylb) ^ (p1[1] > ylb)) |
343 |
< |
if (p0[0] > xlb && p1[0] > xlb) |
342 |
> |
if ((p0[1]<<1 > ylb) ^ (p1[1]<<1 > ylb)) { |
343 |
> |
tv = (p0[0]<<1 > xlb) | ((p1[0]<<1 > xlb) << 1); |
344 |
> |
if (tv == 03) |
345 |
|
ncross++; |
346 |
< |
else if (p0[0] > xlb || p1[0] > xlb) |
346 |
> |
else if (tv) |
347 |
|
ncross += (p1[1] > p0[1]) ^ |
348 |
|
((p0[1]-y)*(p1[0]-x) > |
349 |
|
(p0[0]-x)*(p1[1]-y)); |
350 |
+ |
} |
351 |
|
p0 = p1; |
352 |
|
p1 += 2; |
353 |
|
} |