ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/text.c
(Generate patch)

Comparing ray/src/rt/text.c (file contents):
Revision 2.1 by greg, Tue Nov 12 17:10:02 1991 UTC vs.
Revision 2.2 by greg, Sat Jun 6 07:40:23 1992 UTC

# Line 14 | Line 14 | static char SCCSid[] = "$SunId$ LBL";
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
# Line 55 | Line 57 | static char SCCSid[] = "$SunId$ LBL";
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 */
# Line 84 | Line 76 | TEXT  *gettext();
76  
77   TLINE  *tlalloc();
78  
87 FONT  *getfont();
79  
89 static FONT  *fontlist = NULL;          /* our font list */
90
91
80   text(m, r)
81   register OBJREC  *m;
82   RAY  *r;
# Line 271 | Line 259 | OBJREC  *m;
259                          break;
260          if (tlp == NULL || col >= strlen(TLSTR(tlp)))
261                  return(0);
262 <        return(inglyph(x, y, tp->f->fg[TLSTR(tlp)[col]]));
262 >        return(inglyph(x, y, tp->f->fg[TLSTR(tlp)[col]&0xff]));
263   }
264  
265  
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
266   inglyph(x, y, gl)               /* (x,y) within font glyph gl? */
267   double  x, y;
268   GLYPH  *gl;
269   {
270          int  n, ncross;
271          int  xlb, ylb;
272 <        register GLYPH  *p0, *p1;
272 >        register GORD  *p0, *p1;
273  
274          if (gl == NULL)
275                  return(0);
# Line 365 | Line 277 | GLYPH  *gl;
277          y *= 256.0;
278          xlb = x + 0.5;
279          ylb = y + 0.5;
280 <        n = *gl++;                      /* get # of vertices */
281 <        p0 = gl + 2*(n-1);              /* connect last to first */
282 <        p1 = gl;
280 >        n = gl->nverts;                 /* get # of vertices */
281 >        p0 = gvlist(gl) + 2*(n-1);      /* connect last to first */
282 >        p1 = gvlist(gl);
283          ncross = 0;
284                                          /* positive x axis cross test */
285          while (n--) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines