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.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;
83   {
84 <        double  v[3];
84 >        FVECT  v;
85          int  foreground;
86                                  /* get transformed position */
87          if (r->rox != NULL)
# Line 250 | Line 238 | OBJREC  *m;
238   {
239          register TEXT  *tp;
240          register TLINE  *tlp;
241 <        double  v[3], y, x;
241 >        FVECT  v;
242 >        double  y, x;
243          int  col;
244          register int  lno;
245                                  /* first, compute position in text */
# Line 270 | 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  
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
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 364 | 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