15 |
|
#define galloc(nv) (GLYPH *)malloc(sizeof(GLYPH)+2*sizeof(GORD)*(nv)) |
16 |
|
|
17 |
|
|
18 |
< |
extern char *libpath; /* list of library directories */ |
18 |
> |
extern char *fgetword(), *getlibpath(); |
19 |
|
|
20 |
|
static FONT *fontlist = NULL; /* list of loaded fonts */ |
21 |
|
|
30 |
|
unsigned wsum, hsum, ngly; |
31 |
|
int gn, ngv; |
32 |
|
register int gv; |
33 |
< |
register GLYPH *g; |
33 |
> |
register GLYPH *g; |
34 |
|
GORD *gp; |
35 |
|
register FONT *f; |
36 |
|
|
38 |
|
if (!strcmp(f->name, fname)) |
39 |
|
return(f); |
40 |
|
/* load the font file */ |
41 |
< |
if ((pathname = getpath(fname, libpath, R_OK)) == NULL) { |
41 |
> |
if ((pathname = getpath(fname, getlibpath(), R_OK)) == NULL) { |
42 |
|
sprintf(errmsg, "cannot find font file \"%s\"", fname); |
43 |
|
error(USER, errmsg); |
44 |
|
} |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
+ |
freefont(fname) /* free a font (free all if fname==NULL) */ |
126 |
+ |
char *fname; |
127 |
+ |
{ |
128 |
+ |
FONT head; |
129 |
+ |
register FONT *fl, *f; |
130 |
+ |
register int i; |
131 |
+ |
|
132 |
+ |
head.next = fontlist; |
133 |
+ |
fl = &head; |
134 |
+ |
while ((f = fl->next) != NULL) |
135 |
+ |
if (fname == NULL || !strcmp(fname, f->name)) { |
136 |
+ |
fl->next = f->next; |
137 |
+ |
for (i = 0; i < 256; i++) |
138 |
+ |
if (f->fg[i] != NULL) |
139 |
+ |
free((char *)f->fg[i]); |
140 |
+ |
freestr(f->name); |
141 |
+ |
free((char *)f); |
142 |
+ |
} else |
143 |
+ |
fl = f; |
144 |
+ |
fontlist = head.next; |
145 |
+ |
} |
146 |
+ |
|
147 |
+ |
|
148 |
|
int |
149 |
|
uniftext(sp, tp, f) /* uniformly space text line */ |
150 |
< |
register short *sp; /* returned character spacing */ |
150 |
> |
register short *sp; /* returned character spacing */ |
151 |
|
register char *tp; /* text line */ |
152 |
|
register FONT *f; /* font */ |
153 |
|
{ |
158 |
|
if (f->fg[*tp++&0xff] == NULL) |
159 |
|
*sp++ = 0; |
160 |
|
else |
161 |
< |
linelen += *sp++ = 256; |
161 |
> |
linelen += *sp++ = 255; |
162 |
|
return(linelen); |
163 |
|
} |
164 |
|
|
171 |
|
int cis; /* intercharacter spacing */ |
172 |
|
{ |
173 |
|
int linelen; |
174 |
< |
register GLYPH *gp; |
174 |
> |
register GLYPH *gp; |
175 |
|
|
176 |
+ |
linelen = 0; |
177 |
|
gp = NULL; |
178 |
|
while (*tp && (gp = f->fg[*tp++&0xff]) == NULL) |
179 |
|
*sp++ = 0; |
180 |
|
cis /= 2; |
181 |
< |
linelen = *sp = cis; |
181 |
> |
*sp = cis; |
182 |
|
while (gp != NULL) { |
183 |
|
if (gp->nverts) { /* regular character */ |
184 |
|
linelen += *sp++ += cis - gp->left; |
213 |
|
/* start by squeezing it */ |
214 |
|
squeeztext(sp, tp, f, cis); |
215 |
|
/* now, realign spacing */ |
216 |
< |
len = 0; |
193 |
< |
width = alen = *sp++; |
216 |
> |
width = *sp++; |
217 |
|
while (*tp) { |
218 |
+ |
len = alen = 0; |
219 |
|
nsp = sp; |
220 |
|
for (end = tp; *end; end = tab) { |
221 |
|
tab = end + 1; |
228 |
|
} |
229 |
|
len += tab - end; |
230 |
|
} |
231 |
< |
if (tab - end > nsi) |
231 |
> |
if (nsi && tab - end > nsi) |
232 |
|
break; |
233 |
|
} |
234 |
|
len *= f->mwidth + cis; /* compute target length */ |
239 |
|
*sp++ += alen; |
240 |
|
len -= alen; |
241 |
|
} |
218 |
– |
len = 0; |
219 |
– |
alen = 0; |
242 |
|
tp = tab; |
243 |
|
} |
244 |
|
return(width); |