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.3 by greg, Sat Jun 6 07:40:51 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  MAXLINE                512     /* longest allowable line */
20  
21 < char  *fontfile = "/usr/local/lib/ray/helvet.fnt";      /* our font file */
21 > #ifndef  DEFPATH
22 > #define  DEFPATH                ":/usr/local/lib/ray"
23 > #endif
24 > #ifndef  ULIBVAR
25 > #define  ULIBVAR                "RAYPATH"
26 > #endif
27  
28 + char  *fontfile = "helvet.fnt";         /* our font file */
29 +
30   COLR  bgcolr = WHTCOLR;                 /* background color */
31   COLR  fgcolr = BLKCOLR;                 /* foreground color */
32  
# Line 39 | Line 48 | int  xdim;                             /* size of horizontal scan (bytes) */
48  
49   typedef unsigned char  GLYPH;
50  
51 < GLYPH  *ourfont[128];                   /* our font */
51 > FONT  *ourfont;                         /* our font */
52  
53 + char  *libpath;                         /* library search path */
54 +
55   typedef struct line {
56          char  *s;               /* line w/o LF */
57          struct line  *next;     /* next line up */
# Line 49 | Line 60 | typedef struct line {
60   LINE  *ourtext;                         /* our text */
61   int  nlines, maxline;                   /* text dimensions */
62  
63 < char  *malloc(), *calloc();
63 > extern char  *getenv();
64 > extern char  *malloc(), *calloc();
65  
66  
67   main(argc, argv)
68   int  argc;
69   char  *argv[];
70   {
59        double  atof();
71          int  an;
72  
73          for (an = 1; an < argc && argv[an][0] == '-'; an++)
# Line 115 | Line 126 | unkopt:
126                                          /* create bit map */
127          makemap();
128                                          /* load font file */
129 <        loadfont();
129 >        if ((libpath = getenv(ULIBVAR)) == NULL)
130 >                libpath = DEFPATH;
131 >        ourfont = getfont(fontfile);
132                                          /* convert text to bitmap */
133          maptext();
134                                          /* print header */
135          printargs(argc, argv, stdout);
136 <        printf("\n\n");
136 >        fputformat(COLRFMT, stdout);
137 >        putchar('\n');
138                                          /* write out bitmap */
139          writemap(stdout);
140  
# Line 147 | Line 161 | makemap()                      /* create the bit map */
161   }
162  
163  
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
164   gettext(fp)                     /* get text from a file */
165   FILE  *fp;
166   {
# Line 269 | Line 230 | maptext()                      /* map our text */
230  
231          for (l = 0, curl = ourtext; curl != NULL; l++, curl = curl->next)
232                  for (c = strlen(curl->s)-1; c >= 0; c--)
233 <                        mapglyph(ourfont[curl->s[c]], c, l);
233 >                        mapglyph(ourfont->fg[curl->s[c]&0xff], c, l);
234   }
235  
236  
237   mapglyph(gl, tx0, ty0)          /* convert a glyph */
238 < register GLYPH  *gl;
238 > GLYPH  *gl;
239   int  tx0, ty0;
240   {
241          int  n;
242 +        register GORD  *gp;
243          int  p0[2], p1[2];
244  
245          if (gl == NULL)
246                  return;
247  
248          tx0 <<= 8; ty0 <<= 8;
249 <        n = *gl++;
250 <        mapcoord(p0, gl[2*n-2]+tx0, gl[2*n-1]+ty0);
249 >        n = gl->nverts;
250 >        gp = gvlist(gl);
251 >        mapcoord(p0, gp[2*n-2]+tx0, gp[2*n-1]+ty0);
252          while (n--) {
253 <                mapcoord(p1, gl[0]+tx0, gl[1]+ty0);
253 >                mapcoord(p1, gp[0]+tx0, gp[1]+ty0);
254                  mapedge(p0[0], p0[1], p1[0]-p0[0], p1[1]-p0[1]);
255                  p0[0] = p1[0]; p0[1] = p1[1];
256 <                gl += 2;
256 >                gp += 2;
257          }
258   }
259  
# Line 390 | Line 353 | FILE  *fp;
353                  }
354          }
355          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        }
356   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines