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.23 by greg, Sat Nov 20 15:53:24 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 "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          FILE  *fp;
30 <        char  *pathname, *err;
30 >        char  *pathname, *err = NULL;
31          unsigned  wsum, hsum, ngly;
32          int  gn, ngv, gv;
33 <        register GLYPH  *g;
33 >        GLYPH   *g;
34          GORD  *gp;
35 <        register FONT  *f;
35 >        FONT  *f;
36  
37          for (f = fontlist; f != NULL; f = f->next)
38                  if (!strcmp(f->name, fname)) {
# Line 92 | Line 40 | char  *fname;
40                          return(f);
41                  }
42                                                  /* load the font file */
43 <        if ((pathname = getpath(fname, getlibpath(), R_OK)) == NULL) {
44 <                sprintf(errmsg, "cannot find font file \"%s\"", fname);
45 <                error(USER, errmsg);
43 >        if ((pathname = getpath(fname, getrlibpath(), R_OK)) == NULL) {
44 >                sprintf(errmsg, "cannot find font file \"%s\"\n", fname);
45 >                eputs(errmsg);
46 >                return(NULL);
47          }
48 +        if ((fp = fopen(pathname, "r")) == NULL) {
49 +                sprintf(errmsg, "cannot open font file \"%s\"\n", pathname);
50 +                eputs(errmsg);
51 +                return(NULL);
52 +        }
53          f = (FONT *)calloc(1, sizeof(FONT));
54          if (f == NULL)
55                  goto memerr;
56 <        f->name = savestr(fname);
56 >        strcpy(f->name, fname);
57          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        }
58          wsum = hsum = ngly = 0;                 /* get each glyph */
59          while ((ngv = fgetval(fp, 'i', (char *)&gn)) != EOF) {
60                  if (ngv == 0)
# Line 164 | Line 113 | char  *fname;
113          f->next = fontlist;
114          return(fontlist = f);
115   nonint:
116 <        sprintf(errmsg, "non-integer in font file \"%s\"", pathname);
117 <        error(USER, errmsg);
116 >        sprintf(errmsg, "non-integer in font file \"%s\"\n", pathname);
117 >        eputs(errmsg);
118 >        fclose(fp);
119 >        return(NULL);
120   fonterr:
121 <        sprintf(errmsg, "%s character (%d) in font file \"%s\"",
121 >        sprintf(errmsg, "%s character (%d) in font file \"%s\"\n",
122                          err, gn, pathname);
123 <        error(USER, errmsg);
123 >        eputs(errmsg);
124 >        fclose(fp);
125 >        return(NULL);
126   memerr:
127 <        error(SYSTEM, "out of memory in fontglyph");
127 >        eputs("out of memory in getfont()\n");
128 >        fclose(fp);
129 >        return(NULL);
130   }
131  
132  
133   void
134 < freefont(fnt)                   /* release a font (free all if NULL) */
135 < FONT *fnt;
134 > freefont(                       /* release a font (free all if NULL) */
135 >        FONT *fnt
136 > )
137   {
138          FONT  head;
139 <        register FONT  *fl, *f;
140 <        register int  i;
139 >        FONT  *fl, *f;
140 >        int  i;
141                                          /* check reference count */
142 <        if (fnt != NULL && (fnt->nref-- > 1 | retainfonts))
142 >        if (fnt != NULL && ((fnt->nref-- > 1) | retainfonts))
143                  return;
144          head.next = fontlist;
145          fl = &head;
146          while ((f = fl->next) != NULL)
147 <                if ((fnt == NULL | fnt == f)) {
147 >                if ((fnt == NULL) | (fnt == f)) {
148                          fl->next = f->next;
149                          for (i = 0; i < 256; i++)
150                                  if (f->fg[i] != NULL)
151                                          free((void *)f->fg[i]);
196                        freestr(f->name);
152                          free((void *)f);
153                  } else
154                          fl = f;
# Line 202 | Line 157 | FONT *fnt;
157  
158  
159   int
160 < uniftext(sp, tp, f)                     /* uniformly space text line */
161 < register short  *sp;            /* returned character spacing */
162 < register char  *tp;             /* text line */
163 < register FONT  *f;              /* font */
160 > uniftext(                       /* uniformly space text line */
161 >        short   *sp,            /* returned character spacing */
162 >        char  *tp,              /* text line */
163 >        FONT  *f                /* font */
164 > )
165   {
166          int  linelen;
167  
# Line 220 | Line 176 | register FONT  *f;             /* font */
176  
177  
178   int
179 < squeeztext(sp, tp, f, cis)              /* squeeze text line */
180 < short  *sp;                     /* returned character spacing */
181 < char  *tp;                      /* text line */
182 < FONT  *f;                       /* font */
183 < int  cis;                       /* intercharacter spacing */
179 > squeeztext(             /* squeeze text line */
180 >        short  *sp,                     /* returned character spacing */
181 >        char  *tp,                      /* text line */
182 >        FONT  *f,                       /* font */
183 >        int  cis                        /* intercharacter spacing */
184 > )
185   {
186          int  linelen;
187 <        register GLYPH  *gp;
187 >        GLYPH   *gp;
188  
189          linelen = 0;
190          gp = NULL;
# Line 255 | Line 212 | int  cis;                      /* intercharacter spacing */
212  
213  
214   int
215 < proptext(sp, tp, f, cis, nsi)           /* space line proportionally */
216 < short  *sp;                     /* returned character spacing */
217 < char  *tp;                      /* text line */
218 < FONT  *f;                       /* font */
219 < int  cis;                       /* target intercharacter spacing */
220 < int  nsi;                       /* minimum number of spaces for indent */
215 > proptext(               /* space line proportionally */
216 >        short  *sp,                     /* returned character spacing */
217 >        char  *tp,                      /* text line */
218 >        FONT  *f,                       /* font */
219 >        int  cis,                       /* target intercharacter spacing */
220 >        int  nsi                        /* minimum number of spaces for indent */
221 > )
222   {
223 <        register char  *end, *tab;
223 >        char  *end, *tab = NULL;
224          GLYPH  *gp;
225          short  *nsp;
226          int  alen, len, width;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines