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 "standard.h" |
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 |
|
|
19 |
|
|
20 |
< |
extern char *fgetword(), *getlibpath(); |
20 |
> |
int retainfonts = 0; /* retain loaded fonts? */ |
21 |
|
|
22 |
|
static FONT *fontlist = NULL; /* list of loaded fonts */ |
23 |
|
|
26 |
|
getfont(fname) /* return font fname */ |
27 |
|
char *fname; |
28 |
|
{ |
27 |
– |
char buf[16]; |
29 |
|
FILE *fp; |
30 |
< |
char *pathname, *err; |
30 |
> |
char *pathname, *err = NULL; |
31 |
|
unsigned wsum, hsum, ngly; |
32 |
< |
int gn, ngv; |
32 |
< |
register int gv; |
32 |
> |
int gn, ngv, gv; |
33 |
|
register GLYPH *g; |
34 |
|
GORD *gp; |
35 |
|
register FONT *f; |
36 |
|
|
37 |
|
for (f = fontlist; f != NULL; f = f->next) |
38 |
< |
if (!strcmp(f->name, fname)) |
38 |
> |
if (!strcmp(f->name, fname)) { |
39 |
> |
f->nref++; |
40 |
|
return(f); |
41 |
+ |
} |
42 |
|
/* load the font file */ |
43 |
< |
if ((pathname = getpath(fname, getlibpath(), R_OK)) == NULL) { |
43 |
> |
if ((pathname = getpath(fname, getrlibpath(), R_OK)) == NULL) { |
44 |
|
sprintf(errmsg, "cannot find font file \"%s\"", fname); |
45 |
< |
error(USER, errmsg); |
45 |
> |
error(SYSTEM, errmsg); |
46 |
|
} |
47 |
|
f = (FONT *)calloc(1, sizeof(FONT)); |
48 |
|
if (f == NULL) |
49 |
|
goto memerr; |
50 |
|
f->name = savestr(fname); |
51 |
+ |
f->nref = 1; |
52 |
|
if ((fp = fopen(pathname, "r")) == NULL) { |
53 |
|
sprintf(errmsg, "cannot open font file \"%s\"", |
54 |
|
pathname); |
55 |
|
error(SYSTEM, errmsg); |
56 |
|
} |
57 |
< |
wsum = hsum = ngly = 0; |
58 |
< |
while (fgetword(buf,sizeof(buf),fp) != NULL) { /* get each glyph */ |
59 |
< |
if (!isint(buf)) |
57 |
> |
wsum = hsum = ngly = 0; /* get each glyph */ |
58 |
> |
while ((ngv = fgetval(fp, 'i', (char *)&gn)) != EOF) { |
59 |
> |
if (ngv == 0) |
60 |
|
goto nonint; |
58 |
– |
gn = atoi(buf); |
61 |
|
if (gn < 1 || gn > 255) { |
62 |
|
err = "illegal"; |
63 |
|
goto fonterr; |
66 |
|
err = "duplicate"; |
67 |
|
goto fonterr; |
68 |
|
} |
69 |
< |
if (fgetword(buf,sizeof(buf),fp) == NULL || !isint(buf) || |
70 |
< |
(ngv = atoi(buf)) < 0 || ngv > 32000) { |
69 |
> |
if (fgetval(fp, 'i', (char *)&ngv) <= 0 || |
70 |
> |
ngv < 0 || ngv > 32000) { |
71 |
|
err = "bad # vertices for"; |
72 |
|
goto fonterr; |
73 |
|
} |
79 |
|
ngv *= 2; |
80 |
|
gp = gvlist(g); |
81 |
|
while (ngv--) { |
82 |
< |
if (fgetword(buf,sizeof(buf),fp) == NULL || |
83 |
< |
!isint(buf) || |
82 |
< |
(gv = atoi(buf)) < 0 || gv > 255) { |
82 |
> |
if (fgetval(fp, 'i', (char *)&gv) <= 0 || |
83 |
> |
gv < 0 || gv > 255) { |
84 |
|
err = "bad vertex for"; |
85 |
|
goto fonterr; |
86 |
|
} |
120 |
|
error(USER, errmsg); |
121 |
|
memerr: |
122 |
|
error(SYSTEM, "out of memory in fontglyph"); |
123 |
+ |
return NULL; /* pro forma return */ |
124 |
|
} |
125 |
|
|
126 |
|
|
127 |
< |
freefont(fname) /* free a font (free all if fname==NULL) */ |
128 |
< |
char *fname; |
127 |
> |
void |
128 |
> |
freefont(fnt) /* release a font (free all if NULL) */ |
129 |
> |
FONT *fnt; |
130 |
|
{ |
131 |
|
FONT head; |
132 |
|
register FONT *fl, *f; |
133 |
|
register int i; |
134 |
< |
|
134 |
> |
/* check reference count */ |
135 |
> |
if (fnt != NULL && ((fnt->nref-- > 1) | retainfonts)) |
136 |
> |
return; |
137 |
|
head.next = fontlist; |
138 |
|
fl = &head; |
139 |
|
while ((f = fl->next) != NULL) |
140 |
< |
if (fname == NULL || !strcmp(fname, f->name)) { |
140 |
> |
if ((fnt == NULL) | (fnt == f)) { |
141 |
|
fl->next = f->next; |
142 |
|
for (i = 0; i < 256; i++) |
143 |
|
if (f->fg[i] != NULL) |
144 |
< |
free((char *)f->fg[i]); |
144 |
> |
free((void *)f->fg[i]); |
145 |
|
freestr(f->name); |
146 |
< |
free((char *)f); |
146 |
> |
free((void *)f); |
147 |
|
} else |
148 |
|
fl = f; |
149 |
|
fontlist = head.next; |
211 |
|
int cis; /* target intercharacter spacing */ |
212 |
|
int nsi; /* minimum number of spaces for indent */ |
213 |
|
{ |
214 |
< |
register char *end, *tab; |
214 |
> |
register char *end, *tab = NULL; |
215 |
|
GLYPH *gp; |
216 |
|
short *nsp; |
217 |
|
int alen, len, width; |