| 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 |
|
* |
| 7 |
|
* 7/1/87 |
| 8 |
|
*/ |
| 9 |
|
|
| 10 |
< |
#include "standard.h" |
| 10 |
> |
#include "copyright.h" |
| 11 |
|
|
| 12 |
< |
#include "color.h" |
| 12 |
> |
#include <string.h> |
| 13 |
|
|
| 14 |
+ |
#include "platform.h" |
| 15 |
+ |
#include "standard.h" |
| 16 |
+ |
#include "resolu.h" |
| 17 |
+ |
#include "color.h" |
| 18 |
|
#include "font.h" |
| 19 |
|
|
| 19 |
– |
#include "paths.h" |
| 20 |
– |
|
| 20 |
|
#ifndef SSS |
| 21 |
|
#define SSS 3 /* super-sample size */ |
| 22 |
|
#endif |
| 39 |
|
int xsiz, ysiz; /* bitmap dimensions */ |
| 40 |
|
int xdim; /* size of horizontal scan (bytes) */ |
| 41 |
|
|
| 42 |
+ |
/* conflicting def's in param.h */ |
| 43 |
+ |
#undef tstbit |
| 44 |
+ |
#undef setbit |
| 45 |
+ |
#undef clrbit |
| 46 |
+ |
#undef tglbit |
| 47 |
+ |
|
| 48 |
|
#define bitop(x,y,op) (ourbitmap[(y)*xdim+((x)>>3)] op (1<<((x)&7))) |
| 49 |
|
#define tstbit(x,y) bitop(x,y,&) |
| 50 |
|
#define setbit(x,y) bitop(x,y,|=) |
| 53 |
|
|
| 54 |
|
FONT *ourfont; /* our font */ |
| 55 |
|
|
| 51 |
– |
char *libpath; /* library search path */ |
| 52 |
– |
|
| 56 |
|
typedef struct line { |
| 57 |
|
char *s; /* line w/o LF */ |
| 58 |
|
short *sp; /* character spacing */ |
| 63 |
|
int nlines, maxline; /* text dimensions */ |
| 64 |
|
int maxwidth; /* maximum line width (dvi) */ |
| 65 |
|
|
| 66 |
+ |
static void makemap(void); |
| 67 |
+ |
static void get_text(FILE *fp); |
| 68 |
+ |
static void arg_text(int ac, char *av[]); |
| 69 |
+ |
static void maptext(void); |
| 70 |
+ |
static void mapglyph(GLYPH *gl, int tx0, int ty0); |
| 71 |
+ |
static void mapcoord(int p[2], int tx, int ty); |
| 72 |
+ |
static void mapedge(int x, int y, int run, int rise); |
| 73 |
+ |
static void writemap(FILE *fp); |
| 74 |
|
|
| 75 |
< |
main(argc, argv) |
| 76 |
< |
int argc; |
| 77 |
< |
char *argv[]; |
| 75 |
> |
|
| 76 |
> |
int |
| 77 |
> |
main( |
| 78 |
> |
int argc, |
| 79 |
> |
char *argv[] |
| 80 |
> |
) |
| 81 |
|
{ |
| 82 |
|
int an; |
| 83 |
< |
#ifdef MSDOS |
| 70 |
< |
setmode(fileno(stdout), O_BINARY); |
| 71 |
< |
#endif |
| 83 |
> |
SET_FILE_BINARY(stdout); |
| 84 |
|
for (an = 1; an < argc && argv[an][0] == '-'; an++) |
| 85 |
|
switch (argv[an][1]) { |
| 86 |
|
case 'c': /* color */ |
| 138 |
|
exit(1); |
| 139 |
|
} |
| 140 |
|
/* load font file */ |
| 129 |
– |
if ((libpath = getenv(ULIBVAR)) == NULL) |
| 130 |
– |
libpath = DEFPATH; |
| 141 |
|
ourfont = getfont(fontfile); |
| 142 |
+ |
if (!ourfont) |
| 143 |
+ |
exit(1); |
| 144 |
|
/* get text */ |
| 145 |
|
if (an == argc) |
| 146 |
< |
gettext(stdin); |
| 146 |
> |
get_text(stdin); |
| 147 |
|
else |
| 148 |
|
arg_text(argc-an, argv+an); |
| 149 |
|
|
| 152 |
|
/* convert text to bitmap */ |
| 153 |
|
maptext(); |
| 154 |
|
/* print header */ |
| 155 |
+ |
newheader("RADIANCE", stdout); |
| 156 |
|
printargs(argc, argv, stdout); |
| 157 |
|
fputformat(COLRFMT, stdout); |
| 158 |
|
putchar('\n'); |
| 163 |
|
} |
| 164 |
|
|
| 165 |
|
|
| 166 |
< |
makemap() /* create the bit map */ |
| 166 |
> |
static void |
| 167 |
> |
makemap(void) /* create the bit map */ |
| 168 |
|
{ |
| 169 |
|
double pictaspect; |
| 170 |
|
|
| 182 |
|
else |
| 183 |
|
xsiz = ysiz/pictaspect + 0.5; |
| 184 |
|
cheight = ysiz/nlines; |
| 185 |
< |
cwidth = cheight/aspect + 0.5; |
| 185 |
> |
cwidth = cheight/aspect; |
| 186 |
|
} else { |
| 187 |
|
if (ysiz <= 0) |
| 188 |
|
ysiz = cheight*nlines; |
| 189 |
|
pictaspect = (double)ysiz/xsiz; |
| 190 |
|
aspect = pictaspect*maxwidth/(256*nlines); |
| 191 |
|
cheight = ysiz/nlines; |
| 192 |
< |
cwidth = cheight/aspect + 0.5; |
| 192 |
> |
cwidth = cheight/aspect; |
| 193 |
|
} |
| 194 |
|
} else { /* reverse orientation */ |
| 195 |
|
if (ysiz <= 0) { |
| 205 |
|
else |
| 206 |
|
xsiz = ysiz/pictaspect + 0.5; |
| 207 |
|
cheight = xsiz/nlines; |
| 208 |
< |
cwidth = cheight/aspect + 0.5; |
| 208 |
> |
cwidth = cheight/aspect; |
| 209 |
|
} else { |
| 210 |
|
if (xsiz <= 0) |
| 211 |
|
xsiz = cheight*nlines; |
| 212 |
|
pictaspect = (double)ysiz/xsiz; |
| 213 |
|
aspect = maxwidth/(256*nlines*pictaspect); |
| 214 |
|
cheight = xsiz/nlines; |
| 215 |
< |
cwidth = cheight/aspect + 0.5; |
| 215 |
> |
cwidth = cheight/aspect; |
| 216 |
|
} |
| 217 |
|
} |
| 218 |
|
if (xsiz % SSS) |
| 220 |
|
if (ysiz % SSS) |
| 221 |
|
ysiz += SSS - ysiz%SSS; |
| 222 |
|
xdim = (xsiz+7)/8; |
| 223 |
< |
ourbitmap = (BYTE *)bmalloc(ysiz*xdim); |
| 223 |
> |
ourbitmap = (uby8 *)bmalloc(ysiz*xdim); |
| 224 |
|
if (ourbitmap == NULL) |
| 225 |
|
error(SYSTEM, "Out of memory in makemap"); |
| 226 |
< |
bzero((char *)ourbitmap, ysiz*xdim); |
| 226 |
> |
memset((char *)ourbitmap, '\0', ysiz*xdim); |
| 227 |
|
} |
| 228 |
|
|
| 229 |
|
|
| 230 |
< |
gettext(fp) /* get text from a file */ |
| 231 |
< |
FILE *fp; |
| 230 |
> |
static void |
| 231 |
> |
get_text( /* get text from a file */ |
| 232 |
> |
FILE *fp |
| 233 |
> |
) |
| 234 |
|
{ |
| 219 |
– |
char *fgets(); |
| 235 |
|
char buf[MAXLINE]; |
| 236 |
|
register LINE *curl; |
| 237 |
|
int len; |
| 244 |
|
if (curl == NULL) |
| 245 |
|
goto memerr; |
| 246 |
|
len = strlen(buf); |
| 247 |
< |
curl->s = malloc(len); |
| 247 |
> |
curl->s = (char *)malloc(len); |
| 248 |
|
curl->sp = (short *)malloc(sizeof(short)*len--); |
| 249 |
< |
if (curl->s == NULL | curl->sp == NULL) |
| 249 |
> |
if ((curl->s == NULL) | (curl->sp == NULL)) |
| 250 |
|
goto memerr; |
| 251 |
|
if (len > maxline) |
| 252 |
|
maxline = len; |
| 254 |
|
curl->s[len] = '\0'; |
| 255 |
|
if (spacing < -1./256.) |
| 256 |
|
len = squeeztext(curl->sp, curl->s, ourfont, |
| 257 |
< |
(int)(spacing*-256.0)); |
| 257 |
> |
(int)(spacing*-256.)); |
| 258 |
|
else if (spacing > 1./256.) |
| 259 |
|
len = proptext(curl->sp, curl->s, ourfont, |
| 260 |
< |
(int)(spacing*256.0), 3); |
| 260 |
> |
(int)(spacing*256.), 3); |
| 261 |
|
else |
| 262 |
|
len = uniftext(curl->sp, curl->s, ourfont); |
| 263 |
|
if (len > maxwidth) |
| 268 |
|
} |
| 269 |
|
return; |
| 270 |
|
memerr: |
| 271 |
< |
error(SYSTEM, "Out of memory in gettext"); |
| 271 |
> |
error(SYSTEM, "Out of memory in get_text"); |
| 272 |
|
} |
| 273 |
|
|
| 274 |
|
|
| 275 |
< |
arg_text(ac, av) /* get text from arguments */ |
| 276 |
< |
int ac; |
| 277 |
< |
char *av[]; |
| 275 |
> |
static void |
| 276 |
> |
arg_text( /* get text from arguments */ |
| 277 |
> |
int ac, |
| 278 |
> |
char *av[] |
| 279 |
> |
) |
| 280 |
|
{ |
| 281 |
|
register char *cp; |
| 282 |
|
|
| 283 |
|
ourtext = (LINE *)malloc(sizeof(LINE)); |
| 284 |
|
if (ourtext == NULL) |
| 285 |
|
goto memerr; |
| 286 |
< |
ourtext->s = malloc(MAXLINE); |
| 286 |
> |
ourtext->s = (char *)malloc(MAXLINE); |
| 287 |
|
if (ourtext->s == NULL) |
| 288 |
|
goto memerr; |
| 289 |
|
for (cp = ourtext->s; ac-- > 0; av++) { |
| 297 |
|
ourtext->sp = (short *)malloc(sizeof(short)*(maxline+1)); |
| 298 |
|
if (ourtext->sp == NULL) |
| 299 |
|
goto memerr; |
| 300 |
< |
if (spacing < 0.0) |
| 300 |
> |
if (spacing < -1./256.) |
| 301 |
|
maxwidth = squeeztext(ourtext->sp, ourtext->s, ourfont, |
| 302 |
< |
(int)(spacing*-256.0)); |
| 303 |
< |
else if (spacing > 0.0) |
| 302 |
> |
(int)(spacing*-256.)); |
| 303 |
> |
else if (spacing > 1./256.) |
| 304 |
|
maxwidth = proptext(ourtext->sp, ourtext->s, ourfont, |
| 305 |
< |
(int)(spacing*256.0), 3); |
| 305 |
> |
(int)(spacing*256.), 3); |
| 306 |
|
else |
| 307 |
|
maxwidth = uniftext(ourtext->sp, ourtext->s, ourfont); |
| 308 |
|
nlines = 1; |
| 312 |
|
} |
| 313 |
|
|
| 314 |
|
|
| 315 |
< |
maptext() /* map our text */ |
| 315 |
> |
static void |
| 316 |
> |
maptext(void) /* map our text */ |
| 317 |
|
{ |
| 318 |
|
register LINE *curl; |
| 319 |
|
int l, len; |
| 329 |
|
} |
| 330 |
|
|
| 331 |
|
|
| 332 |
< |
mapglyph(gl, tx0, ty0) /* convert a glyph */ |
| 333 |
< |
GLYPH *gl; |
| 334 |
< |
int tx0, ty0; |
| 332 |
> |
static void |
| 333 |
> |
mapglyph( /* convert a glyph */ |
| 334 |
> |
GLYPH *gl, |
| 335 |
> |
int tx0, |
| 336 |
> |
int ty0 |
| 337 |
> |
) |
| 338 |
|
{ |
| 339 |
|
int n; |
| 340 |
|
register GORD *gp; |
| 355 |
|
} |
| 356 |
|
|
| 357 |
|
|
| 358 |
< |
mapcoord(p, tx, ty) /* map text to picture coordinates */ |
| 359 |
< |
int p[2], tx, ty; |
| 358 |
> |
static void |
| 359 |
> |
mapcoord( /* map text to picture coordinates */ |
| 360 |
> |
int p[2], |
| 361 |
> |
int tx, |
| 362 |
> |
int ty |
| 363 |
> |
) |
| 364 |
|
{ |
| 365 |
|
tx = (long)tx*cwidth >> 8; |
| 366 |
|
ty = (long)ty*cheight >> 8; |
| 386 |
|
} |
| 387 |
|
|
| 388 |
|
|
| 389 |
< |
mapedge(x, y, run, rise) /* map an edge */ |
| 390 |
< |
register int x, y; |
| 391 |
< |
int run, rise; |
| 389 |
> |
static void |
| 390 |
> |
mapedge( /* map an edge */ |
| 391 |
> |
register int x, |
| 392 |
> |
register int y, |
| 393 |
> |
int run, |
| 394 |
> |
int rise |
| 395 |
> |
) |
| 396 |
|
{ |
| 397 |
|
int xstep; |
| 398 |
|
int rise2, run2; |
| 427 |
|
} |
| 428 |
|
|
| 429 |
|
|
| 430 |
< |
writemap(fp) /* write out bitmap */ |
| 431 |
< |
FILE *fp; |
| 430 |
> |
static void |
| 431 |
> |
writemap( /* write out bitmap */ |
| 432 |
> |
FILE *fp |
| 433 |
> |
) |
| 434 |
|
{ |
| 435 |
|
COLR pixval[SSS*SSS+1]; /* possible pixel values */ |
| 436 |
|
COLOR ctmp0, ctmp1; |
| 475 |
|
exit(1); |
| 476 |
|
} |
| 477 |
|
} |
| 478 |
< |
free((char *)scanout); |
| 478 |
> |
free((void *)scanout); |
| 479 |
|
} |