1 |
< |
/* Copyright (c) 1991 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
16 |
|
|
17 |
|
#include "font.h" |
18 |
|
|
19 |
< |
#define SSS 2 /* super-sample size */ |
19 |
> |
#ifndef SSS |
20 |
> |
#define SSS 3 /* super-sample size */ |
21 |
> |
#endif |
22 |
|
|
23 |
|
#define MAXLINE 512 /* longest allowable line */ |
24 |
|
|
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 */ |
66 |
|
int maxwidth; /* maximum line width (dvi) */ |
67 |
|
|
68 |
|
extern char *getenv(); |
66 |
– |
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; |
109 |
|
goto unkopt; |
110 |
|
} |
111 |
|
break; |
112 |
+ |
case 'x': /* x resolution */ |
113 |
+ |
xsiz = atoi(argv[++an])*SSS; |
114 |
+ |
break; |
115 |
+ |
case 'y': |
116 |
+ |
ysiz = atoi(argv[++an])*SSS; |
117 |
+ |
break; |
118 |
|
case 'h': /* height of characters */ |
119 |
< |
cheight = atoi(argv[++an]); |
119 |
> |
cheight = atoi(argv[++an])*SSS; |
120 |
|
break; |
121 |
|
case 'a': /* aspect ratio */ |
122 |
|
aspect = atof(argv[++an]); |
123 |
|
break; |
124 |
+ |
case 's': /* spacing */ |
125 |
+ |
spacing = atof(argv[++an]); |
126 |
+ |
break; |
127 |
|
default:; |
128 |
|
unkopt: |
129 |
|
fprintf(stderr, "%s: unknown option: %s\n", |
157 |
|
|
158 |
|
makemap() /* create the bit map */ |
159 |
|
{ |
160 |
< |
cwidth = cheight/aspect + 0.5; |
160 |
> |
double pictaspect; |
161 |
> |
|
162 |
|
if (direct == 'r' || direct == 'l') { |
163 |
< |
xsiz = maxline*cwidth; |
164 |
< |
ysiz = nlines*cheight; |
163 |
> |
if (xsiz <= 0) { |
164 |
> |
cwidth = cheight/aspect + 0.5; |
165 |
> |
xsiz = (long)maxwidth*cwidth >> 8; |
166 |
> |
ysiz = nlines*cheight; |
167 |
> |
} else if (aspect > FTINY) { |
168 |
> |
if (ysiz <= 0) |
169 |
> |
ysiz = cheight*nlines; |
170 |
> |
pictaspect = 256*nlines*aspect/maxwidth; |
171 |
> |
if (pictaspect*xsiz < ysiz) |
172 |
> |
ysiz = pictaspect*xsiz + 0.5; |
173 |
> |
else |
174 |
> |
xsiz = ysiz/pictaspect + 0.5; |
175 |
> |
cheight = ysiz/nlines; |
176 |
> |
cwidth = cheight/aspect + 0.5; |
177 |
> |
} else { |
178 |
> |
if (ysiz <= 0) |
179 |
> |
ysiz = cheight*nlines; |
180 |
> |
pictaspect = (double)ysiz/xsiz; |
181 |
> |
aspect = pictaspect*maxwidth/(256*nlines); |
182 |
> |
cheight = ysiz/nlines; |
183 |
> |
cwidth = cheight/aspect + 0.5; |
184 |
> |
} |
185 |
|
} else { /* reverse orientation */ |
186 |
< |
xsiz = nlines*cheight; |
187 |
< |
ysiz = maxline*cwidth; |
186 |
> |
if (ysiz <= 0) { |
187 |
> |
cwidth = cheight/aspect + 0.5; |
188 |
> |
xsiz = nlines*cheight; |
189 |
> |
ysiz = (long)maxwidth*cwidth >> 8; |
190 |
> |
} else if (aspect > FTINY) { |
191 |
> |
if (xsiz <= 0) |
192 |
> |
xsiz = cheight*nlines; |
193 |
> |
pictaspect = maxwidth/(256*nlines*aspect); |
194 |
> |
if (pictaspect*xsiz < ysiz) |
195 |
> |
ysiz = pictaspect*xsiz + 0.5; |
196 |
> |
else |
197 |
> |
xsiz = ysiz/pictaspect + 0.5; |
198 |
> |
cheight = xsiz/nlines; |
199 |
> |
cwidth = cheight/aspect + 0.5; |
200 |
> |
} else { |
201 |
> |
if (xsiz <= 0) |
202 |
> |
xsiz = cheight*nlines; |
203 |
> |
pictaspect = (double)ysiz/xsiz; |
204 |
> |
aspect = maxwidth/(256*nlines*pictaspect); |
205 |
> |
cheight = xsiz/nlines; |
206 |
> |
cwidth = cheight/aspect + 0.5; |
207 |
> |
} |
208 |
|
} |
209 |
+ |
if (xsiz % SSS) |
210 |
+ |
xsiz += SSS - xsiz%SSS; |
211 |
+ |
if (ysiz % SSS) |
212 |
+ |
ysiz += SSS - ysiz%SSS; |
213 |
|
xdim = (xsiz+7)/8; |
214 |
< |
ourbitmap = (BYTE *)calloc(ysiz, xdim); |
215 |
< |
if (ourbitmap == NULL) { |
216 |
< |
fprintf(stderr, "out of memory in makemap\n"); |
217 |
< |
exit(1); |
162 |
< |
} |
214 |
> |
ourbitmap = (BYTE *)bmalloc(ysiz*xdim); |
215 |
> |
if (ourbitmap == NULL) |
216 |
> |
error(SYSTEM, "Out of memory in makemap"); |
217 |
> |
bzero((char *)ourbitmap, ysiz*xdim); |
218 |
|
} |
219 |
|
|
220 |
|
|
242 |
|
maxline = len; |
243 |
|
strncpy(curl->s, buf, len); |
244 |
|
curl->s[len] = '\0'; |
245 |
< |
len = uniftext(curl->sp, curl->s, ourfont); |
245 |
> |
if (spacing < -1./256.) |
246 |
> |
len = squeeztext(curl->sp, curl->s, ourfont, |
247 |
> |
(int)(spacing*-256.0)); |
248 |
> |
else if (spacing > 1./256.) |
249 |
> |
len = proptext(curl->sp, curl->s, ourfont, |
250 |
> |
(int)(spacing*256.0), 3); |
251 |
> |
else |
252 |
> |
len = uniftext(curl->sp, curl->s, ourfont); |
253 |
|
if (len > maxwidth) |
254 |
|
maxwidth = len; |
255 |
|
curl->next = ourtext; |
258 |
|
} |
259 |
|
return; |
260 |
|
memerr: |
261 |
< |
fprintf(stderr, "out of memory in gettext\n"); |
200 |
< |
exit(1); |
261 |
> |
error(SYSTEM, "Out of memory in gettext"); |
262 |
|
} |
263 |
|
|
264 |
|
|
285 |
|
ourtext->sp = (short *)malloc(sizeof(short)*(maxline+1)); |
286 |
|
if (ourtext->sp == NULL) |
287 |
|
goto memerr; |
288 |
< |
maxwidth = uniftext(ourtext->sp, ourtext->s, ourfont); |
288 |
> |
if (spacing < 0.0) |
289 |
> |
maxwidth = squeeztext(ourtext->sp, ourtext->s, ourfont, |
290 |
> |
(int)(spacing*-256.0)); |
291 |
> |
else if (spacing > 0.0) |
292 |
> |
maxwidth = proptext(ourtext->sp, ourtext->s, ourfont, |
293 |
> |
(int)(spacing*256.0), 3); |
294 |
> |
else |
295 |
> |
maxwidth = uniftext(ourtext->sp, ourtext->s, ourfont); |
296 |
|
nlines = 1; |
297 |
|
return; |
298 |
|
memerr: |
299 |
< |
fprintf(stderr, "out of memory in arg_text\n"); |
232 |
< |
exit(1); |
299 |
> |
error(SYSTEM, "Out of memory in arg_text"); |
300 |
|
} |
301 |
|
|
302 |
|
|
406 |
|
writemap(fp) /* write out bitmap */ |
407 |
|
FILE *fp; |
408 |
|
{ |
409 |
+ |
COLR pixval[SSS*SSS+1]; /* possible pixel values */ |
410 |
+ |
COLOR ctmp0, ctmp1; |
411 |
+ |
double d; |
412 |
|
COLR *scanout; |
413 |
< |
int y; |
414 |
< |
register int x; |
413 |
> |
int x, y; |
414 |
> |
register int i, j; |
415 |
> |
int cnt; |
416 |
|
register int inglyph; |
417 |
|
|
418 |
< |
fprintf(fp, "-Y %d +X %d\n", ysiz, xsiz); |
418 |
> |
fprintf(fp, "-Y %d +X %d\n", ysiz/SSS, xsiz/SSS); |
419 |
|
|
420 |
< |
scanout = (COLR *)malloc(xsiz*sizeof(COLR)); |
421 |
< |
if (scanout == NULL) { |
422 |
< |
fprintf(stderr, "out of memory in writemap\n"); |
423 |
< |
exit(1); |
420 |
> |
scanout = (COLR *)malloc(xsiz/SSS*sizeof(COLR)); |
421 |
> |
if (scanout == NULL) |
422 |
> |
error(SYSTEM, "Out of memory in writemap"); |
423 |
> |
for (i = 0; i <= SSS*SSS; i++) { /* compute possible values */ |
424 |
> |
copycolor(ctmp0, fgcolor); |
425 |
> |
d = (double)i/(SSS*SSS); |
426 |
> |
scalecolor(ctmp0, d); |
427 |
> |
copycolor(ctmp1, bgcolor); |
428 |
> |
d = 1.0 - d; |
429 |
> |
scalecolor(ctmp1, d); |
430 |
> |
addcolor(ctmp0, ctmp1); |
431 |
> |
setcolr(pixval[i], colval(ctmp0,RED), |
432 |
> |
colval(ctmp0,GRN), colval(ctmp0,BLU)); |
433 |
|
} |
434 |
< |
for (y = ysiz-1; y >= 0; y--) { |
434 |
> |
for (y = ysiz/SSS-1; y >= 0; y--) { |
435 |
|
inglyph = 0; |
436 |
< |
for (x = 0; x < xsiz; x++) { |
437 |
< |
if (tstbit(x, y)) |
438 |
< |
inglyph ^= 1; |
439 |
< |
if (inglyph) |
440 |
< |
copycolr(scanout[x], fgcolr); |
441 |
< |
else |
442 |
< |
copycolr(scanout[x], bgcolr); |
436 |
> |
for (x = 0; x < xsiz/SSS; x++) { |
437 |
> |
cnt = 0; |
438 |
> |
for (j = 0; j < SSS; j++) |
439 |
> |
for (i = 0; i < SSS; i++) { |
440 |
> |
if (tstbit(x*SSS+i, y*SSS+j)) |
441 |
> |
inglyph ^= 1<<j; |
442 |
> |
if (inglyph & 1<<j) |
443 |
> |
cnt++; |
444 |
> |
} |
445 |
> |
copycolr(scanout[x], pixval[cnt]); |
446 |
|
} |
447 |
< |
if (fwritecolrs(scanout, xsiz, fp) < 0) { |
447 |
> |
if (fwritecolrs(scanout, xsiz/SSS, fp) < 0) { |
448 |
|
fprintf(stderr, "write error in writemap\n"); |
449 |
|
exit(1); |
450 |
|
} |