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 |
< |
#ifndef SSS |
20 |
< |
#define SSS 3 /* super-sample size */ |
19 |
> |
#ifndef SSS |
20 |
> |
#define SSS 3 /* super-sample size */ |
21 |
|
#endif |
22 |
|
|
23 |
< |
#define MAXLINE 512 /* longest allowable line */ |
23 |
> |
#define MAXLINE 512 /* longest allowable line */ |
24 |
|
|
25 |
– |
#ifndef DEFPATH |
26 |
– |
#define DEFPATH ":/usr/local/lib/ray" |
27 |
– |
#endif |
28 |
– |
#ifndef ULIBVAR |
29 |
– |
#define ULIBVAR "RAYPATH" |
30 |
– |
#endif |
31 |
– |
|
25 |
|
char *fontfile = "helvet.fnt"; /* our font file */ |
26 |
|
|
27 |
|
COLOR bgcolor = WHTCOLOR; /* background color */ |
30 |
|
int direct = 'r'; /* direction (right, up, left, down) */ |
31 |
|
|
32 |
|
int cheight = 32*SSS; /* character height */ |
33 |
< |
double aspect = 1.67; /* height/width character aspect */ |
33 |
> |
double aspect = 1.67; /* height/width character aspect */ |
34 |
> |
double spacing = 0.0; /* character spacing */ |
35 |
|
int cwidth; /* computed character width */ |
36 |
|
|
37 |
|
unsigned char *ourbitmap; /* our output bitmap */ |
38 |
|
int xsiz, ysiz; /* bitmap dimensions */ |
39 |
|
int xdim; /* size of horizontal scan (bytes) */ |
40 |
|
|
41 |
< |
#define bitop(x,y,op) (ourbitmap[(y)*xdim+((x)>>3)] op (1<<((x)&7))) |
42 |
< |
#define tstbit(x,y) bitop(x,y,&) |
43 |
< |
#define setbit(x,y) bitop(x,y,|=) |
44 |
< |
#define clrbit(x,y) bitop(x,y,&=~) |
45 |
< |
#define tglbit(x,y) bitop(x,y,^=) |
41 |
> |
#define bitop(x,y,op) (ourbitmap[(y)*xdim+((x)>>3)] op (1<<((x)&7))) |
42 |
> |
#define tstbit(x,y) bitop(x,y,&) |
43 |
> |
#define setbit(x,y) bitop(x,y,|=) |
44 |
> |
#define clrbit(x,y) bitop(x,y,&=~) |
45 |
> |
#define tglbit(x,y) bitop(x,y,^=) |
46 |
|
|
47 |
|
FONT *ourfont; /* our font */ |
48 |
|
|
55 |
– |
char *libpath; /* library search path */ |
56 |
– |
|
49 |
|
typedef struct line { |
50 |
|
char *s; /* line w/o LF */ |
51 |
|
short *sp; /* character spacing */ |
56 |
|
int nlines, maxline; /* text dimensions */ |
57 |
|
int maxwidth; /* maximum line width (dvi) */ |
58 |
|
|
67 |
– |
extern char *getenv(); |
68 |
– |
extern char *malloc(), *calloc(); |
59 |
|
|
70 |
– |
|
60 |
|
main(argc, argv) |
61 |
|
int argc; |
62 |
|
char *argv[]; |
63 |
|
{ |
64 |
|
int an; |
65 |
< |
|
65 |
> |
#ifdef MSDOS |
66 |
> |
setmode(fileno(stdout), O_BINARY); |
67 |
> |
#endif |
68 |
|
for (an = 1; an < argc && argv[an][0] == '-'; an++) |
69 |
|
switch (argv[an][1]) { |
70 |
|
case 'c': /* color */ |
100 |
|
goto unkopt; |
101 |
|
} |
102 |
|
break; |
103 |
+ |
case 'x': /* x resolution */ |
104 |
+ |
xsiz = atoi(argv[++an])*SSS; |
105 |
+ |
break; |
106 |
+ |
case 'y': |
107 |
+ |
ysiz = atoi(argv[++an])*SSS; |
108 |
+ |
break; |
109 |
|
case 'h': /* height of characters */ |
110 |
|
cheight = atoi(argv[++an])*SSS; |
111 |
|
break; |
112 |
|
case 'a': /* aspect ratio */ |
113 |
|
aspect = atof(argv[++an]); |
114 |
|
break; |
115 |
+ |
case 's': /* spacing */ |
116 |
+ |
spacing = atof(argv[++an]); |
117 |
+ |
break; |
118 |
|
default:; |
119 |
|
unkopt: |
120 |
|
fprintf(stderr, "%s: unknown option: %s\n", |
122 |
|
exit(1); |
123 |
|
} |
124 |
|
/* load font file */ |
125 |
– |
if ((libpath = getenv(ULIBVAR)) == NULL) |
126 |
– |
libpath = DEFPATH; |
125 |
|
ourfont = getfont(fontfile); |
126 |
|
/* get text */ |
127 |
|
if (an == argc) |
134 |
|
/* convert text to bitmap */ |
135 |
|
maptext(); |
136 |
|
/* print header */ |
137 |
+ |
newheader("RADIANCE", stdout); |
138 |
|
printargs(argc, argv, stdout); |
139 |
|
fputformat(COLRFMT, stdout); |
140 |
|
putchar('\n'); |
147 |
|
|
148 |
|
makemap() /* create the bit map */ |
149 |
|
{ |
150 |
< |
cwidth = cheight/aspect + 0.5; |
150 |
> |
double pictaspect; |
151 |
> |
|
152 |
|
if (direct == 'r' || direct == 'l') { |
153 |
< |
xsiz = (long)maxwidth*cwidth >> 8; |
154 |
< |
ysiz = nlines*cheight; |
153 |
> |
if (xsiz <= 0) { |
154 |
> |
cwidth = cheight/aspect + 0.5; |
155 |
> |
xsiz = (long)maxwidth*cwidth >> 8; |
156 |
> |
ysiz = nlines*cheight; |
157 |
> |
} else if (aspect > FTINY) { |
158 |
> |
if (ysiz <= 0) |
159 |
> |
ysiz = cheight*nlines; |
160 |
> |
pictaspect = 256*nlines*aspect/maxwidth; |
161 |
> |
if (pictaspect*xsiz < ysiz) |
162 |
> |
ysiz = pictaspect*xsiz + 0.5; |
163 |
> |
else |
164 |
> |
xsiz = ysiz/pictaspect + 0.5; |
165 |
> |
cheight = ysiz/nlines; |
166 |
> |
cwidth = cheight/aspect; |
167 |
> |
} else { |
168 |
> |
if (ysiz <= 0) |
169 |
> |
ysiz = cheight*nlines; |
170 |
> |
pictaspect = (double)ysiz/xsiz; |
171 |
> |
aspect = pictaspect*maxwidth/(256*nlines); |
172 |
> |
cheight = ysiz/nlines; |
173 |
> |
cwidth = cheight/aspect; |
174 |
> |
} |
175 |
|
} else { /* reverse orientation */ |
176 |
< |
xsiz = nlines*cheight; |
177 |
< |
ysiz = (long)maxwidth*cwidth >> 8; |
176 |
> |
if (ysiz <= 0) { |
177 |
> |
cwidth = cheight/aspect + 0.5; |
178 |
> |
xsiz = nlines*cheight; |
179 |
> |
ysiz = (long)maxwidth*cwidth >> 8; |
180 |
> |
} else if (aspect > FTINY) { |
181 |
> |
if (xsiz <= 0) |
182 |
> |
xsiz = cheight*nlines; |
183 |
> |
pictaspect = maxwidth/(256*nlines*aspect); |
184 |
> |
if (pictaspect*xsiz < ysiz) |
185 |
> |
ysiz = pictaspect*xsiz + 0.5; |
186 |
> |
else |
187 |
> |
xsiz = ysiz/pictaspect + 0.5; |
188 |
> |
cheight = xsiz/nlines; |
189 |
> |
cwidth = cheight/aspect; |
190 |
> |
} else { |
191 |
> |
if (xsiz <= 0) |
192 |
> |
xsiz = cheight*nlines; |
193 |
> |
pictaspect = (double)ysiz/xsiz; |
194 |
> |
aspect = maxwidth/(256*nlines*pictaspect); |
195 |
> |
cheight = xsiz/nlines; |
196 |
> |
cwidth = cheight/aspect; |
197 |
> |
} |
198 |
|
} |
199 |
|
if (xsiz % SSS) |
200 |
|
xsiz += SSS - xsiz%SSS; |
201 |
|
if (ysiz % SSS) |
202 |
|
ysiz += SSS - ysiz%SSS; |
203 |
|
xdim = (xsiz+7)/8; |
204 |
< |
ourbitmap = (BYTE *)calloc(ysiz, xdim); |
204 |
> |
ourbitmap = (BYTE *)bmalloc(ysiz*xdim); |
205 |
|
if (ourbitmap == NULL) |
206 |
|
error(SYSTEM, "Out of memory in makemap"); |
207 |
+ |
bzero((char *)ourbitmap, ysiz*xdim); |
208 |
|
} |
209 |
|
|
210 |
|
|
211 |
|
gettext(fp) /* get text from a file */ |
212 |
|
FILE *fp; |
213 |
|
{ |
173 |
– |
char *fgets(); |
214 |
|
char buf[MAXLINE]; |
215 |
|
register LINE *curl; |
216 |
|
int len; |
231 |
|
maxline = len; |
232 |
|
strncpy(curl->s, buf, len); |
233 |
|
curl->s[len] = '\0'; |
234 |
< |
len = uniftext(curl->sp, curl->s, ourfont); |
234 |
> |
if (spacing < -1./256.) |
235 |
> |
len = squeeztext(curl->sp, curl->s, ourfont, |
236 |
> |
(int)(spacing*-256.)); |
237 |
> |
else if (spacing > 1./256.) |
238 |
> |
len = proptext(curl->sp, curl->s, ourfont, |
239 |
> |
(int)(spacing*256.), 3); |
240 |
> |
else |
241 |
> |
len = uniftext(curl->sp, curl->s, ourfont); |
242 |
|
if (len > maxwidth) |
243 |
|
maxwidth = len; |
244 |
|
curl->next = ourtext; |
274 |
|
ourtext->sp = (short *)malloc(sizeof(short)*(maxline+1)); |
275 |
|
if (ourtext->sp == NULL) |
276 |
|
goto memerr; |
277 |
< |
maxwidth = squeeztext(ourtext->sp, ourtext->s, ourfont, 50); |
277 |
> |
if (spacing < -1./256.) |
278 |
> |
maxwidth = squeeztext(ourtext->sp, ourtext->s, ourfont, |
279 |
> |
(int)(spacing*-256.)); |
280 |
> |
else if (spacing > 1./256.) |
281 |
> |
maxwidth = proptext(ourtext->sp, ourtext->s, ourfont, |
282 |
> |
(int)(spacing*256.), 3); |
283 |
> |
else |
284 |
> |
maxwidth = uniftext(ourtext->sp, ourtext->s, ourfont); |
285 |
|
nlines = 1; |
286 |
|
return; |
287 |
|
memerr: |
397 |
|
{ |
398 |
|
COLR pixval[SSS*SSS+1]; /* possible pixel values */ |
399 |
|
COLOR ctmp0, ctmp1; |
400 |
< |
double d; |
400 |
> |
double d; |
401 |
|
COLR *scanout; |
402 |
|
int x, y; |
403 |
|
register int i, j; |