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.17 by schorsch, Fri Nov 14 17:22:06 2003 UTC vs.
Revision 2.24 by greg, Sat Nov 20 22:39:01 2021 UTC

# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
7  
8   #include "copyright.h"
9  
10 + #include <stdlib.h>
11 +
12 + #include "paths.h"
13   #include "rtio.h"
14   #include "rterror.h"
15   #include "font.h"
16  
17   #define galloc(nv)      (GLYPH *)malloc(sizeof(GLYPH)+2*sizeof(GORD)*(nv))
18  
16
19   int     retainfonts = 0;                /* retain loaded fonts? */
20  
21   static FONT     *fontlist = NULL;       /* list of loaded fonts */
22  
23  
24   FONT *
25 < getfont(fname)                          /* return font fname */
26 < char  *fname;
25 > getfont(                        /* return font fname */
26 >        char  *fname
27 > )
28   {
29 +        char  embuf[512];
30          FILE  *fp;
31          char  *pathname, *err = NULL;
32          unsigned  wsum, hsum, ngly;
33          int  gn, ngv, gv;
34 <        register GLYPH  *g;
34 >        GLYPH   *g;
35          GORD  *gp;
36 <        register FONT  *f;
36 >        FONT  *f;
37  
38          for (f = fontlist; f != NULL; f = f->next)
39                  if (!strcmp(f->name, fname)) {
# Line 38 | Line 42 | char  *fname;
42                  }
43                                                  /* load the font file */
44          if ((pathname = getpath(fname, getrlibpath(), R_OK)) == NULL) {
45 <                sprintf(errmsg, "cannot find font file \"%s\"", fname);
46 <                error(USER, errmsg);
45 >                sprintf(embuf, "cannot find font file \"%s\"\n", fname);
46 >                eputs(embuf);
47 >                return(NULL);
48          }
49 +        if ((fp = fopen(pathname, "r")) == NULL) {
50 +                sprintf(embuf, "cannot open font file \"%s\"\n", pathname);
51 +                eputs(embuf);
52 +                return(NULL);
53 +        }
54          f = (FONT *)calloc(1, sizeof(FONT));
55          if (f == NULL)
56                  goto memerr;
57 <        f->name = savestr(fname);
57 >        strcpy(f->name, fname);
58          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        }
59          wsum = hsum = ngly = 0;                 /* get each glyph */
60          while ((ngv = fgetval(fp, 'i', (char *)&gn)) != EOF) {
61                  if (ngv == 0)
# Line 109 | Line 114 | char  *fname;
114          f->next = fontlist;
115          return(fontlist = f);
116   nonint:
117 <        sprintf(errmsg, "non-integer in font file \"%s\"", pathname);
118 <        error(USER, errmsg);
117 >        sprintf(embuf, "non-integer in font file \"%s\"\n", pathname);
118 >        eputs(embuf);
119 >        fclose(fp);
120 >        return(NULL);
121   fonterr:
122 <        sprintf(errmsg, "%s character (%d) in font file \"%s\"",
122 >        sprintf(embuf, "%s character (%d) in font file \"%s\"\n",
123                          err, gn, pathname);
124 <        error(USER, errmsg);
124 >        eputs(embuf);
125 >        fclose(fp);
126 >        return(NULL);
127   memerr:
128 <        error(SYSTEM, "out of memory in fontglyph");
129 <        return NULL; /* pro forma return */
128 >        eputs("out of memory in getfont()\n");
129 >        fclose(fp);
130 >        return(NULL);
131   }
132  
133  
134   void
135 < freefont(fnt)                   /* release a font (free all if NULL) */
136 < FONT *fnt;
135 > freefont(                       /* release a font (free all if NULL) */
136 >        FONT *fnt
137 > )
138   {
139          FONT  head;
140 <        register FONT  *fl, *f;
141 <        register int  i;
140 >        FONT  *fl, *f;
141 >        int  i;
142                                          /* check reference count */
143          if (fnt != NULL && ((fnt->nref-- > 1) | retainfonts))
144                  return;
# Line 139 | Line 150 | FONT *fnt;
150                          for (i = 0; i < 256; i++)
151                                  if (f->fg[i] != NULL)
152                                          free((void *)f->fg[i]);
142                        freestr(f->name);
153                          free((void *)f);
154                  } else
155                          fl = f;
# Line 148 | Line 158 | FONT *fnt;
158  
159  
160   int
161 < uniftext(sp, tp, f)                     /* uniformly space text line */
162 < register short  *sp;            /* returned character spacing */
163 < register char  *tp;             /* text line */
164 < register FONT  *f;              /* font */
161 > uniftext(                       /* uniformly space text line */
162 >        short   *sp,            /* returned character spacing */
163 >        char  *tp,              /* text line */
164 >        FONT  *f                /* font */
165 > )
166   {
167          int  linelen;
168  
# Line 166 | Line 177 | register FONT  *f;             /* font */
177  
178  
179   int
180 < squeeztext(sp, tp, f, cis)              /* squeeze text line */
181 < short  *sp;                     /* returned character spacing */
182 < char  *tp;                      /* text line */
183 < FONT  *f;                       /* font */
184 < int  cis;                       /* intercharacter spacing */
180 > squeeztext(             /* squeeze text line */
181 >        short  *sp,                     /* returned character spacing */
182 >        char  *tp,                      /* text line */
183 >        FONT  *f,                       /* font */
184 >        int  cis                        /* intercharacter spacing */
185 > )
186   {
187          int  linelen;
188 <        register GLYPH  *gp;
188 >        GLYPH   *gp;
189  
190          linelen = 0;
191          gp = NULL;
# Line 201 | Line 213 | int  cis;                      /* intercharacter spacing */
213  
214  
215   int
216 < proptext(sp, tp, f, cis, nsi)           /* space line proportionally */
217 < short  *sp;                     /* returned character spacing */
218 < char  *tp;                      /* text line */
219 < FONT  *f;                       /* font */
220 < int  cis;                       /* target intercharacter spacing */
221 < int  nsi;                       /* minimum number of spaces for indent */
216 > proptext(               /* space line proportionally */
217 >        short  *sp,                     /* returned character spacing */
218 >        char  *tp,                      /* text line */
219 >        FONT  *f,                       /* font */
220 >        int  cis,                       /* target intercharacter spacing */
221 >        int  nsi                        /* minimum number of spaces for indent */
222 > )
223   {
224 <        register char  *end, *tab = NULL;
224 >        char  *end, *tab = NULL;
225          GLYPH  *gp;
226          short  *nsp;
227          int  alen, len, width;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines