16 |
|
|
17 |
|
#include "font.h" |
18 |
|
|
19 |
+ |
#ifndef SSS |
20 |
+ |
#define SSS 3 /* super-sample size */ |
21 |
+ |
#endif |
22 |
+ |
|
23 |
|
#define MAXLINE 512 /* longest allowable line */ |
24 |
|
|
25 |
|
#ifndef DEFPATH |
31 |
|
|
32 |
|
char *fontfile = "helvet.fnt"; /* our font file */ |
33 |
|
|
34 |
< |
COLR bgcolr = WHTCOLR; /* background color */ |
35 |
< |
COLR fgcolr = BLKCOLR; /* foreground color */ |
34 |
> |
COLOR bgcolor = WHTCOLOR; /* background color */ |
35 |
> |
COLOR fgcolor = BLKCOLOR; /* foreground color */ |
36 |
|
|
37 |
|
int direct = 'r'; /* direction (right, up, left, down) */ |
38 |
|
|
39 |
< |
int cheight = 32; /* character height */ |
39 |
> |
int cheight = 32*SSS; /* character height */ |
40 |
|
double aspect = 1.67; /* height/width character aspect */ |
41 |
+ |
double spacing = 0.0; /* character spacing */ |
42 |
|
int cwidth; /* computed character width */ |
43 |
|
|
44 |
|
unsigned char *ourbitmap; /* our output bitmap */ |
51 |
|
#define clrbit(x,y) bitop(x,y,&=~) |
52 |
|
#define tglbit(x,y) bitop(x,y,^=) |
53 |
|
|
49 |
– |
typedef unsigned char GLYPH; |
50 |
– |
|
54 |
|
FONT *ourfont; /* our font */ |
55 |
|
|
56 |
|
char *libpath; /* library search path */ |
57 |
|
|
58 |
|
typedef struct line { |
59 |
|
char *s; /* line w/o LF */ |
60 |
+ |
short *sp; /* character spacing */ |
61 |
|
struct line *next; /* next line up */ |
62 |
|
} LINE; |
63 |
|
|
64 |
|
LINE *ourtext; /* our text */ |
65 |
|
int nlines, maxline; /* text dimensions */ |
66 |
+ |
int maxwidth; /* maximum line width (dvi) */ |
67 |
|
|
68 |
|
extern char *getenv(); |
64 |
– |
extern char *malloc(), *calloc(); |
69 |
|
|
70 |
|
|
71 |
|
main(argc, argv) |
79 |
|
case 'c': /* color */ |
80 |
|
switch (argv[an][2]) { |
81 |
|
case 'f': /* foreground */ |
82 |
< |
setcolr(fgcolr, atof(argv[an+1]), |
82 |
> |
setcolor(fgcolor, atof(argv[an+1]), |
83 |
|
atof(argv[an+2]), |
84 |
|
atof(argv[an+3])); |
85 |
|
an += 3; |
86 |
|
break; |
87 |
|
case 'b': /* background */ |
88 |
< |
setcolr(bgcolr, atof(argv[an+1]), |
88 |
> |
setcolor(bgcolor, atof(argv[an+1]), |
89 |
|
atof(argv[an+2]), |
90 |
|
atof(argv[an+3])); |
91 |
|
an += 3; |
110 |
|
} |
111 |
|
break; |
112 |
|
case 'h': /* height of characters */ |
113 |
< |
cheight = atoi(argv[++an]); |
113 |
> |
cheight = atoi(argv[++an])*SSS; |
114 |
|
break; |
115 |
|
case 'a': /* aspect ratio */ |
116 |
|
aspect = atof(argv[++an]); |
117 |
|
break; |
118 |
+ |
case 's': /* spacing */ |
119 |
+ |
spacing = atof(argv[++an]); |
120 |
+ |
break; |
121 |
|
default:; |
122 |
|
unkopt: |
123 |
|
fprintf(stderr, "%s: unknown option: %s\n", |
124 |
|
argv[0], argv[an]); |
125 |
|
exit(1); |
126 |
|
} |
127 |
+ |
/* load font file */ |
128 |
+ |
if ((libpath = getenv(ULIBVAR)) == NULL) |
129 |
+ |
libpath = DEFPATH; |
130 |
+ |
ourfont = getfont(fontfile); |
131 |
|
/* get text */ |
132 |
|
if (an == argc) |
133 |
|
gettext(stdin); |
136 |
|
|
137 |
|
/* create bit map */ |
138 |
|
makemap(); |
128 |
– |
/* load font file */ |
129 |
– |
if ((libpath = getenv(ULIBVAR)) == NULL) |
130 |
– |
libpath = DEFPATH; |
131 |
– |
ourfont = getfont(fontfile); |
139 |
|
/* convert text to bitmap */ |
140 |
|
maptext(); |
141 |
|
/* print header */ |
153 |
|
{ |
154 |
|
cwidth = cheight/aspect + 0.5; |
155 |
|
if (direct == 'r' || direct == 'l') { |
156 |
< |
xsiz = maxline*cwidth; |
156 |
> |
xsiz = (long)maxwidth*cwidth >> 8; |
157 |
|
ysiz = nlines*cheight; |
158 |
|
} else { /* reverse orientation */ |
159 |
|
xsiz = nlines*cheight; |
160 |
< |
ysiz = maxline*cwidth; |
160 |
> |
ysiz = (long)maxwidth*cwidth >> 8; |
161 |
|
} |
162 |
+ |
if (xsiz % SSS) |
163 |
+ |
xsiz += SSS - xsiz%SSS; |
164 |
+ |
if (ysiz % SSS) |
165 |
+ |
ysiz += SSS - ysiz%SSS; |
166 |
|
xdim = (xsiz+7)/8; |
167 |
< |
ourbitmap = (BYTE *)calloc(ysiz, xdim); |
168 |
< |
if (ourbitmap == NULL) { |
169 |
< |
fprintf(stderr, "out of memory in makemap\n"); |
170 |
< |
exit(1); |
160 |
< |
} |
167 |
> |
ourbitmap = (BYTE *)bmalloc(ysiz*xdim); |
168 |
> |
if (ourbitmap == NULL) |
169 |
> |
error(SYSTEM, "Out of memory in makemap"); |
170 |
> |
bzero((char *)ourbitmap, ysiz*xdim); |
171 |
|
} |
172 |
|
|
173 |
|
|
180 |
|
int len; |
181 |
|
|
182 |
|
maxline = 0; |
183 |
+ |
maxwidth = 0; |
184 |
|
nlines = 0; |
185 |
|
while (fgets(buf, MAXLINE, fp) != NULL) { |
186 |
|
curl = (LINE *)malloc(sizeof(LINE)); |
187 |
|
if (curl == NULL) |
188 |
|
goto memerr; |
189 |
|
len = strlen(buf); |
190 |
< |
curl->s = malloc(len--); |
191 |
< |
if (curl->s == NULL) |
190 |
> |
curl->s = malloc(len); |
191 |
> |
curl->sp = (short *)malloc(sizeof(short)*len--); |
192 |
> |
if (curl->s == NULL | curl->sp == NULL) |
193 |
|
goto memerr; |
194 |
+ |
if (len > maxline) |
195 |
+ |
maxline = len; |
196 |
|
strncpy(curl->s, buf, len); |
197 |
|
curl->s[len] = '\0'; |
198 |
+ |
if (spacing < -1./256.) |
199 |
+ |
len = squeeztext(curl->sp, curl->s, ourfont, |
200 |
+ |
(int)(spacing*-256.0)); |
201 |
+ |
else if (spacing > 1./256.) |
202 |
+ |
len = proptext(curl->sp, curl->s, ourfont, |
203 |
+ |
(int)(spacing*256.0), 3); |
204 |
+ |
else |
205 |
+ |
len = uniftext(curl->sp, curl->s, ourfont); |
206 |
+ |
if (len > maxwidth) |
207 |
+ |
maxwidth = len; |
208 |
|
curl->next = ourtext; |
209 |
|
ourtext = curl; |
186 |
– |
if (len > maxline) |
187 |
– |
maxline = len; |
210 |
|
nlines++; |
211 |
|
} |
212 |
|
return; |
213 |
|
memerr: |
214 |
< |
fprintf(stderr, "out of memory in gettext\n"); |
193 |
< |
exit(1); |
214 |
> |
error(SYSTEM, "Out of memory in gettext"); |
215 |
|
} |
216 |
|
|
217 |
|
|
235 |
|
*--cp = '\0'; |
236 |
|
ourtext->next = NULL; |
237 |
|
maxline = strlen(ourtext->s); |
238 |
+ |
ourtext->sp = (short *)malloc(sizeof(short)*(maxline+1)); |
239 |
+ |
if (ourtext->sp == NULL) |
240 |
+ |
goto memerr; |
241 |
+ |
if (spacing < 0.0) |
242 |
+ |
maxwidth = squeeztext(ourtext->sp, ourtext->s, ourfont, |
243 |
+ |
(int)(spacing*-256.0)); |
244 |
+ |
else if (spacing > 0.0) |
245 |
+ |
maxwidth = proptext(ourtext->sp, ourtext->s, ourfont, |
246 |
+ |
(int)(spacing*256.0), 3); |
247 |
+ |
else |
248 |
+ |
maxwidth = uniftext(ourtext->sp, ourtext->s, ourfont); |
249 |
|
nlines = 1; |
250 |
|
return; |
251 |
|
memerr: |
252 |
< |
fprintf(stderr, "out of memory in arg_text\n"); |
221 |
< |
exit(1); |
252 |
> |
error(SYSTEM, "Out of memory in arg_text"); |
253 |
|
} |
254 |
|
|
255 |
|
|
256 |
|
maptext() /* map our text */ |
257 |
|
{ |
258 |
|
register LINE *curl; |
259 |
< |
int l; |
260 |
< |
register int c; |
259 |
> |
int l, len; |
260 |
> |
register int i, c; |
261 |
|
|
262 |
< |
for (l = 0, curl = ourtext; curl != NULL; l++, curl = curl->next) |
263 |
< |
for (c = strlen(curl->s)-1; c >= 0; c--) |
264 |
< |
mapglyph(ourfont->fg[curl->s[c]&0xff], c, l); |
262 |
> |
for (l = 0, curl = ourtext; curl != NULL; l += 256, curl = curl->next) { |
263 |
> |
len = strlen(curl->s); c = 0; |
264 |
> |
for (i = 0; i < len; i++) { |
265 |
> |
c += curl->sp[i]; |
266 |
> |
mapglyph(ourfont->fg[curl->s[i]&0xff], c, l); |
267 |
> |
} |
268 |
> |
} |
269 |
|
} |
270 |
|
|
271 |
|
|
280 |
|
if (gl == NULL) |
281 |
|
return; |
282 |
|
|
248 |
– |
tx0 <<= 8; ty0 <<= 8; |
283 |
|
n = gl->nverts; |
284 |
|
gp = gvlist(gl); |
285 |
|
mapcoord(p0, gp[2*n-2]+tx0, gp[2*n-1]+ty0); |
359 |
|
writemap(fp) /* write out bitmap */ |
360 |
|
FILE *fp; |
361 |
|
{ |
362 |
+ |
COLR pixval[SSS*SSS+1]; /* possible pixel values */ |
363 |
+ |
COLOR ctmp0, ctmp1; |
364 |
+ |
double d; |
365 |
|
COLR *scanout; |
366 |
< |
int y; |
367 |
< |
register int x; |
366 |
> |
int x, y; |
367 |
> |
register int i, j; |
368 |
> |
int cnt; |
369 |
|
register int inglyph; |
370 |
|
|
371 |
< |
fprintf(fp, "-Y %d +X %d\n", ysiz, xsiz); |
371 |
> |
fprintf(fp, "-Y %d +X %d\n", ysiz/SSS, xsiz/SSS); |
372 |
|
|
373 |
< |
scanout = (COLR *)malloc(xsiz*sizeof(COLR)); |
374 |
< |
if (scanout == NULL) { |
375 |
< |
fprintf(stderr, "out of memory in writemap\n"); |
376 |
< |
exit(1); |
373 |
> |
scanout = (COLR *)malloc(xsiz/SSS*sizeof(COLR)); |
374 |
> |
if (scanout == NULL) |
375 |
> |
error(SYSTEM, "Out of memory in writemap"); |
376 |
> |
for (i = 0; i <= SSS*SSS; i++) { /* compute possible values */ |
377 |
> |
copycolor(ctmp0, fgcolor); |
378 |
> |
d = (double)i/(SSS*SSS); |
379 |
> |
scalecolor(ctmp0, d); |
380 |
> |
copycolor(ctmp1, bgcolor); |
381 |
> |
d = 1.0 - d; |
382 |
> |
scalecolor(ctmp1, d); |
383 |
> |
addcolor(ctmp0, ctmp1); |
384 |
> |
setcolr(pixval[i], colval(ctmp0,RED), |
385 |
> |
colval(ctmp0,GRN), colval(ctmp0,BLU)); |
386 |
|
} |
387 |
< |
for (y = ysiz-1; y >= 0; y--) { |
387 |
> |
for (y = ysiz/SSS-1; y >= 0; y--) { |
388 |
|
inglyph = 0; |
389 |
< |
for (x = 0; x < xsiz; x++) { |
390 |
< |
if (tstbit(x, y)) |
391 |
< |
inglyph ^= 1; |
392 |
< |
if (inglyph) |
393 |
< |
copycolr(scanout[x], fgcolr); |
394 |
< |
else |
395 |
< |
copycolr(scanout[x], bgcolr); |
389 |
> |
for (x = 0; x < xsiz/SSS; x++) { |
390 |
> |
cnt = 0; |
391 |
> |
for (j = 0; j < SSS; j++) |
392 |
> |
for (i = 0; i < SSS; i++) { |
393 |
> |
if (tstbit(x*SSS+i, y*SSS+j)) |
394 |
> |
inglyph ^= 1<<j; |
395 |
> |
if (inglyph & 1<<j) |
396 |
> |
cnt++; |
397 |
> |
} |
398 |
> |
copycolr(scanout[x], pixval[cnt]); |
399 |
|
} |
400 |
< |
if (fwritecolrs(scanout, xsiz, fp) < 0) { |
400 |
> |
if (fwritecolrs(scanout, xsiz/SSS, fp) < 0) { |
401 |
|
fprintf(stderr, "write error in writemap\n"); |
402 |
|
exit(1); |
403 |
|
} |