| 27 |
|
char buf[16]; |
| 28 |
|
FILE *fp; |
| 29 |
|
char *pathname, *err; |
| 30 |
+ |
unsigned wsum, hsum, ngly; |
| 31 |
|
int gn, ngv; |
| 32 |
|
register int gv; |
| 33 |
|
register GLYPH *g; |
| 51 |
|
pathname); |
| 52 |
|
error(SYSTEM, errmsg); |
| 53 |
|
} |
| 54 |
+ |
wsum = hsum = ngly = 0; |
| 55 |
|
while (fgetword(buf,sizeof(buf),fp) != NULL) { /* get each glyph */ |
| 56 |
|
if (!isint(buf)) |
| 57 |
|
goto nonint; |
| 58 |
|
gn = atoi(buf); |
| 59 |
< |
if (gn < 0 || gn > 255) { |
| 59 |
> |
if (gn < 1 || gn > 255) { |
| 60 |
|
err = "illegal"; |
| 61 |
|
goto fonterr; |
| 62 |
|
} |
| 96 |
|
g->top = gv; |
| 97 |
|
} |
| 98 |
|
} |
| 99 |
+ |
if (g->right - g->left && g->top - g->bottom) { |
| 100 |
+ |
ngly++; |
| 101 |
+ |
wsum += g->right - g->left; |
| 102 |
+ |
hsum += g->top - g->bottom; |
| 103 |
+ |
} |
| 104 |
|
f->fg[gn] = g; |
| 105 |
|
} |
| 106 |
|
fclose(fp); |
| 107 |
+ |
if (ngly) { |
| 108 |
+ |
f->mwidth = wsum / ngly; |
| 109 |
+ |
f->mheight = hsum / ngly; |
| 110 |
+ |
} |
| 111 |
|
f->next = fontlist; |
| 112 |
|
return(fontlist = f); |
| 113 |
|
nonint: |
| 123 |
|
|
| 124 |
|
|
| 125 |
|
int |
| 126 |
+ |
uniftext(sp, tp, f) /* uniformly space text line */ |
| 127 |
+ |
register short *sp; /* returned character spacing */ |
| 128 |
+ |
register char *tp; /* text line */ |
| 129 |
+ |
register FONT *f; /* font */ |
| 130 |
+ |
{ |
| 131 |
+ |
int linelen; |
| 132 |
+ |
|
| 133 |
+ |
linelen = *sp++ = 0; |
| 134 |
+ |
while (*tp) |
| 135 |
+ |
if (f->fg[*tp++&0xff] == NULL) |
| 136 |
+ |
*sp++ = 0; |
| 137 |
+ |
else |
| 138 |
+ |
linelen += *sp++ = 256; |
| 139 |
+ |
return(linelen); |
| 140 |
+ |
} |
| 141 |
+ |
|
| 142 |
+ |
|
| 143 |
+ |
int |
| 144 |
|
squeeztext(sp, tp, f, cis) /* squeeze text line */ |
| 145 |
|
short *sp; /* returned character spacing */ |
| 146 |
|
char *tp; /* text line */ |
| 154 |
|
while (*tp && (gp = f->fg[*tp++&0xff]) == NULL) |
| 155 |
|
*sp++ = 0; |
| 156 |
|
cis /= 2; |
| 157 |
< |
linelen = *sp = 0; |
| 157 |
> |
linelen = *sp = cis; |
| 158 |
|
while (gp != NULL) { |
| 159 |
|
if (gp->nverts) { /* regular character */ |
| 160 |
|
linelen += *sp++ += cis - gp->left; |
| 161 |
|
*sp = gp->right + cis; |
| 162 |
|
} else { /* space */ |
| 163 |
|
linelen += *sp++; |
| 164 |
< |
*sp = 256; |
| 164 |
> |
*sp = f->mwidth; |
| 165 |
|
} |
| 166 |
|
gp = NULL; |
| 167 |
|
while (*tp && (gp = f->fg[*tp++&0xff]) == NULL) { |
| 169 |
|
*sp = 0; |
| 170 |
|
} |
| 171 |
|
} |
| 172 |
< |
linelen += *sp; |
| 172 |
> |
linelen += *sp += cis; |
| 173 |
|
return(linelen); |
| 174 |
|
} |
| 175 |
|
|
| 176 |
|
|
| 177 |
+ |
int |
| 178 |
|
proptext(sp, tp, f, cis, nsi) /* space line proportionally */ |
| 179 |
|
short *sp; /* returned character spacing */ |
| 180 |
|
char *tp; /* text line */ |
| 182 |
|
int cis; /* target intercharacter spacing */ |
| 183 |
|
int nsi; /* minimum number of spaces for indent */ |
| 184 |
|
{ |
| 185 |
+ |
register char *end, *tab; |
| 186 |
+ |
GLYPH *gp; |
| 187 |
+ |
short *nsp; |
| 188 |
+ |
int alen, len, width; |
| 189 |
+ |
/* start by squeezing it */ |
| 190 |
+ |
squeeztext(sp, tp, f, cis); |
| 191 |
+ |
/* now, realign spacing */ |
| 192 |
+ |
len = 0; |
| 193 |
+ |
width = alen = *sp++; |
| 194 |
+ |
while (*tp) { |
| 195 |
+ |
nsp = sp; |
| 196 |
+ |
for (end = tp; *end; end = tab) { |
| 197 |
+ |
tab = end + 1; |
| 198 |
+ |
alen += *nsp++; |
| 199 |
+ |
if (f->fg[*end&0xff]) { |
| 200 |
+ |
while ((gp = f->fg[*tab&0xff]) != NULL && |
| 201 |
+ |
gp->nverts == 0) { /* tab in */ |
| 202 |
+ |
alen += *nsp++; |
| 203 |
+ |
tab++; |
| 204 |
+ |
} |
| 205 |
+ |
len += tab - end; |
| 206 |
+ |
} |
| 207 |
+ |
if (tab - end > nsi) |
| 208 |
+ |
break; |
| 209 |
+ |
} |
| 210 |
+ |
len *= f->mwidth + cis; /* compute target length */ |
| 211 |
+ |
width += len; |
| 212 |
+ |
len -= alen; /* necessary adjustment */ |
| 213 |
+ |
while (sp < nsp) { |
| 214 |
+ |
alen = len/(nsp-sp); |
| 215 |
+ |
*sp++ += alen; |
| 216 |
+ |
len -= alen; |
| 217 |
+ |
} |
| 218 |
+ |
len = 0; |
| 219 |
+ |
alen = 0; |
| 220 |
+ |
tp = tab; |
| 221 |
+ |
} |
| 222 |
+ |
return(width); |
| 223 |
|
} |
| 156 |
– |
|
| 157 |
– |
|