| 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 |
|
* |
| 8 |
|
*/ |
| 9 |
|
|
| 10 |
|
#include "standard.h" |
| 14 |
– |
|
| 11 |
|
#include "color.h" |
| 16 |
– |
|
| 12 |
|
#include "font.h" |
| 13 |
|
|
| 14 |
< |
#ifndef SSS |
| 15 |
< |
#define SSS 3 /* super-sample size */ |
| 14 |
> |
#ifndef SSS |
| 15 |
> |
#define SSS 3 /* super-sample size */ |
| 16 |
|
#endif |
| 17 |
|
|
| 18 |
< |
#define MAXLINE 512 /* longest allowable line */ |
| 18 |
> |
#define MAXLINE 512 /* longest allowable line */ |
| 19 |
|
|
| 25 |
– |
#ifndef DEFPATH |
| 26 |
– |
#define DEFPATH ":/usr/local/lib/ray" |
| 27 |
– |
#endif |
| 28 |
– |
#ifndef ULIBVAR |
| 29 |
– |
#define ULIBVAR "RAYPATH" |
| 30 |
– |
#endif |
| 31 |
– |
|
| 20 |
|
char *fontfile = "helvet.fnt"; /* our font file */ |
| 21 |
|
|
| 22 |
|
COLOR bgcolor = WHTCOLOR; /* background color */ |
| 25 |
|
int direct = 'r'; /* direction (right, up, left, down) */ |
| 26 |
|
|
| 27 |
|
int cheight = 32*SSS; /* character height */ |
| 28 |
< |
double aspect = 1.67; /* height/width character aspect */ |
| 29 |
< |
double spacing = 0.0; /* character spacing */ |
| 28 |
> |
double aspect = 1.67; /* height/width character aspect */ |
| 29 |
> |
double spacing = 0.0; /* character spacing */ |
| 30 |
|
int cwidth; /* computed character width */ |
| 31 |
|
|
| 32 |
|
unsigned char *ourbitmap; /* our output bitmap */ |
| 33 |
|
int xsiz, ysiz; /* bitmap dimensions */ |
| 34 |
|
int xdim; /* size of horizontal scan (bytes) */ |
| 35 |
|
|
| 36 |
< |
#define bitop(x,y,op) (ourbitmap[(y)*xdim+((x)>>3)] op (1<<((x)&7))) |
| 37 |
< |
#define tstbit(x,y) bitop(x,y,&) |
| 38 |
< |
#define setbit(x,y) bitop(x,y,|=) |
| 39 |
< |
#define clrbit(x,y) bitop(x,y,&=~) |
| 40 |
< |
#define tglbit(x,y) bitop(x,y,^=) |
| 36 |
> |
#define bitop(x,y,op) (ourbitmap[(y)*xdim+((x)>>3)] op (1<<((x)&7))) |
| 37 |
> |
#define tstbit(x,y) bitop(x,y,&) |
| 38 |
> |
#define setbit(x,y) bitop(x,y,|=) |
| 39 |
> |
#define clrbit(x,y) bitop(x,y,&=~) |
| 40 |
> |
#define tglbit(x,y) bitop(x,y,^=) |
| 41 |
|
|
| 42 |
|
FONT *ourfont; /* our font */ |
| 43 |
|
|
| 56 |
– |
char *libpath; /* library search path */ |
| 57 |
– |
|
| 44 |
|
typedef struct line { |
| 45 |
|
char *s; /* line w/o LF */ |
| 46 |
|
short *sp; /* character spacing */ |
| 51 |
|
int nlines, maxline; /* text dimensions */ |
| 52 |
|
int maxwidth; /* maximum line width (dvi) */ |
| 53 |
|
|
| 68 |
– |
extern char *getenv(); |
| 54 |
|
|
| 70 |
– |
|
| 55 |
|
main(argc, argv) |
| 56 |
|
int argc; |
| 57 |
|
char *argv[]; |
| 58 |
|
{ |
| 59 |
|
int an; |
| 60 |
< |
|
| 60 |
> |
SET_FILE_BINARY(stdout); |
| 61 |
|
for (an = 1; an < argc && argv[an][0] == '-'; an++) |
| 62 |
|
switch (argv[an][1]) { |
| 63 |
|
case 'c': /* color */ |
| 115 |
|
exit(1); |
| 116 |
|
} |
| 117 |
|
/* load font file */ |
| 134 |
– |
if ((libpath = getenv(ULIBVAR)) == NULL) |
| 135 |
– |
libpath = DEFPATH; |
| 118 |
|
ourfont = getfont(fontfile); |
| 119 |
|
/* get text */ |
| 120 |
|
if (an == argc) |
| 127 |
|
/* convert text to bitmap */ |
| 128 |
|
maptext(); |
| 129 |
|
/* print header */ |
| 130 |
+ |
newheader("RADIANCE", stdout); |
| 131 |
|
printargs(argc, argv, stdout); |
| 132 |
|
fputformat(COLRFMT, stdout); |
| 133 |
|
putchar('\n'); |
| 140 |
|
|
| 141 |
|
makemap() /* create the bit map */ |
| 142 |
|
{ |
| 143 |
< |
double pictaspect; |
| 143 |
> |
double pictaspect; |
| 144 |
|
|
| 145 |
|
if (direct == 'r' || direct == 'l') { |
| 146 |
|
if (xsiz <= 0) { |
| 156 |
|
else |
| 157 |
|
xsiz = ysiz/pictaspect + 0.5; |
| 158 |
|
cheight = ysiz/nlines; |
| 159 |
< |
cwidth = cheight/aspect + 0.5; |
| 159 |
> |
cwidth = cheight/aspect; |
| 160 |
|
} else { |
| 161 |
|
if (ysiz <= 0) |
| 162 |
|
ysiz = cheight*nlines; |
| 163 |
|
pictaspect = (double)ysiz/xsiz; |
| 164 |
|
aspect = pictaspect*maxwidth/(256*nlines); |
| 165 |
|
cheight = ysiz/nlines; |
| 166 |
< |
cwidth = cheight/aspect + 0.5; |
| 166 |
> |
cwidth = cheight/aspect; |
| 167 |
|
} |
| 168 |
|
} else { /* reverse orientation */ |
| 169 |
|
if (ysiz <= 0) { |
| 179 |
|
else |
| 180 |
|
xsiz = ysiz/pictaspect + 0.5; |
| 181 |
|
cheight = xsiz/nlines; |
| 182 |
< |
cwidth = cheight/aspect + 0.5; |
| 182 |
> |
cwidth = cheight/aspect; |
| 183 |
|
} else { |
| 184 |
|
if (xsiz <= 0) |
| 185 |
|
xsiz = cheight*nlines; |
| 186 |
|
pictaspect = (double)ysiz/xsiz; |
| 187 |
|
aspect = maxwidth/(256*nlines*pictaspect); |
| 188 |
|
cheight = xsiz/nlines; |
| 189 |
< |
cwidth = cheight/aspect + 0.5; |
| 189 |
> |
cwidth = cheight/aspect; |
| 190 |
|
} |
| 191 |
|
} |
| 192 |
|
if (xsiz % SSS) |
| 204 |
|
gettext(fp) /* get text from a file */ |
| 205 |
|
FILE *fp; |
| 206 |
|
{ |
| 224 |
– |
char *fgets(); |
| 207 |
|
char buf[MAXLINE]; |
| 208 |
|
register LINE *curl; |
| 209 |
|
int len; |
| 216 |
|
if (curl == NULL) |
| 217 |
|
goto memerr; |
| 218 |
|
len = strlen(buf); |
| 219 |
< |
curl->s = malloc(len); |
| 219 |
> |
curl->s = (char *)malloc(len); |
| 220 |
|
curl->sp = (short *)malloc(sizeof(short)*len--); |
| 221 |
|
if (curl->s == NULL | curl->sp == NULL) |
| 222 |
|
goto memerr; |
| 226 |
|
curl->s[len] = '\0'; |
| 227 |
|
if (spacing < -1./256.) |
| 228 |
|
len = squeeztext(curl->sp, curl->s, ourfont, |
| 229 |
< |
(int)(spacing*-256.0)); |
| 229 |
> |
(int)(spacing*-256.)); |
| 230 |
|
else if (spacing > 1./256.) |
| 231 |
|
len = proptext(curl->sp, curl->s, ourfont, |
| 232 |
< |
(int)(spacing*256.0), 3); |
| 232 |
> |
(int)(spacing*256.), 3); |
| 233 |
|
else |
| 234 |
|
len = uniftext(curl->sp, curl->s, ourfont); |
| 235 |
|
if (len > maxwidth) |
| 253 |
|
ourtext = (LINE *)malloc(sizeof(LINE)); |
| 254 |
|
if (ourtext == NULL) |
| 255 |
|
goto memerr; |
| 256 |
< |
ourtext->s = malloc(MAXLINE); |
| 256 |
> |
ourtext->s = (char *)malloc(MAXLINE); |
| 257 |
|
if (ourtext->s == NULL) |
| 258 |
|
goto memerr; |
| 259 |
|
for (cp = ourtext->s; ac-- > 0; av++) { |
| 267 |
|
ourtext->sp = (short *)malloc(sizeof(short)*(maxline+1)); |
| 268 |
|
if (ourtext->sp == NULL) |
| 269 |
|
goto memerr; |
| 270 |
< |
if (spacing < 0.0) |
| 270 |
> |
if (spacing < -1./256.) |
| 271 |
|
maxwidth = squeeztext(ourtext->sp, ourtext->s, ourfont, |
| 272 |
< |
(int)(spacing*-256.0)); |
| 273 |
< |
else if (spacing > 0.0) |
| 272 |
> |
(int)(spacing*-256.)); |
| 273 |
> |
else if (spacing > 1./256.) |
| 274 |
|
maxwidth = proptext(ourtext->sp, ourtext->s, ourfont, |
| 275 |
< |
(int)(spacing*256.0), 3); |
| 275 |
> |
(int)(spacing*256.), 3); |
| 276 |
|
else |
| 277 |
|
maxwidth = uniftext(ourtext->sp, ourtext->s, ourfont); |
| 278 |
|
nlines = 1; |
| 390 |
|
{ |
| 391 |
|
COLR pixval[SSS*SSS+1]; /* possible pixel values */ |
| 392 |
|
COLOR ctmp0, ctmp1; |
| 393 |
< |
double d; |
| 393 |
> |
double d; |
| 394 |
|
COLR *scanout; |
| 395 |
|
int x, y; |
| 396 |
|
register int i, j; |
| 431 |
|
exit(1); |
| 432 |
|
} |
| 433 |
|
} |
| 434 |
< |
free((char *)scanout); |
| 434 |
> |
free((void *)scanout); |
| 435 |
|
} |