--- ray/src/px/psign.c 1992/06/16 16:27:37 2.5 +++ ray/src/px/psign.c 1994/02/28 09:25:31 2.16 @@ -1,4 +1,4 @@ -/* Copyright (c) 1991 Regents of the University of California */ +/* Copyright (c) 1992 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -16,19 +16,14 @@ static char SCCSid[] = "$SunId$ LBL"; #include "font.h" -#ifndef SSS -#define SSS 3 /* super-sample size */ -#endif +#include "paths.h" -#define MAXLINE 512 /* longest allowable line */ - -#ifndef DEFPATH -#define DEFPATH ":/usr/local/lib/ray" +#ifndef SSS +#define SSS 3 /* super-sample size */ #endif -#ifndef ULIBVAR -#define ULIBVAR "RAYPATH" -#endif +#define MAXLINE 512 /* longest allowable line */ + char *fontfile = "helvet.fnt"; /* our font file */ COLOR bgcolor = WHTCOLOR; /* background color */ @@ -37,18 +32,19 @@ COLOR fgcolor = BLKCOLOR; /* foreground color */ int direct = 'r'; /* direction (right, up, left, down) */ int cheight = 32*SSS; /* character height */ -double aspect = 1.67; /* height/width character aspect */ +double aspect = 1.67; /* height/width character aspect */ +double spacing = 0.0; /* character spacing */ int cwidth; /* computed character width */ unsigned char *ourbitmap; /* our output bitmap */ int xsiz, ysiz; /* bitmap dimensions */ int xdim; /* size of horizontal scan (bytes) */ -#define bitop(x,y,op) (ourbitmap[(y)*xdim+((x)>>3)] op (1<<((x)&7))) -#define tstbit(x,y) bitop(x,y,&) -#define setbit(x,y) bitop(x,y,|=) -#define clrbit(x,y) bitop(x,y,&=~) -#define tglbit(x,y) bitop(x,y,^=) +#define bitop(x,y,op) (ourbitmap[(y)*xdim+((x)>>3)] op (1<<((x)&7))) +#define tstbit(x,y) bitop(x,y,&) +#define setbit(x,y) bitop(x,y,|=) +#define clrbit(x,y) bitop(x,y,&=~) +#define tglbit(x,y) bitop(x,y,^=) FONT *ourfont; /* our font */ @@ -64,16 +60,15 @@ LINE *ourtext; /* our text */ int nlines, maxline; /* text dimensions */ int maxwidth; /* maximum line width (dvi) */ -extern char *getenv(); -extern char *malloc(), *calloc(); - main(argc, argv) int argc; char *argv[]; { int an; - +#ifdef MSDOS + setmode(fileno(stdout), O_BINARY); +#endif for (an = 1; an < argc && argv[an][0] == '-'; an++) switch (argv[an][1]) { case 'c': /* color */ @@ -109,12 +104,21 @@ char *argv[]; goto unkopt; } break; + case 'x': /* x resolution */ + xsiz = atoi(argv[++an])*SSS; + break; + case 'y': + ysiz = atoi(argv[++an])*SSS; + break; case 'h': /* height of characters */ cheight = atoi(argv[++an])*SSS; break; case 'a': /* aspect ratio */ aspect = atof(argv[++an]); break; + case 's': /* spacing */ + spacing = atof(argv[++an]); + break; default:; unkopt: fprintf(stderr, "%s: unknown option: %s\n", @@ -136,6 +140,7 @@ unkopt: /* convert text to bitmap */ maptext(); /* print header */ + newheader("RADIANCE", stdout); printargs(argc, argv, stdout); fputformat(COLRFMT, stdout); putchar('\n'); @@ -148,29 +153,70 @@ unkopt: makemap() /* create the bit map */ { - cwidth = cheight/aspect + 0.5; + double pictaspect; + if (direct == 'r' || direct == 'l') { - xsiz = (long)maxwidth*cwidth >> 8; - ysiz = nlines*cheight; + if (xsiz <= 0) { + cwidth = cheight/aspect + 0.5; + xsiz = (long)maxwidth*cwidth >> 8; + ysiz = nlines*cheight; + } else if (aspect > FTINY) { + if (ysiz <= 0) + ysiz = cheight*nlines; + pictaspect = 256*nlines*aspect/maxwidth; + if (pictaspect*xsiz < ysiz) + ysiz = pictaspect*xsiz + 0.5; + else + xsiz = ysiz/pictaspect + 0.5; + cheight = ysiz/nlines; + cwidth = cheight/aspect; + } else { + if (ysiz <= 0) + ysiz = cheight*nlines; + pictaspect = (double)ysiz/xsiz; + aspect = pictaspect*maxwidth/(256*nlines); + cheight = ysiz/nlines; + cwidth = cheight/aspect; + } } else { /* reverse orientation */ - xsiz = nlines*cheight; - ysiz = (long)maxwidth*cwidth >> 8; + if (ysiz <= 0) { + cwidth = cheight/aspect + 0.5; + xsiz = nlines*cheight; + ysiz = (long)maxwidth*cwidth >> 8; + } else if (aspect > FTINY) { + if (xsiz <= 0) + xsiz = cheight*nlines; + pictaspect = maxwidth/(256*nlines*aspect); + if (pictaspect*xsiz < ysiz) + ysiz = pictaspect*xsiz + 0.5; + else + xsiz = ysiz/pictaspect + 0.5; + cheight = xsiz/nlines; + cwidth = cheight/aspect; + } else { + if (xsiz <= 0) + xsiz = cheight*nlines; + pictaspect = (double)ysiz/xsiz; + aspect = maxwidth/(256*nlines*pictaspect); + cheight = xsiz/nlines; + cwidth = cheight/aspect; + } } if (xsiz % SSS) xsiz += SSS - xsiz%SSS; if (ysiz % SSS) ysiz += SSS - ysiz%SSS; xdim = (xsiz+7)/8; - ourbitmap = (BYTE *)calloc(ysiz, xdim); + ourbitmap = (BYTE *)bmalloc(ysiz*xdim); if (ourbitmap == NULL) error(SYSTEM, "Out of memory in makemap"); + bzero((char *)ourbitmap, ysiz*xdim); } gettext(fp) /* get text from a file */ FILE *fp; { - char *fgets(); char buf[MAXLINE]; register LINE *curl; int len; @@ -191,7 +237,14 @@ FILE *fp; maxline = len; strncpy(curl->s, buf, len); curl->s[len] = '\0'; -len = uniftext(curl->sp, curl->s, ourfont); + if (spacing < -1./256.) + len = squeeztext(curl->sp, curl->s, ourfont, + (int)(spacing*-256.)); + else if (spacing > 1./256.) + len = proptext(curl->sp, curl->s, ourfont, + (int)(spacing*256.), 3); + else + len = uniftext(curl->sp, curl->s, ourfont); if (len > maxwidth) maxwidth = len; curl->next = ourtext; @@ -227,7 +280,14 @@ char *av[]; ourtext->sp = (short *)malloc(sizeof(short)*(maxline+1)); if (ourtext->sp == NULL) goto memerr; -maxwidth = squeeztext(ourtext->sp, ourtext->s, ourfont, 50); + if (spacing < -1./256.) + maxwidth = squeeztext(ourtext->sp, ourtext->s, ourfont, + (int)(spacing*-256.)); + else if (spacing > 1./256.) + maxwidth = proptext(ourtext->sp, ourtext->s, ourfont, + (int)(spacing*256.), 3); + else + maxwidth = uniftext(ourtext->sp, ourtext->s, ourfont); nlines = 1; return; memerr: @@ -343,7 +403,7 @@ FILE *fp; { COLR pixval[SSS*SSS+1]; /* possible pixel values */ COLOR ctmp0, ctmp1; - double d; + double d; COLR *scanout; int x, y; register int i, j;