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.3 by greg, Wed Jun 24 17:52:58 1992 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  *libpath;                  /* list of library directories */
17 > int     retainfonts = 0;                /* retain loaded fonts? */
18  
19   static FONT     *fontlist = NULL;       /* list of loaded fonts */
20  
# Line 24 | Line 23 | FONT *
23   getfont(fname)                          /* return font fname */
24   char  *fname;
25   {
27        char  buf[16];
26          FILE  *fp;
27          char  *pathname, *err;
28          unsigned  wsum, hsum, ngly;
29 <        int  gn, ngv;
30 <        register int  gv;
33 <        register GLYPH  *g;
29 >        int  gn, ngv, gv;
30 >        register GLYPH  *g;
31          GORD  *gp;
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, libpath, 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 46 | 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 (fgetword(buf,sizeof(buf),fp) != NULL) {  /* get each glyph */
56 <                if (!isint(buf))
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                gn = atoi(buf);
58                  if (gn < 1 || gn > 255) {
59                          err = "illegal";
60                          goto fonterr;
# Line 64 | Line 63 | char  *fname;
63                          err = "duplicate";
64                          goto fonterr;
65                  }
66 <                if (fgetword(buf,sizeof(buf),fp) == NULL || !isint(buf) ||
67 <                                (ngv = atoi(buf)) < 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 77 | Line 76 | char  *fname;
76                  ngv *= 2;
77                  gp = gvlist(g);
78                  while (ngv--) {
79 <                        if (fgetword(buf,sizeof(buf),fp) == NULL ||
80 <                                        !isint(buf) ||
82 <                                        (gv = atoi(buf)) < 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 122 | Line 120 | memerr:
120   }
121  
122  
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 +                                        /* 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 ((fnt == NULL | fnt == f)) {
137 +                        fl->next = f->next;
138 +                        for (i = 0; i < 256; i++)
139 +                                if (f->fg[i] != NULL)
140 +                                        free((void *)f->fg[i]);
141 +                        freestr(f->name);
142 +                        free((void *)f);
143 +                } else
144 +                        fl = f;
145 +        fontlist = head.next;
146 + }
147 +
148 +
149   int
150   uniftext(sp, tp, f)                     /* uniformly space text line */
151 < register short  *sp;            /* returned character spacing */
151 > register short  *sp;            /* returned character spacing */
152   register char  *tp;             /* text line */
153   register FONT  *f;              /* font */
154   {
# Line 135 | Line 159 | register FONT  *f;             /* font */
159                  if (f->fg[*tp++&0xff] == NULL)
160                          *sp++ = 0;
161                  else
162 <                        linelen += *sp++ = 256;
162 >                        linelen += *sp++ = 255;
163          return(linelen);
164   }
165  
# Line 148 | Line 172 | FONT  *f;                      /* font */
172   int  cis;                       /* intercharacter spacing */
173   {
174          int  linelen;
175 <        register GLYPH  *gp;
175 >        register GLYPH  *gp;
176  
177 +        linelen = 0;
178          gp = NULL;
179          while (*tp && (gp = f->fg[*tp++&0xff]) == NULL)
180                  *sp++ = 0;
181          cis /= 2;
182 <        linelen = *sp = cis;
182 >        *sp = cis;
183          while (gp != NULL) {
184                  if (gp->nverts) {               /* regular character */
185                          linelen += *sp++ += cis - gp->left;
# Line 189 | Line 214 | int  nsi;                      /* minimum number of spaces for indent */
214                                          /* start by squeezing it */
215          squeeztext(sp, tp, f, cis);
216                                          /* now, realign spacing */
217 <        len = 0;
193 <        width = alen = *sp++;
217 >        width = *sp++;
218          while (*tp) {
219 +                len = alen = 0;
220                  nsp = sp;
221                  for (end = tp; *end; end = tab) {
222                          tab = end + 1;
# Line 204 | Line 229 | int  nsi;                      /* minimum number of spaces for indent */
229                                  }
230                                  len += tab - end;
231                          }
232 <                        if (tab - end > nsi)
232 >                        if (nsi && tab - end > nsi)
233                                  break;
234                  }
235                  len *= f->mwidth + cis;         /* compute target length */
# Line 215 | Line 240 | int  nsi;                      /* minimum number of spaces for indent */
240                          *sp++ += alen;
241                          len -= alen;
242                  }
218                len = 0;
219                alen = 0;
243                  tp = tab;
244          }
245          return(width);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines