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

Comparing ray/src/common/font.c (file contents):
Revision 2.11 by greg, Fri Jun 30 16:06:40 1995 UTC vs.
Revision 2.16 by schorsch, Sun Jul 27 22:12:01 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1992 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   * Polygonal font handling routines
6   */
7  
8 + #include "copyright.h"
9 +
10   #include "standard.h"
11  
12   #include "font.h"
# Line 15 | Line 14 | static char SCCSid[] = "$SunId$ LBL";
14   #define galloc(nv)      (GLYPH *)malloc(sizeof(GLYPH)+2*sizeof(GORD)*(nv))
15  
16  
17 < extern char  *getlibpath();
17 > int     retainfonts = 0;                /* retain loaded fonts? */
18  
19   static FONT     *fontlist = NULL;       /* list of loaded fonts */
20  
# Line 33 | Line 32 | char  *fname;
32          register FONT  *f;
33  
34          for (f = fontlist; f != NULL; f = f->next)
35 <                if (!strcmp(f->name, fname))
35 >                if (!strcmp(f->name, fname)) {
36 >                        f->nref++;
37                          return(f);
38 +                }
39                                                  /* load the font file */
40 <        if ((pathname = getpath(fname, getlibpath(), R_OK)) == NULL) {
40 >        if ((pathname = getpath(fname, getrlibpath(), R_OK)) == NULL) {
41                  sprintf(errmsg, "cannot find font file \"%s\"", fname);
42                  error(USER, errmsg);
43          }
# Line 44 | Line 45 | char  *fname;
45          if (f == NULL)
46                  goto memerr;
47          f->name = savestr(fname);
48 +        f->nref = 1;
49          if ((fp = fopen(pathname, "r")) == NULL) {
50                  sprintf(errmsg, "cannot open font file \"%s\"",
51                                  pathname);
52                  error(SYSTEM, errmsg);
53          }
54 <        wsum = hsum = ngly = 0;
55 <        while ((ngv = fgetval(fp, 'i', &gn)) != EOF) {  /* get each glyph */
54 >        wsum = hsum = ngly = 0;                 /* get each glyph */
55 >        while ((ngv = fgetval(fp, 'i', (char *)&gn)) != EOF) {
56                  if (ngv == 0)
57                          goto nonint;
58                  if (gn < 1 || gn > 255) {
# Line 61 | Line 63 | char  *fname;
63                          err = "duplicate";
64                          goto fonterr;
65                  }
66 <                if (fgetval(fp, 'i', &ngv) <= 0 || ngv < 0 || ngv > 32000) {
66 >                if (fgetval(fp, 'i', (char *)&ngv) <= 0 ||
67 >                                ngv < 0 || ngv > 32000) {
68                          err = "bad # vertices for";
69                          goto fonterr;
70                  }
# Line 73 | Line 76 | char  *fname;
76                  ngv *= 2;
77                  gp = gvlist(g);
78                  while (ngv--) {
79 <                        if (fgetval(fp, 'i', &gv) <= 0 || gv < 0 || gv > 255) {
79 >                        if (fgetval(fp, 'i', (char *)&gv) <= 0 ||
80 >                                        gv < 0 || gv > 255) {
81                                  err = "bad vertex for";
82                                  goto fonterr;
83                          }
# Line 113 | Line 117 | fonterr:
117          error(USER, errmsg);
118   memerr:
119          error(SYSTEM, "out of memory in fontglyph");
120 +        return NULL; /* pro forma return */
121   }
122  
123  
124 < freefont(fname)                 /* free a font (free all if fname==NULL) */
125 < char  *fname;
124 > void
125 > freefont(fnt)                   /* release a font (free all if NULL) */
126 > FONT *fnt;
127   {
128          FONT  head;
129          register FONT  *fl, *f;
130          register int  i;
131 <
131 >                                        /* check reference count */
132 >        if (fnt != NULL && ((fnt->nref-- > 1) | retainfonts))
133 >                return;
134          head.next = fontlist;
135          fl = &head;
136          while ((f = fl->next) != NULL)
137 <                if (fname == NULL || !strcmp(fname, f->name)) {
137 >                if ((fnt == NULL) | (fnt == f)) {
138                          fl->next = f->next;
139                          for (i = 0; i < 256; i++)
140                                  if (f->fg[i] != NULL)
141 <                                        free((char *)f->fg[i]);
141 >                                        free((void *)f->fg[i]);
142                          freestr(f->name);
143 <                        free((char *)f);
143 >                        free((void *)f);
144                  } else
145                          fl = f;
146          fontlist = head.next;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines