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.6 by greg, Sat Nov 21 21:35:36 1992 UTC vs.
Revision 2.18 by schorsch, Fri Mar 26 21:29:19 2004 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 "standard.h"
8 > #include "copyright.h"
9  
10 + #include <stdlib.h>
11 +
12 + #include "rtio.h"
13 + #include "rterror.h"
14   #include "font.h"
15  
16   #define galloc(nv)      (GLYPH *)malloc(sizeof(GLYPH)+2*sizeof(GORD)*(nv))
17  
18  
19 < extern char  *libpath;                  /* list of library directories */
19 > int     retainfonts = 0;                /* retain loaded fonts? */
20  
20 extern char  *fgetword();
21
21   static FONT     *fontlist = NULL;       /* list of loaded fonts */
22  
23  
# Line 26 | Line 25 | FONT *
25   getfont(fname)                          /* return font fname */
26   char  *fname;
27   {
29        char  buf[16];
28          FILE  *fp;
29 <        char  *pathname, *err;
29 >        char  *pathname, *err = NULL;
30          unsigned  wsum, hsum, ngly;
31 <        int  gn, ngv;
34 <        register int  gv;
31 >        int  gn, ngv, gv;
32          register GLYPH  *g;
33          GORD  *gp;
34          register FONT  *f;
35  
36          for (f = fontlist; f != NULL; f = f->next)
37 <                if (!strcmp(f->name, fname))
37 >                if (!strcmp(f->name, fname)) {
38 >                        f->nref++;
39                          return(f);
40 +                }
41                                                  /* load the font file */
42 <        if ((pathname = getpath(fname, libpath, R_OK)) == NULL) {
42 >        if ((pathname = getpath(fname, getrlibpath(), R_OK)) == NULL) {
43                  sprintf(errmsg, "cannot find font file \"%s\"", fname);
44                  error(USER, errmsg);
45          }
# Line 48 | Line 47 | char  *fname;
47          if (f == NULL)
48                  goto memerr;
49          f->name = savestr(fname);
50 +        f->nref = 1;
51          if ((fp = fopen(pathname, "r")) == NULL) {
52                  sprintf(errmsg, "cannot open font file \"%s\"",
53                                  pathname);
54                  error(SYSTEM, errmsg);
55          }
56 <        wsum = hsum = ngly = 0;
57 <        while (fgetword(buf,sizeof(buf),fp) != NULL) {  /* get each glyph */
58 <                if (!isint(buf))
56 >        wsum = hsum = ngly = 0;                 /* get each glyph */
57 >        while ((ngv = fgetval(fp, 'i', (char *)&gn)) != EOF) {
58 >                if (ngv == 0)
59                          goto nonint;
60                gn = atoi(buf);
60                  if (gn < 1 || gn > 255) {
61                          err = "illegal";
62                          goto fonterr;
# Line 66 | Line 65 | char  *fname;
65                          err = "duplicate";
66                          goto fonterr;
67                  }
68 <                if (fgetword(buf,sizeof(buf),fp) == NULL || !isint(buf) ||
69 <                                (ngv = atoi(buf)) < 0 || ngv > 32000) {
68 >                if (fgetval(fp, 'i', (char *)&ngv) <= 0 ||
69 >                                ngv < 0 || ngv > 32000) {
70                          err = "bad # vertices for";
71                          goto fonterr;
72                  }
# Line 79 | Line 78 | char  *fname;
78                  ngv *= 2;
79                  gp = gvlist(g);
80                  while (ngv--) {
81 <                        if (fgetword(buf,sizeof(buf),fp) == NULL ||
82 <                                        !isint(buf) ||
84 <                                        (gv = atoi(buf)) < 0 || gv > 255) {
81 >                        if (fgetval(fp, 'i', (char *)&gv) <= 0 ||
82 >                                        gv < 0 || gv > 255) {
83                                  err = "bad vertex for";
84                                  goto fonterr;
85                          }
# Line 121 | Line 119 | fonterr:
119          error(USER, errmsg);
120   memerr:
121          error(SYSTEM, "out of memory in fontglyph");
122 +        return NULL; /* pro forma return */
123   }
124  
125  
126 < freefont(fname)                 /* free a font (free all if fname==NULL) */
127 < char  *fname;
126 > void
127 > freefont(fnt)                   /* release a font (free all if NULL) */
128 > FONT *fnt;
129   {
130          FONT  head;
131          register FONT  *fl, *f;
132          register int  i;
133 <
133 >                                        /* check reference count */
134 >        if (fnt != NULL && ((fnt->nref-- > 1) | retainfonts))
135 >                return;
136          head.next = fontlist;
137          fl = &head;
138          while ((f = fl->next) != NULL)
139 <                if (fname == NULL || !strcmp(fname, f->name)) {
139 >                if ((fnt == NULL) | (fnt == f)) {
140                          fl->next = f->next;
141                          for (i = 0; i < 256; i++)
142                                  if (f->fg[i] != NULL)
143 <                                        free((char *)f->fg[i]);
143 >                                        free((void *)f->fg[i]);
144                          freestr(f->name);
145 <                        free((char *)f);
145 >                        free((void *)f);
146                  } else
147                          fl = f;
148          fontlist = head.next;
# Line 160 | Line 162 | register FONT  *f;             /* font */
162                  if (f->fg[*tp++&0xff] == NULL)
163                          *sp++ = 0;
164                  else
165 <                        linelen += *sp++ = 256;
165 >                        linelen += *sp++ = 255;
166          return(linelen);
167   }
168  
# Line 175 | Line 177 | int  cis;                      /* intercharacter spacing */
177          int  linelen;
178          register GLYPH  *gp;
179  
180 +        linelen = 0;
181          gp = NULL;
182          while (*tp && (gp = f->fg[*tp++&0xff]) == NULL)
183                  *sp++ = 0;
184          cis /= 2;
185 <        linelen = *sp = cis;
185 >        *sp = cis;
186          while (gp != NULL) {
187                  if (gp->nverts) {               /* regular character */
188                          linelen += *sp++ += cis - gp->left;
# Line 207 | Line 210 | FONT  *f;                      /* font */
210   int  cis;                       /* target intercharacter spacing */
211   int  nsi;                       /* minimum number of spaces for indent */
212   {
213 <        register char  *end, *tab;
213 >        register char  *end, *tab = NULL;
214          GLYPH  *gp;
215          short  *nsp;
216          int  alen, len, width;
217                                          /* start by squeezing it */
218          squeeztext(sp, tp, f, cis);
219                                          /* now, realign spacing */
220 <        len = 0;
218 <        width = alen = *sp++;
220 >        width = *sp++;
221          while (*tp) {
222 +                len = alen = 0;
223                  nsp = sp;
224                  for (end = tp; *end; end = tab) {
225                          tab = end + 1;
# Line 240 | Line 243 | int  nsi;                      /* minimum number of spaces for indent */
243                          *sp++ += alen;
244                          len -= alen;
245                  }
243                len = 0;
244                alen = 0;
246                  tp = tab;
247          }
248          return(width);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines