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 1.9 by greg, Wed Aug 7 08:37:27 1991 UTC vs.
Revision 2.3 by greg, Tue Jun 16 13:24: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 78 | Line 70 | typedef struct {
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;
85   {
86 <        double  v[3];
86 >        FVECT  v;
87          int  foreground;
88                                  /* get transformed position */
89          if (r->rox != NULL)
# Line 250 | Line 240 | OBJREC  *m;
240   {
241          register TEXT  *tp;
242          register TLINE  *tlp;
243 <        double  v[3], y, x;
243 >        FVECT  v;
244 >        double  y, x;
245          int  col;
246          register int  lno;
247                                  /* first, compute position in text */
# Line 270 | Line 261 | OBJREC  *m;
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  
277 FONT *
278 getfont(fname)                          /* return font fname */
279 char  *fname;
280 {
281        char  buf[16];
282        FILE  *fp;
283        char  *pathname, *err;
284        int  gn, ngv, gv;
285        register GLYPH  *g;
286        register FONT  *f;
287
288        for (f = fontlist; f != NULL; f = f->next)
289                if (!strcmp(f->name, fname))
290                        return(f);
291                                                /* load the font file */
292        if ((pathname = getpath(fname, libpath, R_OK)) == NULL) {
293                sprintf(errmsg, "cannot find font file \"%s\"", fname);
294                error(USER, errmsg);
295        }
296        f = (FONT *)calloc(1, sizeof(FONT));
297        if (f == NULL)
298                goto memerr;
299        f->name = savestr(fname);
300        if ((fp = fopen(pathname, "r")) == NULL) {
301                sprintf(errmsg, "cannot open font file \"%s\"",
302                                pathname);
303                error(SYSTEM, errmsg);
304        }
305        while (fgetword(buf,sizeof(buf),fp) != NULL) {  /* get each glyph */
306                if (!isint(buf))
307                        goto nonint;
308                gn = atoi(buf);
309                if (gn < 0 || gn > 255) {
310                        err = "illegal";
311                        goto fonterr;
312                }
313                if (f->fg[gn] != NULL) {
314                        err = "duplicate";
315                        goto fonterr;
316                }
317                if (fgetword(buf,sizeof(buf),fp) == NULL || !isint(buf) ||
318                                (ngv = atoi(buf)) < 0 || ngv > 255) {
319                        err = "bad # vertices for";
320                        goto fonterr;
321                }
322                g = (GLYPH *)malloc((2*ngv+1)*sizeof(GLYPH));
323                if (g == NULL)
324                        goto memerr;
325                f->fg[gn] = g;
326                *g++ = ngv;
327                ngv *= 2;
328                while (ngv--) {
329                        if (fgetword(buf,sizeof(buf),fp) == NULL ||
330                                        !isint(buf) ||
331                                        (gv = atoi(buf)) < 0 || gv > 255) {
332                                err = "bad vertex for";
333                                goto fonterr;
334                        }
335                        *g++ = gv;
336                }
337        }
338        fclose(fp);
339        f->next = fontlist;
340        return(fontlist = f);
341 nonint:
342        sprintf(errmsg, "non-integer in font file \"%s\"", pathname);
343        error(USER, errmsg);
344 fonterr:
345        sprintf(errmsg, "%s character (%d) in font file \"%s\"",
346                        err, gn, pathname);
347        error(USER, errmsg);
348 memerr:
349        error(SYSTEM, "out of memory in fontglyph");
350 }
351
352
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);
# Line 364 | Line 279 | GLYPH  *gl;
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--) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines