ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/psign.c
(Generate patch)

Comparing ray/src/px/psign.c (file contents):
Revision 2.3 by greg, Sat Jun 6 07:40:51 1992 UTC vs.
Revision 2.11 by greg, Wed Jul 8 13:58:10 1992 UTC

# Line 1 | Line 1
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";
# Line 16 | Line 16 | static char SCCSid[] = "$SunId$ LBL";
16  
17   #include  "font.h"
18  
19 + #ifndef  SSS
20 + #define  SSS                    3       /* super-sample size */
21 + #endif
22 +
23   #define  MAXLINE                512     /* longest allowable line */
24  
25   #ifndef  DEFPATH
# Line 27 | Line 31 | static char SCCSid[] = "$SunId$ LBL";
31  
32   char  *fontfile = "helvet.fnt";         /* our font file */
33  
34 < COLR  bgcolr = WHTCOLR;                 /* background color */
35 < COLR  fgcolr = BLKCOLR;                 /* foreground color */
34 > COLOR  bgcolor = WHTCOLOR;              /* background color */
35 > COLOR  fgcolor = BLKCOLOR;              /* foreground color */
36  
37   int  direct = 'r';                      /* direction (right, up, left, down) */
38  
39 < int  cheight = 32;                      /* character height */
39 > int  cheight = 32*SSS;                  /* character height */
40   double  aspect = 1.67;                  /* height/width character aspect */
41 + double  spacing = 0.0;                  /* character spacing */
42   int  cwidth;                            /* computed character width */
43  
44   unsigned char  *ourbitmap;              /* our output bitmap */
# Line 46 | Line 51 | int  xdim;                             /* size of horizontal scan (bytes) */
51   #define  clrbit(x,y)            bitop(x,y,&=~)
52   #define  tglbit(x,y)            bitop(x,y,^=)
53  
49 typedef unsigned char  GLYPH;
50
54   FONT  *ourfont;                         /* our font */
55  
56   char  *libpath;                         /* library search path */
57  
58   typedef struct line {
59          char  *s;               /* line w/o LF */
60 +        short  *sp;             /* character spacing */
61          struct line  *next;     /* next line up */
62   } LINE;
63  
64   LINE  *ourtext;                         /* our text */
65   int  nlines, maxline;                   /* text dimensions */
66 + int  maxwidth;                          /* maximum line width (dvi) */
67  
68   extern char  *getenv();
64 extern char  *malloc(), *calloc();
69  
70  
71   main(argc, argv)
# Line 75 | Line 79 | char  *argv[];
79                  case 'c':                       /* color */
80                          switch (argv[an][2]) {
81                          case 'f':                       /* foreground */
82 <                                setcolr(fgcolr, atof(argv[an+1]),
82 >                                setcolor(fgcolor, atof(argv[an+1]),
83                                                  atof(argv[an+2]),
84                                                  atof(argv[an+3]));
85                                  an += 3;
86                                  break;
87                          case 'b':                       /* background */
88 <                                setcolr(bgcolr, atof(argv[an+1]),
88 >                                setcolor(bgcolor, atof(argv[an+1]),
89                                                  atof(argv[an+2]),
90                                                  atof(argv[an+3]));
91                                  an += 3;
# Line 105 | Line 109 | char  *argv[];
109                                  goto unkopt;
110                          }
111                          break;
112 +                case 'x':                       /* x resolution */
113 +                        xsiz = atoi(argv[++an])*SSS;
114 +                        break;
115 +                case 'y':
116 +                        ysiz = atoi(argv[++an])*SSS;
117 +                        break;
118                  case 'h':                       /* height of characters */
119 <                        cheight = atoi(argv[++an]);
119 >                        cheight = atoi(argv[++an])*SSS;
120                          break;
121                  case 'a':                       /* aspect ratio */
122                          aspect = atof(argv[++an]);
123                          break;
124 +                case 's':                       /* spacing */
125 +                        spacing = atof(argv[++an]);
126 +                        break;
127                  default:;
128   unkopt:
129                          fprintf(stderr, "%s: unknown option: %s\n",
130                                          argv[0], argv[an]);
131                          exit(1);
132                  }
133 +                                        /* load font file */
134 +        if ((libpath = getenv(ULIBVAR)) == NULL)
135 +                libpath = DEFPATH;
136 +        ourfont = getfont(fontfile);
137                                          /* get text */
138          if (an == argc)
139                  gettext(stdin);
# Line 125 | Line 142 | unkopt:
142  
143                                          /* create bit map */
144          makemap();
128                                        /* load font file */
129        if ((libpath = getenv(ULIBVAR)) == NULL)
130                libpath = DEFPATH;
131        ourfont = getfont(fontfile);
145                                          /* convert text to bitmap */
146          maptext();
147                                          /* print header */
# Line 144 | Line 157 | unkopt:
157  
158   makemap()                       /* create the bit map */
159   {
160 <        cwidth = cheight/aspect + 0.5;
160 >        double  pictaspect;
161 >        
162          if (direct == 'r' || direct == 'l') {
163 <                xsiz = maxline*cwidth;
164 <                ysiz = nlines*cheight;
163 >                if (xsiz <= 0) {
164 >                        cwidth = cheight/aspect + 0.5;
165 >                        xsiz = (long)maxwidth*cwidth >> 8;
166 >                        ysiz = nlines*cheight;
167 >                } else if (aspect > FTINY) {
168 >                        if (ysiz <= 0)
169 >                                ysiz = cheight*nlines;
170 >                        pictaspect = 256*nlines*aspect/maxwidth;
171 >                        if (pictaspect*xsiz < ysiz)
172 >                                ysiz = pictaspect*xsiz + 0.5;
173 >                        else
174 >                                xsiz = ysiz/pictaspect + 0.5;
175 >                        cheight = ysiz/nlines;
176 >                        cwidth = cheight/aspect + 0.5;
177 >                } else {
178 >                        if (ysiz <= 0)
179 >                                ysiz = cheight*nlines;
180 >                        pictaspect = (double)ysiz/xsiz;
181 >                        aspect = pictaspect*maxwidth/(256*nlines);
182 >                        cheight = ysiz/nlines;
183 >                        cwidth = cheight/aspect + 0.5;
184 >                }
185          } else {                        /* reverse orientation */
186 <                xsiz = nlines*cheight;
187 <                ysiz = maxline*cwidth;
186 >                if (ysiz <= 0) {
187 >                        cwidth = cheight/aspect + 0.5;
188 >                        xsiz = nlines*cheight;
189 >                        ysiz = (long)maxwidth*cwidth >> 8;
190 >                } else if (aspect > FTINY) {
191 >                        if (xsiz <= 0)
192 >                                xsiz = cheight*nlines;
193 >                        pictaspect = maxwidth/(256*nlines*aspect);
194 >                        if (pictaspect*xsiz < ysiz)
195 >                                ysiz = pictaspect*xsiz + 0.5;
196 >                        else
197 >                                xsiz = ysiz/pictaspect + 0.5;
198 >                        cheight = xsiz/nlines;
199 >                        cwidth = cheight/aspect + 0.5;
200 >                } else {
201 >                        if (xsiz <= 0)
202 >                                xsiz = cheight*nlines;
203 >                        pictaspect = (double)ysiz/xsiz;
204 >                        aspect = maxwidth/(256*nlines*pictaspect);
205 >                        cheight = xsiz/nlines;
206 >                        cwidth = cheight/aspect + 0.5;
207 >                }
208          }
209 +        if (xsiz % SSS)
210 +                xsiz += SSS - xsiz%SSS;
211 +        if (ysiz % SSS)
212 +                ysiz += SSS - ysiz%SSS;
213          xdim = (xsiz+7)/8;
214 <        ourbitmap = (BYTE *)calloc(ysiz, xdim);
215 <        if (ourbitmap == NULL) {
216 <                fprintf(stderr, "out of memory in makemap\n");
217 <                exit(1);
160 <        }
214 >        ourbitmap = (BYTE *)bmalloc(ysiz*xdim);
215 >        if (ourbitmap == NULL)
216 >                error(SYSTEM, "Out of memory in makemap");
217 >        bzero((char *)ourbitmap, ysiz*xdim);
218   }
219  
220  
# Line 170 | Line 227 | FILE  *fp;
227          int  len;
228  
229          maxline = 0;
230 +        maxwidth = 0;
231          nlines = 0;
232          while (fgets(buf, MAXLINE, fp) != NULL) {
233                  curl = (LINE *)malloc(sizeof(LINE));
234                  if (curl == NULL)
235                          goto memerr;
236                  len = strlen(buf);
237 <                curl->s = malloc(len--);
238 <                if (curl->s == NULL)
237 >                curl->s = malloc(len);
238 >                curl->sp = (short *)malloc(sizeof(short)*len--);
239 >                if (curl->s == NULL | curl->sp == NULL)
240                          goto memerr;
241 +                if (len > maxline)
242 +                        maxline = len;
243                  strncpy(curl->s, buf, len);
244                  curl->s[len] = '\0';
245 +                if (spacing < -1./256.)
246 +                        len = squeeztext(curl->sp, curl->s, ourfont,
247 +                                        (int)(spacing*-256.0));
248 +                else if (spacing > 1./256.)
249 +                        len = proptext(curl->sp, curl->s, ourfont,
250 +                                        (int)(spacing*256.0), 3);
251 +                else
252 +                        len = uniftext(curl->sp, curl->s, ourfont);
253 +                if (len > maxwidth)
254 +                        maxwidth = len;
255                  curl->next = ourtext;
256                  ourtext = curl;
186                if (len > maxline)
187                        maxline = len;
257                  nlines++;
258          }
259          return;
260   memerr:
261 <        fprintf(stderr, "out of memory in gettext\n");
193 <        exit(1);
261 >        error(SYSTEM, "Out of memory in gettext");
262   }
263  
264  
# Line 214 | Line 282 | char  *av[];
282          *--cp = '\0';
283          ourtext->next = NULL;
284          maxline = strlen(ourtext->s);
285 +        ourtext->sp = (short *)malloc(sizeof(short)*(maxline+1));
286 +        if (ourtext->sp == NULL)
287 +                goto memerr;
288 +        if (spacing < 0.0)
289 +                maxwidth = squeeztext(ourtext->sp, ourtext->s, ourfont,
290 +                                (int)(spacing*-256.0));
291 +        else if (spacing > 0.0)
292 +                maxwidth = proptext(ourtext->sp, ourtext->s, ourfont,
293 +                                (int)(spacing*256.0), 3);
294 +        else
295 +                maxwidth = uniftext(ourtext->sp, ourtext->s, ourfont);
296          nlines = 1;
297          return;
298   memerr:
299 <        fprintf(stderr, "out of memory in arg_text\n");
221 <        exit(1);
299 >        error(SYSTEM, "Out of memory in arg_text");
300   }
301  
302  
303   maptext()                       /* map our text */
304   {
305          register LINE  *curl;
306 <        int  l;
307 <        register int  c;
306 >        int  l, len;
307 >        register int  i, c;
308  
309 <        for (l = 0, curl = ourtext; curl != NULL; l++, curl = curl->next)
310 <                for (c = strlen(curl->s)-1; c >= 0; c--)
311 <                        mapglyph(ourfont->fg[curl->s[c]&0xff], c, l);
309 >        for (l = 0, curl = ourtext; curl != NULL; l += 256, curl = curl->next) {
310 >                len = strlen(curl->s); c = 0;
311 >                for (i = 0; i < len; i++) {
312 >                        c += curl->sp[i];
313 >                        mapglyph(ourfont->fg[curl->s[i]&0xff], c, l);
314 >                }
315 >        }
316   }
317  
318  
# Line 245 | Line 327 | int  tx0, ty0;
327          if (gl == NULL)
328                  return;
329  
248        tx0 <<= 8; ty0 <<= 8;
330          n = gl->nverts;
331          gp = gvlist(gl);
332          mapcoord(p0, gp[2*n-2]+tx0, gp[2*n-1]+ty0);
# Line 325 | Line 406 | int  run, rise;
406   writemap(fp)                    /* write out bitmap */
407   FILE  *fp;
408   {
409 +        COLR  pixval[SSS*SSS+1];        /* possible pixel values */
410 +        COLOR  ctmp0, ctmp1;
411 +        double  d;
412          COLR  *scanout;
413 <        int  y;
414 <        register int  x;
413 >        int  x, y;
414 >        register int  i, j;
415 >        int  cnt;
416          register int  inglyph;
417  
418 <        fprintf(fp, "-Y %d +X %d\n", ysiz, xsiz);
418 >        fprintf(fp, "-Y %d +X %d\n", ysiz/SSS, xsiz/SSS);
419  
420 <        scanout = (COLR *)malloc(xsiz*sizeof(COLR));
421 <        if (scanout == NULL) {
422 <                fprintf(stderr, "out of memory in writemap\n");
423 <                exit(1);
420 >        scanout = (COLR *)malloc(xsiz/SSS*sizeof(COLR));
421 >        if (scanout == NULL)
422 >                error(SYSTEM, "Out of memory in writemap");
423 >        for (i = 0; i <= SSS*SSS; i++) {        /* compute possible values */
424 >                copycolor(ctmp0, fgcolor);
425 >                d = (double)i/(SSS*SSS);
426 >                scalecolor(ctmp0, d);
427 >                copycolor(ctmp1, bgcolor);
428 >                d = 1.0 - d;
429 >                scalecolor(ctmp1, d);
430 >                addcolor(ctmp0, ctmp1);
431 >                setcolr(pixval[i], colval(ctmp0,RED),
432 >                                colval(ctmp0,GRN), colval(ctmp0,BLU));
433          }
434 <        for (y = ysiz-1; y >= 0; y--) {
434 >        for (y = ysiz/SSS-1; y >= 0; y--) {
435                  inglyph = 0;
436 <                for (x = 0; x < xsiz; x++) {
437 <                        if (tstbit(x, y))
438 <                                inglyph ^= 1;
439 <                        if (inglyph)
440 <                                copycolr(scanout[x], fgcolr);
441 <                        else
442 <                                copycolr(scanout[x], bgcolr);
436 >                for (x = 0; x < xsiz/SSS; x++) {
437 >                        cnt = 0;
438 >                        for (j = 0; j < SSS; j++)
439 >                                for (i = 0; i < SSS; i++) {
440 >                                        if (tstbit(x*SSS+i, y*SSS+j))
441 >                                                inglyph ^= 1<<j;
442 >                                        if (inglyph & 1<<j)
443 >                                                cnt++;
444 >                                }
445 >                        copycolr(scanout[x], pixval[cnt]);
446                  }
447 <                if (fwritecolrs(scanout, xsiz, fp) < 0) {
447 >                if (fwritecolrs(scanout, xsiz/SSS, fp) < 0) {
448                          fprintf(stderr, "write error in writemap\n");
449                          exit(1);
450                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines