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 |
> |
#include "paths.h" |
20 |
|
|
21 |
< |
#define MAXLINE 512 /* longest allowable line */ |
22 |
< |
|
23 |
< |
#ifndef DEFPATH |
24 |
< |
#define DEFPATH ":/usr/local/lib/ray" |
21 |
> |
#ifndef SSS |
22 |
> |
#define SSS 3 /* super-sample size */ |
23 |
|
#endif |
26 |
– |
#ifndef ULIBVAR |
27 |
– |
#define ULIBVAR "RAYPATH" |
28 |
– |
#endif |
24 |
|
|
25 |
+ |
#define MAXLINE 512 /* longest allowable line */ |
26 |
+ |
|
27 |
|
char *fontfile = "helvet.fnt"; /* our font file */ |
28 |
|
|
29 |
< |
COLR bgcolr = WHTCOLR; /* background color */ |
30 |
< |
COLR fgcolr = BLKCOLR; /* foreground color */ |
29 |
> |
COLOR bgcolor = WHTCOLOR; /* background color */ |
30 |
> |
COLOR fgcolor = BLKCOLOR; /* foreground color */ |
31 |
|
|
32 |
|
int direct = 'r'; /* direction (right, up, left, down) */ |
33 |
|
|
34 |
< |
int cheight = 32; /* character height */ |
35 |
< |
double aspect = 1.67; /* height/width character aspect */ |
34 |
> |
int cheight = 32*SSS; /* character height */ |
35 |
> |
double aspect = 1.67; /* height/width character aspect */ |
36 |
> |
double spacing = 0.0; /* character spacing */ |
37 |
|
int cwidth; /* computed character width */ |
38 |
|
|
39 |
|
unsigned char *ourbitmap; /* our output bitmap */ |
40 |
|
int xsiz, ysiz; /* bitmap dimensions */ |
41 |
|
int xdim; /* size of horizontal scan (bytes) */ |
42 |
|
|
43 |
< |
#define bitop(x,y,op) (ourbitmap[(y)*xdim+((x)>>3)] op (1<<((x)&7))) |
44 |
< |
#define tstbit(x,y) bitop(x,y,&) |
45 |
< |
#define setbit(x,y) bitop(x,y,|=) |
46 |
< |
#define clrbit(x,y) bitop(x,y,&=~) |
47 |
< |
#define tglbit(x,y) bitop(x,y,^=) |
43 |
> |
#define bitop(x,y,op) (ourbitmap[(y)*xdim+((x)>>3)] op (1<<((x)&7))) |
44 |
> |
#define tstbit(x,y) bitop(x,y,&) |
45 |
> |
#define setbit(x,y) bitop(x,y,|=) |
46 |
> |
#define clrbit(x,y) bitop(x,y,&=~) |
47 |
> |
#define tglbit(x,y) bitop(x,y,^=) |
48 |
|
|
49 |
|
FONT *ourfont; /* our font */ |
50 |
|
|
60 |
|
int nlines, maxline; /* text dimensions */ |
61 |
|
int maxwidth; /* maximum line width (dvi) */ |
62 |
|
|
65 |
– |
extern char *getenv(); |
66 |
– |
extern char *malloc(), *calloc(); |
63 |
|
|
68 |
– |
|
64 |
|
main(argc, argv) |
65 |
|
int argc; |
66 |
|
char *argv[]; |
67 |
|
{ |
68 |
|
int an; |
69 |
< |
|
69 |
> |
#ifdef MSDOS |
70 |
> |
setmode(fileno(stdout), O_BINARY); |
71 |
> |
#endif |
72 |
|
for (an = 1; an < argc && argv[an][0] == '-'; an++) |
73 |
|
switch (argv[an][1]) { |
74 |
|
case 'c': /* color */ |
75 |
|
switch (argv[an][2]) { |
76 |
|
case 'f': /* foreground */ |
77 |
< |
setcolr(fgcolr, atof(argv[an+1]), |
77 |
> |
setcolor(fgcolor, atof(argv[an+1]), |
78 |
|
atof(argv[an+2]), |
79 |
|
atof(argv[an+3])); |
80 |
|
an += 3; |
81 |
|
break; |
82 |
|
case 'b': /* background */ |
83 |
< |
setcolr(bgcolr, atof(argv[an+1]), |
83 |
> |
setcolor(bgcolor, atof(argv[an+1]), |
84 |
|
atof(argv[an+2]), |
85 |
|
atof(argv[an+3])); |
86 |
|
an += 3; |
104 |
|
goto unkopt; |
105 |
|
} |
106 |
|
break; |
107 |
+ |
case 'x': /* x resolution */ |
108 |
+ |
xsiz = atoi(argv[++an])*SSS; |
109 |
+ |
break; |
110 |
+ |
case 'y': |
111 |
+ |
ysiz = atoi(argv[++an])*SSS; |
112 |
+ |
break; |
113 |
|
case 'h': /* height of characters */ |
114 |
< |
cheight = atoi(argv[++an]); |
114 |
> |
cheight = atoi(argv[++an])*SSS; |
115 |
|
break; |
116 |
|
case 'a': /* aspect ratio */ |
117 |
|
aspect = atof(argv[++an]); |
118 |
|
break; |
119 |
+ |
case 's': /* spacing */ |
120 |
+ |
spacing = atof(argv[++an]); |
121 |
+ |
break; |
122 |
|
default:; |
123 |
|
unkopt: |
124 |
|
fprintf(stderr, "%s: unknown option: %s\n", |
152 |
|
|
153 |
|
makemap() /* create the bit map */ |
154 |
|
{ |
155 |
< |
cwidth = cheight/aspect + 0.5; |
155 |
> |
double pictaspect; |
156 |
> |
|
157 |
|
if (direct == 'r' || direct == 'l') { |
158 |
< |
xsiz = maxline*cwidth; |
159 |
< |
ysiz = nlines*cheight; |
158 |
> |
if (xsiz <= 0) { |
159 |
> |
cwidth = cheight/aspect + 0.5; |
160 |
> |
xsiz = (long)maxwidth*cwidth >> 8; |
161 |
> |
ysiz = nlines*cheight; |
162 |
> |
} else if (aspect > FTINY) { |
163 |
> |
if (ysiz <= 0) |
164 |
> |
ysiz = cheight*nlines; |
165 |
> |
pictaspect = 256*nlines*aspect/maxwidth; |
166 |
> |
if (pictaspect*xsiz < ysiz) |
167 |
> |
ysiz = pictaspect*xsiz + 0.5; |
168 |
> |
else |
169 |
> |
xsiz = ysiz/pictaspect + 0.5; |
170 |
> |
cheight = ysiz/nlines; |
171 |
> |
cwidth = cheight/aspect + 0.5; |
172 |
> |
} else { |
173 |
> |
if (ysiz <= 0) |
174 |
> |
ysiz = cheight*nlines; |
175 |
> |
pictaspect = (double)ysiz/xsiz; |
176 |
> |
aspect = pictaspect*maxwidth/(256*nlines); |
177 |
> |
cheight = ysiz/nlines; |
178 |
> |
cwidth = cheight/aspect + 0.5; |
179 |
> |
} |
180 |
|
} else { /* reverse orientation */ |
181 |
< |
xsiz = nlines*cheight; |
182 |
< |
ysiz = maxline*cwidth; |
181 |
> |
if (ysiz <= 0) { |
182 |
> |
cwidth = cheight/aspect + 0.5; |
183 |
> |
xsiz = nlines*cheight; |
184 |
> |
ysiz = (long)maxwidth*cwidth >> 8; |
185 |
> |
} else if (aspect > FTINY) { |
186 |
> |
if (xsiz <= 0) |
187 |
> |
xsiz = cheight*nlines; |
188 |
> |
pictaspect = maxwidth/(256*nlines*aspect); |
189 |
> |
if (pictaspect*xsiz < ysiz) |
190 |
> |
ysiz = pictaspect*xsiz + 0.5; |
191 |
> |
else |
192 |
> |
xsiz = ysiz/pictaspect + 0.5; |
193 |
> |
cheight = xsiz/nlines; |
194 |
> |
cwidth = cheight/aspect + 0.5; |
195 |
> |
} else { |
196 |
> |
if (xsiz <= 0) |
197 |
> |
xsiz = cheight*nlines; |
198 |
> |
pictaspect = (double)ysiz/xsiz; |
199 |
> |
aspect = maxwidth/(256*nlines*pictaspect); |
200 |
> |
cheight = xsiz/nlines; |
201 |
> |
cwidth = cheight/aspect + 0.5; |
202 |
> |
} |
203 |
|
} |
204 |
+ |
if (xsiz % SSS) |
205 |
+ |
xsiz += SSS - xsiz%SSS; |
206 |
+ |
if (ysiz % SSS) |
207 |
+ |
ysiz += SSS - ysiz%SSS; |
208 |
|
xdim = (xsiz+7)/8; |
209 |
< |
ourbitmap = (BYTE *)calloc(ysiz, xdim); |
210 |
< |
if (ourbitmap == NULL) { |
211 |
< |
fprintf(stderr, "out of memory in makemap\n"); |
212 |
< |
exit(1); |
162 |
< |
} |
209 |
> |
ourbitmap = (BYTE *)bmalloc(ysiz*xdim); |
210 |
> |
if (ourbitmap == NULL) |
211 |
> |
error(SYSTEM, "Out of memory in makemap"); |
212 |
> |
bzero((char *)ourbitmap, ysiz*xdim); |
213 |
|
} |
214 |
|
|
215 |
|
|
237 |
|
maxline = len; |
238 |
|
strncpy(curl->s, buf, len); |
239 |
|
curl->s[len] = '\0'; |
240 |
< |
len = uniftext(curl->sp, curl->s, ourfont); |
240 |
> |
if (spacing < -1./256.) |
241 |
> |
len = squeeztext(curl->sp, curl->s, ourfont, |
242 |
> |
(int)(spacing*-256.0)); |
243 |
> |
else if (spacing > 1./256.) |
244 |
> |
len = proptext(curl->sp, curl->s, ourfont, |
245 |
> |
(int)(spacing*256.0), 3); |
246 |
> |
else |
247 |
> |
len = uniftext(curl->sp, curl->s, ourfont); |
248 |
|
if (len > maxwidth) |
249 |
|
maxwidth = len; |
250 |
|
curl->next = ourtext; |
253 |
|
} |
254 |
|
return; |
255 |
|
memerr: |
256 |
< |
fprintf(stderr, "out of memory in gettext\n"); |
200 |
< |
exit(1); |
256 |
> |
error(SYSTEM, "Out of memory in gettext"); |
257 |
|
} |
258 |
|
|
259 |
|
|
280 |
|
ourtext->sp = (short *)malloc(sizeof(short)*(maxline+1)); |
281 |
|
if (ourtext->sp == NULL) |
282 |
|
goto memerr; |
283 |
< |
maxwidth = uniftext(ourtext->sp, ourtext->s, ourfont); |
283 |
> |
if (spacing < 0.0) |
284 |
> |
maxwidth = squeeztext(ourtext->sp, ourtext->s, ourfont, |
285 |
> |
(int)(spacing*-256.0)); |
286 |
> |
else if (spacing > 0.0) |
287 |
> |
maxwidth = proptext(ourtext->sp, ourtext->s, ourfont, |
288 |
> |
(int)(spacing*256.0), 3); |
289 |
> |
else |
290 |
> |
maxwidth = uniftext(ourtext->sp, ourtext->s, ourfont); |
291 |
|
nlines = 1; |
292 |
|
return; |
293 |
|
memerr: |
294 |
< |
fprintf(stderr, "out of memory in arg_text\n"); |
232 |
< |
exit(1); |
294 |
> |
error(SYSTEM, "Out of memory in arg_text"); |
295 |
|
} |
296 |
|
|
297 |
|
|
401 |
|
writemap(fp) /* write out bitmap */ |
402 |
|
FILE *fp; |
403 |
|
{ |
404 |
+ |
COLR pixval[SSS*SSS+1]; /* possible pixel values */ |
405 |
+ |
COLOR ctmp0, ctmp1; |
406 |
+ |
double d; |
407 |
|
COLR *scanout; |
408 |
< |
int y; |
409 |
< |
register int x; |
408 |
> |
int x, y; |
409 |
> |
register int i, j; |
410 |
> |
int cnt; |
411 |
|
register int inglyph; |
412 |
|
|
413 |
< |
fprintf(fp, "-Y %d +X %d\n", ysiz, xsiz); |
413 |
> |
fprintf(fp, "-Y %d +X %d\n", ysiz/SSS, xsiz/SSS); |
414 |
|
|
415 |
< |
scanout = (COLR *)malloc(xsiz*sizeof(COLR)); |
416 |
< |
if (scanout == NULL) { |
417 |
< |
fprintf(stderr, "out of memory in writemap\n"); |
418 |
< |
exit(1); |
415 |
> |
scanout = (COLR *)malloc(xsiz/SSS*sizeof(COLR)); |
416 |
> |
if (scanout == NULL) |
417 |
> |
error(SYSTEM, "Out of memory in writemap"); |
418 |
> |
for (i = 0; i <= SSS*SSS; i++) { /* compute possible values */ |
419 |
> |
copycolor(ctmp0, fgcolor); |
420 |
> |
d = (double)i/(SSS*SSS); |
421 |
> |
scalecolor(ctmp0, d); |
422 |
> |
copycolor(ctmp1, bgcolor); |
423 |
> |
d = 1.0 - d; |
424 |
> |
scalecolor(ctmp1, d); |
425 |
> |
addcolor(ctmp0, ctmp1); |
426 |
> |
setcolr(pixval[i], colval(ctmp0,RED), |
427 |
> |
colval(ctmp0,GRN), colval(ctmp0,BLU)); |
428 |
|
} |
429 |
< |
for (y = ysiz-1; y >= 0; y--) { |
429 |
> |
for (y = ysiz/SSS-1; y >= 0; y--) { |
430 |
|
inglyph = 0; |
431 |
< |
for (x = 0; x < xsiz; x++) { |
432 |
< |
if (tstbit(x, y)) |
433 |
< |
inglyph ^= 1; |
434 |
< |
if (inglyph) |
435 |
< |
copycolr(scanout[x], fgcolr); |
436 |
< |
else |
437 |
< |
copycolr(scanout[x], bgcolr); |
431 |
> |
for (x = 0; x < xsiz/SSS; x++) { |
432 |
> |
cnt = 0; |
433 |
> |
for (j = 0; j < SSS; j++) |
434 |
> |
for (i = 0; i < SSS; i++) { |
435 |
> |
if (tstbit(x*SSS+i, y*SSS+j)) |
436 |
> |
inglyph ^= 1<<j; |
437 |
> |
if (inglyph & 1<<j) |
438 |
> |
cnt++; |
439 |
> |
} |
440 |
> |
copycolr(scanout[x], pixval[cnt]); |
441 |
|
} |
442 |
< |
if (fwritecolrs(scanout, xsiz, fp) < 0) { |
442 |
> |
if (fwritecolrs(scanout, xsiz/SSS, fp) < 0) { |
443 |
|
fprintf(stderr, "write error in writemap\n"); |
444 |
|
exit(1); |
445 |
|
} |