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 1.1 by greg, Thu Feb 2 10:49:28 1989 UTC vs.
Revision 2.4 by greg, Tue Jun 16 15:34:47 1992 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1987 Regents of the University of California */
1 > /* Copyright (c) 1991 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10   *      7/1/87
11   */
12  
13 < #include  <stdio.h>
13 > #include  "standard.h"
14  
15   #include  "color.h"
16  
17 + #include  "font.h"
18 +
19 + #define  SSS                    2       /* super-sample size */
20 +
21   #define  MAXLINE                512     /* longest allowable line */
22  
23 < char  *fontfile = "/usr/local/lib/ray/helvet.fnt";      /* our font file */
23 > #ifndef  DEFPATH
24 > #define  DEFPATH                ":/usr/local/lib/ray"
25 > #endif
26 > #ifndef  ULIBVAR
27 > #define  ULIBVAR                "RAYPATH"
28 > #endif
29  
30 + char  *fontfile = "helvet.fnt";         /* our font file */
31 +
32   COLR  bgcolr = WHTCOLR;                 /* background color */
33   COLR  fgcolr = BLKCOLR;                 /* foreground color */
34  
# Line 37 | Line 48 | int  xdim;                             /* size of horizontal scan (bytes) */
48   #define  clrbit(x,y)            bitop(x,y,&=~)
49   #define  tglbit(x,y)            bitop(x,y,^=)
50  
51 < typedef unsigned char  GLYPH;
51 > FONT  *ourfont;                         /* our font */
52  
53 < GLYPH  *ourfont[128];                   /* our font */
53 > char  *libpath;                         /* library search path */
54  
55   typedef struct line {
56          char  *s;               /* line w/o LF */
57 +        short  *sp;             /* character spacing */
58          struct line  *next;     /* next line up */
59   } LINE;
60  
61   LINE  *ourtext;                         /* our text */
62   int  nlines, maxline;                   /* text dimensions */
63 + int  maxwidth;                          /* maximum line width (dvi) */
64  
65 < char  *malloc(), *calloc();
65 > extern char  *getenv();
66 > extern char  *malloc(), *calloc();
67  
68  
69   main(argc, argv)
70   int  argc;
71   char  *argv[];
72   {
59        double  atof();
73          int  an;
74  
75          for (an = 1; an < argc && argv[an][0] == '-'; an++)
# Line 106 | Line 119 | unkopt:
119                                          argv[0], argv[an]);
120                          exit(1);
121                  }
122 +                                        /* load font file */
123 +        if ((libpath = getenv(ULIBVAR)) == NULL)
124 +                libpath = DEFPATH;
125 +        ourfont = getfont(fontfile);
126                                          /* get text */
127          if (an == argc)
128                  gettext(stdin);
# Line 114 | Line 131 | unkopt:
131  
132                                          /* create bit map */
133          makemap();
117                                        /* load font file */
118        loadfont();
134                                          /* convert text to bitmap */
135          maptext();
136                                          /* print header */
137          printargs(argc, argv, stdout);
138 <        printf("\n\n");
138 >        fputformat(COLRFMT, stdout);
139 >        putchar('\n');
140                                          /* write out bitmap */
141          writemap(stdout);
142  
# Line 147 | Line 163 | makemap()                      /* create the bit map */
163   }
164  
165  
150 loadfont()                      /* load the font file */
151 {
152        FILE  *fp;
153        char  *err;
154        int  gn, ngv, gv;
155        register GLYPH  *g;
156
157        if ((fp = fopen(fontfile, "r")) == NULL) {
158                fprintf(stderr, "cannot open font file \"%s\"\n",
159                                fontfile);
160                exit(1);
161        }
162        while (fscanf(fp, "%d", &gn) == 1) {    /* get each glyph */
163                if (gn < 0 || gn > 127) {
164                        err = "illegal";
165                        goto fonterr;
166                }
167                if (ourfont[gn] != NULL) {
168                        err = "duplicate";
169                        goto fonterr;
170                }
171                if (fscanf(fp, "%d", &ngv) != 1 ||
172                                ngv < 0 || ngv > 255) {
173                        err = "bad # vertices for";
174                        goto fonterr;
175                }
176                g = (GLYPH *)malloc((2*ngv+1)*sizeof(GLYPH));
177                if (g == NULL)
178                        goto memerr;
179                ourfont[gn] = g;
180                *g++ = ngv;
181                ngv *= 2;
182                while (ngv--) {
183                        if (fscanf(fp, "%d", &gv) != 1 ||
184                                        gv < 0 || gv > 255) {
185                                err = "bad vertex for";
186                                goto fonterr;
187                        }
188                        *g++ = gv;
189                }
190        }
191        fclose(fp);
192        return;
193 fonterr:
194        fprintf(stderr, "%s character (%d) in font file \"%s\"\n",
195                        err, gn, fontfile);
196        exit(1);
197 memerr:
198        fprintf(stderr, "out of memory in loadfont\n");
199        exit(1);
200 }
201
202
166   gettext(fp)                     /* get text from a file */
167   FILE  *fp;
168   {
# Line 209 | Line 172 | FILE  *fp;
172          int  len;
173  
174          maxline = 0;
175 +        maxwidth = 0;
176          nlines = 0;
177          while (fgets(buf, MAXLINE, fp) != NULL) {
178                  curl = (LINE *)malloc(sizeof(LINE));
179                  if (curl == NULL)
180                          goto memerr;
181                  len = strlen(buf);
182 <                curl->s = malloc(len--);
183 <                if (curl->s == NULL)
182 >                curl->s = malloc(len);
183 >                curl->sp = (short *)malloc(sizeof(short)*len--);
184 >                if (curl->s == NULL | curl->sp == NULL)
185                          goto memerr;
186 +                if (len > maxline)
187 +                        maxline = len;
188                  strncpy(curl->s, buf, len);
189                  curl->s[len] = '\0';
190 + len = uniftext(curl->sp, curl->s, ourfont);
191 +                if (len > maxwidth)
192 +                        maxwidth = len;
193                  curl->next = ourtext;
194                  ourtext = curl;
225                if (len > maxline)
226                        maxline = len;
195                  nlines++;
196          }
197          return;
# Line 253 | Line 221 | char  *av[];
221          *--cp = '\0';
222          ourtext->next = NULL;
223          maxline = strlen(ourtext->s);
224 +        ourtext->sp = (short *)malloc(sizeof(short)*(maxline+1));
225 +        if (ourtext->sp == NULL)
226 +                goto memerr;
227 + maxwidth = uniftext(ourtext->sp, ourtext->s, ourfont);
228          nlines = 1;
229          return;
230   memerr:
# Line 264 | Line 236 | memerr:
236   maptext()                       /* map our text */
237   {
238          register LINE  *curl;
239 <        int  l;
240 <        register int  c;
239 >        int  l, len;
240 >        register int  i, c;
241  
242 <        for (l = 0, curl = ourtext; curl != NULL; l++, curl = curl->next)
243 <                for (c = strlen(curl->s)-1; c >= 0; c--)
244 <                        mapglyph(ourfont[curl->s[c]], c, l);
242 >        for (l = 0, curl = ourtext; curl != NULL; l += 256, curl = curl->next) {
243 >                len = strlen(curl->s); c = 0;
244 >                for (i = 0; i < len; i++) {
245 >                        c += curl->sp[i];
246 >                        mapglyph(ourfont->fg[curl->s[i]&0xff], c, l);
247 >                }
248 >        }
249   }
250  
251  
252   mapglyph(gl, tx0, ty0)          /* convert a glyph */
253 < register GLYPH  *gl;
253 > GLYPH  *gl;
254   int  tx0, ty0;
255   {
256          int  n;
257 +        register GORD  *gp;
258          int  p0[2], p1[2];
259  
260          if (gl == NULL)
261                  return;
262  
263 <        tx0 <<= 8; ty0 <<= 8;
264 <        n = *gl++;
265 <        mapcoord(p0, gl[2*n-2]+tx0, gl[2*n-1]+ty0);
263 >        n = gl->nverts;
264 >        gp = gvlist(gl);
265 >        mapcoord(p0, gp[2*n-2]+tx0, gp[2*n-1]+ty0);
266          while (n--) {
267 <                mapcoord(p1, gl[0]+tx0, gl[1]+ty0);
267 >                mapcoord(p1, gp[0]+tx0, gp[1]+ty0);
268                  mapedge(p0[0], p0[1], p1[0]-p0[0], p1[1]-p0[1]);
269                  p0[0] = p1[0]; p0[1] = p1[1];
270 <                gl += 2;
270 >                gp += 2;
271          }
272   }
273  
# Line 390 | Line 367 | FILE  *fp;
367                  }
368          }
369          free((char *)scanout);
393 }
394
395
396 printargs(ac, av, fp)           /* print arguments to a file */
397 int  ac;
398 char  **av;
399 FILE  *fp;
400 {
401        while (ac-- > 0) {
402                fputs(*av++, fp);
403                putc(' ', fp);
404        }
370   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines