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.14 by greg, Tue May 13 17:58:32 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 116 | Line 120 | memerr:
120   }
121  
122  
123 < freefont(fname)                 /* free a font (free all if fname==NULL) */
124 < char  *fname;
123 > void
124 > freefont(fnt)                   /* release a font (free all if NULL) */
125 > FONT *fnt;
126   {
127          FONT  head;
128          register FONT  *fl, *f;
129          register int  i;
130 <
130 >                                        /* check reference count */
131 >        if (fnt != NULL && (fnt->nref-- > 1 | retainfonts))
132 >                return;
133          head.next = fontlist;
134          fl = &head;
135          while ((f = fl->next) != NULL)
136 <                if (fname == NULL || !strcmp(fname, f->name)) {
136 >                if ((fnt == NULL | fnt == f)) {
137                          fl->next = f->next;
138                          for (i = 0; i < 256; i++)
139                                  if (f->fg[i] != NULL)
140 <                                        free((char *)f->fg[i]);
140 >                                        free((void *)f->fg[i]);
141                          freestr(f->name);
142 <                        free((char *)f);
142 >                        free((void *)f);
143                  } else
144                          fl = f;
145          fontlist = head.next;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines