| 14 |
|
|
| 15 |
|
#include "otypes.h" |
| 16 |
|
|
| 17 |
+ |
#include "font.h" |
| 18 |
+ |
|
| 19 |
|
/* |
| 20 |
|
* A text pattern is specified as the text (a file or line), |
| 21 |
|
* the upper left anchor point, the right motion vector, the down |
| 57 |
|
#define fndx(m) ((m)->otype==MIX_TEXT ? 2 : 0) |
| 58 |
|
#define tndx(m) ((m)->otype==MIX_TEXT ? 3 : 1) |
| 59 |
|
|
| 58 |
– |
extern char *libpath; /* library search path */ |
| 59 |
– |
|
| 60 |
– |
typedef unsigned char GLYPH; |
| 61 |
– |
|
| 62 |
– |
typedef struct font { |
| 63 |
– |
GLYPH *fg[256]; /* font glyphs */ |
| 64 |
– |
char *name; /* font file name */ |
| 65 |
– |
struct font *next; /* next font in list */ |
| 66 |
– |
} FONT; |
| 67 |
– |
|
| 60 |
|
typedef struct tline { |
| 61 |
|
struct tline *next; /* pointer to next line */ |
| 62 |
|
/* followed by the string */ |
| 70 |
|
TLINE tl; /* line list */ |
| 71 |
|
} TEXT; |
| 72 |
|
|
| 73 |
+ |
extern char *libpath; |
| 74 |
+ |
|
| 75 |
|
extern char *fgetword(); |
| 76 |
|
|
| 77 |
|
TEXT *gettext(); |
| 78 |
|
|
| 79 |
|
TLINE *tlalloc(); |
| 80 |
|
|
| 87 |
– |
FONT *getfont(); |
| 81 |
|
|
| 89 |
– |
static FONT *fontlist = NULL; /* our font list */ |
| 90 |
– |
|
| 91 |
– |
|
| 82 |
|
text(m, r) |
| 83 |
|
register OBJREC *m; |
| 84 |
|
RAY *r; |
| 261 |
|
break; |
| 262 |
|
if (tlp == NULL || col >= strlen(TLSTR(tlp))) |
| 263 |
|
return(0); |
| 264 |
< |
return(inglyph(x, y, tp->f->fg[TLSTR(tlp)[col]])); |
| 264 |
> |
return(inglyph(x, y, tp->f->fg[TLSTR(tlp)[col]&0xff])); |
| 265 |
|
} |
| 266 |
|
|
| 267 |
|
|
| 278 |
– |
FONT * |
| 279 |
– |
getfont(fname) /* return font fname */ |
| 280 |
– |
char *fname; |
| 281 |
– |
{ |
| 282 |
– |
char buf[16]; |
| 283 |
– |
FILE *fp; |
| 284 |
– |
char *pathname, *err; |
| 285 |
– |
int gn, ngv, gv; |
| 286 |
– |
register GLYPH *g; |
| 287 |
– |
register FONT *f; |
| 288 |
– |
|
| 289 |
– |
for (f = fontlist; f != NULL; f = f->next) |
| 290 |
– |
if (!strcmp(f->name, fname)) |
| 291 |
– |
return(f); |
| 292 |
– |
/* load the font file */ |
| 293 |
– |
if ((pathname = getpath(fname, libpath, R_OK)) == NULL) { |
| 294 |
– |
sprintf(errmsg, "cannot find font file \"%s\"", fname); |
| 295 |
– |
error(USER, errmsg); |
| 296 |
– |
} |
| 297 |
– |
f = (FONT *)calloc(1, sizeof(FONT)); |
| 298 |
– |
if (f == NULL) |
| 299 |
– |
goto memerr; |
| 300 |
– |
f->name = savestr(fname); |
| 301 |
– |
if ((fp = fopen(pathname, "r")) == NULL) { |
| 302 |
– |
sprintf(errmsg, "cannot open font file \"%s\"", |
| 303 |
– |
pathname); |
| 304 |
– |
error(SYSTEM, errmsg); |
| 305 |
– |
} |
| 306 |
– |
while (fgetword(buf,sizeof(buf),fp) != NULL) { /* get each glyph */ |
| 307 |
– |
if (!isint(buf)) |
| 308 |
– |
goto nonint; |
| 309 |
– |
gn = atoi(buf); |
| 310 |
– |
if (gn < 0 || gn > 255) { |
| 311 |
– |
err = "illegal"; |
| 312 |
– |
goto fonterr; |
| 313 |
– |
} |
| 314 |
– |
if (f->fg[gn] != NULL) { |
| 315 |
– |
err = "duplicate"; |
| 316 |
– |
goto fonterr; |
| 317 |
– |
} |
| 318 |
– |
if (fgetword(buf,sizeof(buf),fp) == NULL || !isint(buf) || |
| 319 |
– |
(ngv = atoi(buf)) < 0 || ngv > 255) { |
| 320 |
– |
err = "bad # vertices for"; |
| 321 |
– |
goto fonterr; |
| 322 |
– |
} |
| 323 |
– |
g = (GLYPH *)malloc((2*ngv+1)*sizeof(GLYPH)); |
| 324 |
– |
if (g == NULL) |
| 325 |
– |
goto memerr; |
| 326 |
– |
f->fg[gn] = g; |
| 327 |
– |
*g++ = ngv; |
| 328 |
– |
ngv *= 2; |
| 329 |
– |
while (ngv--) { |
| 330 |
– |
if (fgetword(buf,sizeof(buf),fp) == NULL || |
| 331 |
– |
!isint(buf) || |
| 332 |
– |
(gv = atoi(buf)) < 0 || gv > 255) { |
| 333 |
– |
err = "bad vertex for"; |
| 334 |
– |
goto fonterr; |
| 335 |
– |
} |
| 336 |
– |
*g++ = gv; |
| 337 |
– |
} |
| 338 |
– |
} |
| 339 |
– |
fclose(fp); |
| 340 |
– |
f->next = fontlist; |
| 341 |
– |
return(fontlist = f); |
| 342 |
– |
nonint: |
| 343 |
– |
sprintf(errmsg, "non-integer in font file \"%s\"", pathname); |
| 344 |
– |
error(USER, errmsg); |
| 345 |
– |
fonterr: |
| 346 |
– |
sprintf(errmsg, "%s character (%d) in font file \"%s\"", |
| 347 |
– |
err, gn, pathname); |
| 348 |
– |
error(USER, errmsg); |
| 349 |
– |
memerr: |
| 350 |
– |
error(SYSTEM, "out of memory in fontglyph"); |
| 351 |
– |
} |
| 352 |
– |
|
| 353 |
– |
|
| 268 |
|
inglyph(x, y, gl) /* (x,y) within font glyph gl? */ |
| 269 |
|
double x, y; |
| 270 |
< |
GLYPH *gl; |
| 270 |
> |
register GLYPH *gl; |
| 271 |
|
{ |
| 272 |
|
int n, ncross; |
| 273 |
|
int xlb, ylb; |
| 274 |
< |
register GLYPH *p0, *p1; |
| 274 |
> |
register GORD *p0, *p1; |
| 275 |
|
|
| 276 |
|
if (gl == NULL) |
| 277 |
|
return(0); |
| 279 |
|
y *= 256.0; |
| 280 |
|
xlb = x + 0.5; |
| 281 |
|
ylb = y + 0.5; |
| 282 |
< |
n = *gl++; /* get # of vertices */ |
| 283 |
< |
p0 = gl + 2*(n-1); /* connect last to first */ |
| 284 |
< |
p1 = gl; |
| 282 |
> |
if (gl->left > xlb || gl->right <= xlb || |
| 283 |
> |
gl->bottom > ylb || gl->top <= ylb) |
| 284 |
> |
return(0); /* outside extent */ |
| 285 |
> |
n = gl->nverts; /* get # of vertices */ |
| 286 |
> |
p0 = gvlist(gl) + 2*(n-1); /* connect last to first */ |
| 287 |
> |
p1 = gvlist(gl); |
| 288 |
|
ncross = 0; |
| 289 |
|
/* positive x axis cross test */ |
| 290 |
|
while (n--) { |