| 1 |
– |
/* Copyright (c) 1992 Regents of the University of California */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* psign.c - produce picture from text. |
| 6 |
|
* |
| 13 |
|
|
| 14 |
|
#include "font.h" |
| 15 |
|
|
| 16 |
< |
#ifndef SSS |
| 17 |
< |
#define SSS 3 /* super-sample size */ |
| 16 |
> |
#ifndef SSS |
| 17 |
> |
#define SSS 3 /* super-sample size */ |
| 18 |
|
#endif |
| 19 |
|
|
| 20 |
< |
#define MAXLINE 512 /* longest allowable line */ |
| 20 |
> |
#define MAXLINE 512 /* longest allowable line */ |
| 21 |
|
|
| 25 |
– |
#ifndef DEFPATH |
| 26 |
– |
#define DEFPATH ":/usr/local/lib/ray" |
| 27 |
– |
#endif |
| 28 |
– |
#ifndef ULIBVAR |
| 29 |
– |
#define ULIBVAR "RAYPATH" |
| 30 |
– |
#endif |
| 31 |
– |
|
| 22 |
|
char *fontfile = "helvet.fnt"; /* our font file */ |
| 23 |
|
|
| 24 |
|
COLOR bgcolor = WHTCOLOR; /* background color */ |
| 27 |
|
int direct = 'r'; /* direction (right, up, left, down) */ |
| 28 |
|
|
| 29 |
|
int cheight = 32*SSS; /* character height */ |
| 30 |
< |
double aspect = 1.67; /* height/width character aspect */ |
| 31 |
< |
double spacing = 0.0; /* character spacing */ |
| 30 |
> |
double aspect = 1.67; /* height/width character aspect */ |
| 31 |
> |
double spacing = 0.0; /* character spacing */ |
| 32 |
|
int cwidth; /* computed character width */ |
| 33 |
|
|
| 34 |
|
unsigned char *ourbitmap; /* our output bitmap */ |
| 35 |
|
int xsiz, ysiz; /* bitmap dimensions */ |
| 36 |
|
int xdim; /* size of horizontal scan (bytes) */ |
| 37 |
|
|
| 38 |
< |
#define bitop(x,y,op) (ourbitmap[(y)*xdim+((x)>>3)] op (1<<((x)&7))) |
| 39 |
< |
#define tstbit(x,y) bitop(x,y,&) |
| 40 |
< |
#define setbit(x,y) bitop(x,y,|=) |
| 41 |
< |
#define clrbit(x,y) bitop(x,y,&=~) |
| 42 |
< |
#define tglbit(x,y) bitop(x,y,^=) |
| 38 |
> |
#define bitop(x,y,op) (ourbitmap[(y)*xdim+((x)>>3)] op (1<<((x)&7))) |
| 39 |
> |
#define tstbit(x,y) bitop(x,y,&) |
| 40 |
> |
#define setbit(x,y) bitop(x,y,|=) |
| 41 |
> |
#define clrbit(x,y) bitop(x,y,&=~) |
| 42 |
> |
#define tglbit(x,y) bitop(x,y,^=) |
| 43 |
|
|
| 44 |
|
FONT *ourfont; /* our font */ |
| 45 |
|
|
| 56 |
– |
char *libpath; /* library search path */ |
| 57 |
– |
|
| 46 |
|
typedef struct line { |
| 47 |
|
char *s; /* line w/o LF */ |
| 48 |
|
short *sp; /* character spacing */ |
| 53 |
|
int nlines, maxline; /* text dimensions */ |
| 54 |
|
int maxwidth; /* maximum line width (dvi) */ |
| 55 |
|
|
| 68 |
– |
extern char *getenv(); |
| 56 |
|
|
| 70 |
– |
|
| 57 |
|
main(argc, argv) |
| 58 |
|
int argc; |
| 59 |
|
char *argv[]; |
| 60 |
|
{ |
| 61 |
|
int an; |
| 62 |
< |
|
| 62 |
> |
#ifdef MSDOS |
| 63 |
> |
setmode(fileno(stdout), O_BINARY); |
| 64 |
> |
#endif |
| 65 |
|
for (an = 1; an < argc && argv[an][0] == '-'; an++) |
| 66 |
|
switch (argv[an][1]) { |
| 67 |
|
case 'c': /* color */ |
| 105 |
|
break; |
| 106 |
|
case 'h': /* height of characters */ |
| 107 |
|
cheight = atoi(argv[++an])*SSS; |
| 120 |
– |
xsiz = xsiz = 0; |
| 108 |
|
break; |
| 109 |
|
case 'a': /* aspect ratio */ |
| 110 |
|
aspect = atof(argv[++an]); |
| 119 |
|
exit(1); |
| 120 |
|
} |
| 121 |
|
/* load font file */ |
| 135 |
– |
if ((libpath = getenv(ULIBVAR)) == NULL) |
| 136 |
– |
libpath = DEFPATH; |
| 122 |
|
ourfont = getfont(fontfile); |
| 123 |
|
/* get text */ |
| 124 |
|
if (an == argc) |
| 131 |
|
/* convert text to bitmap */ |
| 132 |
|
maptext(); |
| 133 |
|
/* print header */ |
| 134 |
+ |
newheader("RADIANCE", stdout); |
| 135 |
|
printargs(argc, argv, stdout); |
| 136 |
|
fputformat(COLRFMT, stdout); |
| 137 |
|
putchar('\n'); |
| 144 |
|
|
| 145 |
|
makemap() /* create the bit map */ |
| 146 |
|
{ |
| 147 |
< |
double pictaspect; |
| 147 |
> |
double pictaspect; |
| 148 |
|
|
| 149 |
|
if (direct == 'r' || direct == 'l') { |
| 150 |
< |
if (xsiz == 0 || ysiz == 0) { |
| 150 |
> |
if (xsiz <= 0) { |
| 151 |
|
cwidth = cheight/aspect + 0.5; |
| 152 |
|
xsiz = (long)maxwidth*cwidth >> 8; |
| 153 |
|
ysiz = nlines*cheight; |
| 154 |
< |
} else { |
| 154 |
> |
} else if (aspect > FTINY) { |
| 155 |
> |
if (ysiz <= 0) |
| 156 |
> |
ysiz = cheight*nlines; |
| 157 |
|
pictaspect = 256*nlines*aspect/maxwidth; |
| 158 |
|
if (pictaspect*xsiz < ysiz) |
| 159 |
|
ysiz = pictaspect*xsiz + 0.5; |
| 160 |
|
else |
| 161 |
|
xsiz = ysiz/pictaspect + 0.5; |
| 162 |
|
cheight = ysiz/nlines; |
| 163 |
< |
cwidth = cheight/aspect + 0.5; |
| 163 |
> |
cwidth = cheight/aspect; |
| 164 |
> |
} else { |
| 165 |
> |
if (ysiz <= 0) |
| 166 |
> |
ysiz = cheight*nlines; |
| 167 |
> |
pictaspect = (double)ysiz/xsiz; |
| 168 |
> |
aspect = pictaspect*maxwidth/(256*nlines); |
| 169 |
> |
cheight = ysiz/nlines; |
| 170 |
> |
cwidth = cheight/aspect; |
| 171 |
|
} |
| 172 |
|
} else { /* reverse orientation */ |
| 173 |
< |
if (xsiz == 0 || ysiz == 0) { |
| 173 |
> |
if (ysiz <= 0) { |
| 174 |
|
cwidth = cheight/aspect + 0.5; |
| 175 |
|
xsiz = nlines*cheight; |
| 176 |
|
ysiz = (long)maxwidth*cwidth >> 8; |
| 177 |
< |
} else { |
| 177 |
> |
} else if (aspect > FTINY) { |
| 178 |
> |
if (xsiz <= 0) |
| 179 |
> |
xsiz = cheight*nlines; |
| 180 |
|
pictaspect = maxwidth/(256*nlines*aspect); |
| 181 |
|
if (pictaspect*xsiz < ysiz) |
| 182 |
|
ysiz = pictaspect*xsiz + 0.5; |
| 183 |
|
else |
| 184 |
|
xsiz = ysiz/pictaspect + 0.5; |
| 185 |
|
cheight = xsiz/nlines; |
| 186 |
< |
cwidth = cheight/aspect + 0.5; |
| 186 |
> |
cwidth = cheight/aspect; |
| 187 |
> |
} else { |
| 188 |
> |
if (xsiz <= 0) |
| 189 |
> |
xsiz = cheight*nlines; |
| 190 |
> |
pictaspect = (double)ysiz/xsiz; |
| 191 |
> |
aspect = maxwidth/(256*nlines*pictaspect); |
| 192 |
> |
cheight = xsiz/nlines; |
| 193 |
> |
cwidth = cheight/aspect; |
| 194 |
|
} |
| 195 |
|
} |
| 196 |
|
if (xsiz % SSS) |
| 208 |
|
gettext(fp) /* get text from a file */ |
| 209 |
|
FILE *fp; |
| 210 |
|
{ |
| 207 |
– |
char *fgets(); |
| 211 |
|
char buf[MAXLINE]; |
| 212 |
|
register LINE *curl; |
| 213 |
|
int len; |
| 220 |
|
if (curl == NULL) |
| 221 |
|
goto memerr; |
| 222 |
|
len = strlen(buf); |
| 223 |
< |
curl->s = malloc(len); |
| 223 |
> |
curl->s = (char *)malloc(len); |
| 224 |
|
curl->sp = (short *)malloc(sizeof(short)*len--); |
| 225 |
|
if (curl->s == NULL | curl->sp == NULL) |
| 226 |
|
goto memerr; |
| 230 |
|
curl->s[len] = '\0'; |
| 231 |
|
if (spacing < -1./256.) |
| 232 |
|
len = squeeztext(curl->sp, curl->s, ourfont, |
| 233 |
< |
(int)(spacing*-256.0)); |
| 233 |
> |
(int)(spacing*-256.)); |
| 234 |
|
else if (spacing > 1./256.) |
| 235 |
|
len = proptext(curl->sp, curl->s, ourfont, |
| 236 |
< |
(int)(spacing*256.0), 3); |
| 236 |
> |
(int)(spacing*256.), 3); |
| 237 |
|
else |
| 238 |
|
len = uniftext(curl->sp, curl->s, ourfont); |
| 239 |
|
if (len > maxwidth) |
| 257 |
|
ourtext = (LINE *)malloc(sizeof(LINE)); |
| 258 |
|
if (ourtext == NULL) |
| 259 |
|
goto memerr; |
| 260 |
< |
ourtext->s = malloc(MAXLINE); |
| 260 |
> |
ourtext->s = (char *)malloc(MAXLINE); |
| 261 |
|
if (ourtext->s == NULL) |
| 262 |
|
goto memerr; |
| 263 |
|
for (cp = ourtext->s; ac-- > 0; av++) { |
| 271 |
|
ourtext->sp = (short *)malloc(sizeof(short)*(maxline+1)); |
| 272 |
|
if (ourtext->sp == NULL) |
| 273 |
|
goto memerr; |
| 274 |
< |
if (spacing < 0.0) |
| 274 |
> |
if (spacing < -1./256.) |
| 275 |
|
maxwidth = squeeztext(ourtext->sp, ourtext->s, ourfont, |
| 276 |
< |
(int)(spacing*-256.0)); |
| 277 |
< |
else if (spacing > 0.0) |
| 276 |
> |
(int)(spacing*-256.)); |
| 277 |
> |
else if (spacing > 1./256.) |
| 278 |
|
maxwidth = proptext(ourtext->sp, ourtext->s, ourfont, |
| 279 |
< |
(int)(spacing*256.0), 3); |
| 279 |
> |
(int)(spacing*256.), 3); |
| 280 |
|
else |
| 281 |
|
maxwidth = uniftext(ourtext->sp, ourtext->s, ourfont); |
| 282 |
|
nlines = 1; |
| 394 |
|
{ |
| 395 |
|
COLR pixval[SSS*SSS+1]; /* possible pixel values */ |
| 396 |
|
COLOR ctmp0, ctmp1; |
| 397 |
< |
double d; |
| 397 |
> |
double d; |
| 398 |
|
COLR *scanout; |
| 399 |
|
int x, y; |
| 400 |
|
register int i, j; |
| 435 |
|
exit(1); |
| 436 |
|
} |
| 437 |
|
} |
| 438 |
< |
free((char *)scanout); |
| 438 |
> |
free((void *)scanout); |
| 439 |
|
} |