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.22 by greg, Fri Nov 19 22:51:31 2021 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 "font.h"
15  
16   #define galloc(nv)      (GLYPH *)malloc(sizeof(GLYPH)+2*sizeof(GORD)*(nv))
17  
71
18   int     retainfonts = 0;                /* retain loaded fonts? */
19  
20   static FONT     *fontlist = NULL;       /* list of loaded fonts */
21  
22  
23   FONT *
24 < getfont(fname)                          /* return font fname */
25 < char  *fname;
24 > getfont(                        /* return font fname */
25 >        char  *fname
26 > )
27   {
28          FILE  *fp;
29 <        char  *pathname, *err;
29 >        char  *pathname, *err = NULL;
30          unsigned  wsum, hsum, ngly;
31          int  gn, ngv, gv;
32 <        register GLYPH  *g;
32 >        GLYPH   *g;
33          GORD  *gp;
34 <        register FONT  *f;
34 >        FONT  *f;
35  
36          for (f = fontlist; f != NULL; f = f->next)
37                  if (!strcmp(f->name, fname)) {
# Line 92 | Line 39 | char  *fname;
39                          return(f);
40                  }
41                                                  /* load the font file */
42 <        if ((pathname = getpath(fname, getlibpath(), R_OK)) == NULL) {
43 <                sprintf(errmsg, "cannot find font file \"%s\"", fname);
44 <                error(USER, errmsg);
42 >        if ((pathname = getpath(fname, getrlibpath(), R_OK)) == NULL) {
43 >                fprintf(stderr, "cannot find font file \"%s\"\n", fname);
44 >                return(NULL);
45          }
46 +        if ((fp = fopen(pathname, "r")) == NULL) {
47 +                fprintf(stderr, "cannot open font file \"%s\"\n", pathname);
48 +                return(NULL);
49 +        }
50          f = (FONT *)calloc(1, sizeof(FONT));
51          if (f == NULL)
52                  goto memerr;
53 <        f->name = savestr(fname);
53 >        strcpy(f->name, fname);
54          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        }
55          wsum = hsum = ngly = 0;                 /* get each glyph */
56          while ((ngv = fgetval(fp, 'i', (char *)&gn)) != EOF) {
57                  if (ngv == 0)
# Line 164 | Line 110 | char  *fname;
110          f->next = fontlist;
111          return(fontlist = f);
112   nonint:
113 <        sprintf(errmsg, "non-integer in font file \"%s\"", pathname);
114 <        error(USER, errmsg);
113 >        fprintf(stderr, "non-integer in font file \"%s\"\n", pathname);
114 >        fclose(fp);
115 >        return(NULL);
116   fonterr:
117 <        sprintf(errmsg, "%s character (%d) in font file \"%s\"",
117 >        fprintf(stderr, "%s character (%d) in font file \"%s\"\n",
118                          err, gn, pathname);
119 <        error(USER, errmsg);
119 >        fclose(fp);
120 >        return(NULL);
121   memerr:
122 <        error(SYSTEM, "out of memory in fontglyph");
122 >        fprintf(stderr, "out of memory in getfont()\n");
123 >        fclose(fp);
124 >        return(NULL);
125   }
126  
127  
128   void
129 < freefont(fnt)                   /* release a font (free all if NULL) */
130 < FONT *fnt;
129 > freefont(                       /* release a font (free all if NULL) */
130 >        FONT *fnt
131 > )
132   {
133          FONT  head;
134 <        register FONT  *fl, *f;
135 <        register int  i;
134 >        FONT  *fl, *f;
135 >        int  i;
136                                          /* check reference count */
137 <        if (fnt != NULL && (fnt->nref-- > 1 | retainfonts))
137 >        if (fnt != NULL && ((fnt->nref-- > 1) | retainfonts))
138                  return;
139          head.next = fontlist;
140          fl = &head;
141          while ((f = fl->next) != NULL)
142 <                if ((fnt == NULL | fnt == f)) {
142 >                if ((fnt == NULL) | (fnt == f)) {
143                          fl->next = f->next;
144                          for (i = 0; i < 256; i++)
145                                  if (f->fg[i] != NULL)
146                                          free((void *)f->fg[i]);
196                        freestr(f->name);
147                          free((void *)f);
148                  } else
149                          fl = f;
# Line 202 | Line 152 | FONT *fnt;
152  
153  
154   int
155 < uniftext(sp, tp, f)                     /* uniformly space text line */
156 < register short  *sp;            /* returned character spacing */
157 < register char  *tp;             /* text line */
158 < register FONT  *f;              /* font */
155 > uniftext(                       /* uniformly space text line */
156 >        short   *sp,            /* returned character spacing */
157 >        char  *tp,              /* text line */
158 >        FONT  *f                /* font */
159 > )
160   {
161          int  linelen;
162  
# Line 220 | Line 171 | register FONT  *f;             /* font */
171  
172  
173   int
174 < squeeztext(sp, tp, f, cis)              /* squeeze text line */
175 < short  *sp;                     /* returned character spacing */
176 < char  *tp;                      /* text line */
177 < FONT  *f;                       /* font */
178 < int  cis;                       /* intercharacter spacing */
174 > squeeztext(             /* squeeze text line */
175 >        short  *sp,                     /* returned character spacing */
176 >        char  *tp,                      /* text line */
177 >        FONT  *f,                       /* font */
178 >        int  cis                        /* intercharacter spacing */
179 > )
180   {
181          int  linelen;
182 <        register GLYPH  *gp;
182 >        GLYPH   *gp;
183  
184          linelen = 0;
185          gp = NULL;
# Line 255 | Line 207 | int  cis;                      /* intercharacter spacing */
207  
208  
209   int
210 < proptext(sp, tp, f, cis, nsi)           /* space line proportionally */
211 < short  *sp;                     /* returned character spacing */
212 < char  *tp;                      /* text line */
213 < FONT  *f;                       /* font */
214 < int  cis;                       /* target intercharacter spacing */
215 < int  nsi;                       /* minimum number of spaces for indent */
210 > proptext(               /* space line proportionally */
211 >        short  *sp,                     /* returned character spacing */
212 >        char  *tp,                      /* text line */
213 >        FONT  *f,                       /* font */
214 >        int  cis,                       /* target intercharacter spacing */
215 >        int  nsi                        /* minimum number of spaces for indent */
216 > )
217   {
218 <        register char  *end, *tab;
218 >        char  *end, *tab = NULL;
219          GLYPH  *gp;
220          short  *nsp;
221          int  alen, len, width;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines