| 17 |
|
|
| 18 |
|
extern char *libpath; /* list of library directories */ |
| 19 |
|
|
| 20 |
+ |
extern char *fgetword(); |
| 21 |
+ |
|
| 22 |
|
static FONT *fontlist = NULL; /* list of loaded fonts */ |
| 23 |
|
|
| 24 |
|
|
| 29 |
|
char buf[16]; |
| 30 |
|
FILE *fp; |
| 31 |
|
char *pathname, *err; |
| 32 |
+ |
unsigned wsum, hsum, ngly; |
| 33 |
|
int gn, ngv; |
| 34 |
|
register int gv; |
| 35 |
< |
register GLYPH *g; |
| 35 |
> |
register GLYPH *g; |
| 36 |
|
GORD *gp; |
| 37 |
|
register FONT *f; |
| 38 |
|
|
| 53 |
|
pathname); |
| 54 |
|
error(SYSTEM, errmsg); |
| 55 |
|
} |
| 56 |
+ |
wsum = hsum = ngly = 0; |
| 57 |
|
while (fgetword(buf,sizeof(buf),fp) != NULL) { /* get each glyph */ |
| 58 |
|
if (!isint(buf)) |
| 59 |
|
goto nonint; |
| 60 |
|
gn = atoi(buf); |
| 61 |
< |
if (gn < 0 || gn > 255) { |
| 61 |
> |
if (gn < 1 || gn > 255) { |
| 62 |
|
err = "illegal"; |
| 63 |
|
goto fonterr; |
| 64 |
|
} |
| 98 |
|
g->top = gv; |
| 99 |
|
} |
| 100 |
|
} |
| 101 |
+ |
if (g->right - g->left && g->top - g->bottom) { |
| 102 |
+ |
ngly++; |
| 103 |
+ |
wsum += g->right - g->left; |
| 104 |
+ |
hsum += g->top - g->bottom; |
| 105 |
+ |
} |
| 106 |
|
f->fg[gn] = g; |
| 107 |
|
} |
| 108 |
|
fclose(fp); |
| 109 |
+ |
if (ngly) { |
| 110 |
+ |
f->mwidth = wsum / ngly; |
| 111 |
+ |
f->mheight = hsum / ngly; |
| 112 |
+ |
} |
| 113 |
|
f->next = fontlist; |
| 114 |
|
return(fontlist = f); |
| 115 |
|
nonint: |
| 124 |
|
} |
| 125 |
|
|
| 126 |
|
|
| 127 |
+ |
freefont(fname) /* free a font (free all if fname==NULL) */ |
| 128 |
+ |
char *fname; |
| 129 |
+ |
{ |
| 130 |
+ |
FONT head; |
| 131 |
+ |
register FONT *fl, *f; |
| 132 |
+ |
register int i; |
| 133 |
+ |
|
| 134 |
+ |
head.next = fontlist; |
| 135 |
+ |
fl = &head; |
| 136 |
+ |
while ((f = fl->next) != NULL) |
| 137 |
+ |
if (fname == NULL || !strcmp(fname, f->name)) { |
| 138 |
+ |
fl->next = f->next; |
| 139 |
+ |
for (i = 0; i < 256; i++) |
| 140 |
+ |
if (f->fg[i] != NULL) |
| 141 |
+ |
free((char *)f->fg[i]); |
| 142 |
+ |
freestr(f->name); |
| 143 |
+ |
free((char *)f); |
| 144 |
+ |
} else |
| 145 |
+ |
fl = f; |
| 146 |
+ |
fontlist = head.next; |
| 147 |
+ |
} |
| 148 |
+ |
|
| 149 |
+ |
|
| 150 |
|
int |
| 151 |
+ |
uniftext(sp, tp, f) /* uniformly space text line */ |
| 152 |
+ |
register short *sp; /* returned character spacing */ |
| 153 |
+ |
register char *tp; /* text line */ |
| 154 |
+ |
register FONT *f; /* font */ |
| 155 |
+ |
{ |
| 156 |
+ |
int linelen; |
| 157 |
+ |
|
| 158 |
+ |
linelen = *sp++ = 0; |
| 159 |
+ |
while (*tp) |
| 160 |
+ |
if (f->fg[*tp++&0xff] == NULL) |
| 161 |
+ |
*sp++ = 0; |
| 162 |
+ |
else |
| 163 |
+ |
linelen += *sp++ = 256; |
| 164 |
+ |
return(linelen); |
| 165 |
+ |
} |
| 166 |
+ |
|
| 167 |
+ |
|
| 168 |
+ |
int |
| 169 |
|
squeeztext(sp, tp, f, cis) /* squeeze text line */ |
| 170 |
|
short *sp; /* returned character spacing */ |
| 171 |
|
char *tp; /* text line */ |
| 173 |
|
int cis; /* intercharacter spacing */ |
| 174 |
|
{ |
| 175 |
|
int linelen; |
| 176 |
< |
register GLYPH *gp; |
| 176 |
> |
register GLYPH *gp; |
| 177 |
|
|
| 178 |
+ |
linelen = 0; |
| 179 |
|
gp = NULL; |
| 180 |
|
while (*tp && (gp = f->fg[*tp++&0xff]) == NULL) |
| 181 |
|
*sp++ = 0; |
| 182 |
|
cis /= 2; |
| 183 |
< |
linelen = *sp = 0; |
| 183 |
> |
*sp = cis; |
| 184 |
|
while (gp != NULL) { |
| 185 |
|
if (gp->nverts) { /* regular character */ |
| 186 |
|
linelen += *sp++ += cis - gp->left; |
| 187 |
|
*sp = gp->right + cis; |
| 188 |
|
} else { /* space */ |
| 189 |
|
linelen += *sp++; |
| 190 |
< |
*sp = 256; |
| 190 |
> |
*sp = f->mwidth; |
| 191 |
|
} |
| 192 |
|
gp = NULL; |
| 193 |
|
while (*tp && (gp = f->fg[*tp++&0xff]) == NULL) { |
| 195 |
|
*sp = 0; |
| 196 |
|
} |
| 197 |
|
} |
| 198 |
< |
linelen += *sp; |
| 198 |
> |
linelen += *sp += cis; |
| 199 |
|
return(linelen); |
| 200 |
|
} |
| 201 |
|
|
| 202 |
|
|
| 203 |
+ |
int |
| 204 |
|
proptext(sp, tp, f, cis, nsi) /* space line proportionally */ |
| 205 |
|
short *sp; /* returned character spacing */ |
| 206 |
|
char *tp; /* text line */ |
| 208 |
|
int cis; /* target intercharacter spacing */ |
| 209 |
|
int nsi; /* minimum number of spaces for indent */ |
| 210 |
|
{ |
| 211 |
+ |
register char *end, *tab; |
| 212 |
+ |
GLYPH *gp; |
| 213 |
+ |
short *nsp; |
| 214 |
+ |
int alen, len, width; |
| 215 |
+ |
/* start by squeezing it */ |
| 216 |
+ |
squeeztext(sp, tp, f, cis); |
| 217 |
+ |
/* now, realign spacing */ |
| 218 |
+ |
width = *sp++; |
| 219 |
+ |
while (*tp) { |
| 220 |
+ |
len = alen = 0; |
| 221 |
+ |
nsp = sp; |
| 222 |
+ |
for (end = tp; *end; end = tab) { |
| 223 |
+ |
tab = end + 1; |
| 224 |
+ |
alen += *nsp++; |
| 225 |
+ |
if (f->fg[*end&0xff]) { |
| 226 |
+ |
while ((gp = f->fg[*tab&0xff]) != NULL && |
| 227 |
+ |
gp->nverts == 0) { /* tab in */ |
| 228 |
+ |
alen += *nsp++; |
| 229 |
+ |
tab++; |
| 230 |
+ |
} |
| 231 |
+ |
len += tab - end; |
| 232 |
+ |
} |
| 233 |
+ |
if (nsi && tab - end > nsi) |
| 234 |
+ |
break; |
| 235 |
+ |
} |
| 236 |
+ |
len *= f->mwidth + cis; /* compute target length */ |
| 237 |
+ |
width += len; |
| 238 |
+ |
len -= alen; /* necessary adjustment */ |
| 239 |
+ |
while (sp < nsp) { |
| 240 |
+ |
alen = len/(nsp-sp); |
| 241 |
+ |
*sp++ += alen; |
| 242 |
+ |
len -= alen; |
| 243 |
+ |
} |
| 244 |
+ |
tp = tab; |
| 245 |
+ |
} |
| 246 |
+ |
return(width); |
| 247 |
|
} |
| 156 |
– |
|
| 157 |
– |
|