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.12 by greg, Sat Feb 22 02:07:22 2003 UTC vs.
Revision 2.26 by greg, Wed Feb 2 00:03:40 2022 UTC

# Line 5 | Line 5 | static const char      RCSid[] = "$Id$";
5   * Polygonal font handling routines
6   */
7  
8 < /* ====================================================================
9 < * The Radiance Software License, Version 1.0
10 < *
11 < * Copyright (c) 1990 - 2002 The Regents of the University of California,
12 < * through Lawrence Berkeley National Laboratory.   All rights reserved.
13 < *
14 < * Redistribution and use in source and binary forms, with or without
15 < * modification, are permitted provided that the following conditions
16 < * are met:
17 < *
18 < * 1. Redistributions of source code must retain the above copyright
19 < *         notice, this list of conditions and the following disclaimer.
20 < *
21 < * 2. Redistributions in binary form must reproduce the above copyright
22 < *       notice, this list of conditions and the following disclaimer in
23 < *       the documentation and/or other materials provided with the
24 < *       distribution.
25 < *
26 < * 3. The end-user documentation included with the redistribution,
27 < *           if any, must include the following acknowledgment:
28 < *             "This product includes Radiance software
29 < *                 (http://radsite.lbl.gov/)
30 < *                 developed by the Lawrence Berkeley National Laboratory
31 < *               (http://www.lbl.gov/)."
32 < *       Alternately, this acknowledgment may appear in the software itself,
33 < *       if and wherever such third-party acknowledgments normally appear.
34 < *
35 < * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
36 < *       and "The Regents of the University of California" must
37 < *       not be used to endorse or promote products derived from this
38 < *       software without prior written permission. For written
39 < *       permission, please contact [email protected].
40 < *
41 < * 5. Products derived from this software may not be called "Radiance",
42 < *       nor may "Radiance" appear in their name, without prior written
43 < *       permission of Lawrence Berkeley National Laboratory.
44 < *
45 < * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
46 < * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 < * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48 < * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
49 < * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50 < * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51 < * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
52 < * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53 < * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54 < * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55 < * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 < * SUCH DAMAGE.
57 < * ====================================================================
58 < *
59 < * This software consists of voluntary contributions made by many
60 < * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
61 < * information on Lawrence Berkeley National Laboratory, please see
62 < * <http://www.lbl.gov/>.
63 < */
8 > #include "copyright.h"
9  
10 < #include "standard.h"
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  
71
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;
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 92 | Line 41 | char  *fname;
41                          return(f);
42                  }
43                                                  /* load the font file */
44 <        if ((pathname = getpath(fname, getlibpath(), R_OK)) == NULL) {
45 <                sprintf(errmsg, "cannot find font file \"%s\"", fname);
46 <                error(USER, errmsg);
44 >        if ((pathname = getpath(fname, getrlibpath(), R_OK)) == NULL) {
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;
104        if ((fp = fopen(pathname, "r")) == NULL) {
105                sprintf(errmsg, "cannot open font file \"%s\"",
106                                pathname);
107                error(SYSTEM, errmsg);
108        }
59          wsum = hsum = ngly = 0;                 /* get each glyph */
60          while ((ngv = fgetval(fp, 'i', (char *)&gn)) != EOF) {
61                  if (ngv == 0)
# Line 123 | Line 73 | char  *fname;
73                          err = "bad # vertices for";
74                          goto fonterr;
75                  }
76 +                if (ngv > f->maxgv)
77 +                        f->maxgv = ngv;
78                  g = galloc(ngv);
79                  if (g == NULL)
80                          goto memerr;
# Line 164 | Line 116 | char  *fname;
116          f->next = fontlist;
117          return(fontlist = f);
118   nonint:
119 <        sprintf(errmsg, "non-integer in font file \"%s\"", pathname);
120 <        error(USER, errmsg);
119 >        sprintf(embuf, "non-integer in font file \"%s\"\n", pathname);
120 >        eputs(embuf);
121 >        fclose(fp);
122 >        return(NULL);
123   fonterr:
124 <        sprintf(errmsg, "%s character (%d) in font file \"%s\"",
124 >        sprintf(embuf, "%s character (%d) in font file \"%s\"\n",
125                          err, gn, pathname);
126 <        error(USER, errmsg);
126 >        eputs(embuf);
127 >        fclose(fp);
128 >        return(NULL);
129   memerr:
130 <        error(SYSTEM, "out of memory in fontglyph");
130 >        eputs("out of memory in getfont()\n");
131 >        fclose(fp);
132 >        return(NULL);
133   }
134  
135  
136   void
137 < freefont(fnt)                   /* release a font (free all if NULL) */
138 < FONT *fnt;
137 > freefont(                       /* release a font (free all if NULL) */
138 >        FONT *fnt
139 > )
140   {
141          FONT  head;
142 <        register FONT  *fl, *f;
143 <        register int  i;
142 >        FONT  *fl, *f;
143 >        int  i;
144                                          /* check reference count */
145 <        if (fnt != NULL && (fnt->nref-- > 1 | retainfonts))
145 >        if (fnt != NULL && ((fnt->nref -= (f->nref > 0)) | retainfonts))
146                  return;
147          head.next = fontlist;
148          fl = &head;
149          while ((f = fl->next) != NULL)
150 <                if ((fnt == NULL | fnt == f)) {
150 >                if ((fnt == NULL) | (fnt == f)) {
151                          fl->next = f->next;
152                          for (i = 0; i < 256; i++)
153                                  if (f->fg[i] != NULL)
154                                          free((void *)f->fg[i]);
196                        freestr(f->name);
155                          free((void *)f);
156                  } else
157                          fl = f;
# Line 202 | Line 160 | FONT *fnt;
160  
161  
162   int
163 < uniftext(sp, tp, f)                     /* uniformly space text line */
164 < register short  *sp;            /* returned character spacing */
165 < register char  *tp;             /* text line */
166 < register FONT  *f;              /* font */
163 > uniftext(                       /* uniformly space text line */
164 >        short   *sp,            /* returned character spacing */
165 >        char  *tp,              /* text line */
166 >        FONT  *f                /* font */
167 > )
168   {
169          int  linelen;
170  
# Line 220 | Line 179 | register FONT  *f;             /* font */
179  
180  
181   int
182 < squeeztext(sp, tp, f, cis)              /* squeeze text line */
183 < short  *sp;                     /* returned character spacing */
184 < char  *tp;                      /* text line */
185 < FONT  *f;                       /* font */
186 < int  cis;                       /* intercharacter spacing */
182 > squeeztext(             /* squeeze text line */
183 >        short  *sp,                     /* returned character spacing */
184 >        char  *tp,                      /* text line */
185 >        FONT  *f,                       /* font */
186 >        int  cis                        /* intercharacter spacing */
187 > )
188   {
189          int  linelen;
190 <        register GLYPH  *gp;
190 >        GLYPH   *gp;
191  
192          linelen = 0;
193          gp = NULL;
# Line 255 | Line 215 | int  cis;                      /* intercharacter spacing */
215  
216  
217   int
218 < proptext(sp, tp, f, cis, nsi)           /* space line proportionally */
219 < short  *sp;                     /* returned character spacing */
220 < char  *tp;                      /* text line */
221 < FONT  *f;                       /* font */
222 < int  cis;                       /* target intercharacter spacing */
223 < int  nsi;                       /* minimum number of spaces for indent */
218 > proptext(               /* space line proportionally */
219 >        short  *sp,                     /* returned character spacing */
220 >        char  *tp,                      /* text line */
221 >        FONT  *f,                       /* font */
222 >        int  cis,                       /* target intercharacter spacing */
223 >        int  nsi                        /* minimum number of spaces for indent */
224 > )
225   {
226 <        register char  *end, *tab;
226 >        char  *end, *tab = NULL;
227          GLYPH  *gp;
228          short  *nsp;
229          int  alen, len, width;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines