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.2 by greg, Thu Dec 19 14:52:00 1991 UTC vs.
Revision 2.4 by greg, Tue Jun 16 15:34:47 1992 UTC

# 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 + #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 */
# 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 + extern char  *getenv();
66   extern char  *malloc(), *calloc();
53 extern FILE  *fropen();
67  
68  
69   main(argc, argv)
# 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 */
# Line 148 | Line 163 | makemap()                      /* create the bit map */
163   }
164  
165  
151 loadfont()                      /* load the font file */
152 {
153        FILE  *fp;
154        char  *err;
155        int  gn, ngv, gv;
156        register GLYPH  *g;
157
158        if ((fp = fropen(fontfile)) == NULL) {
159                fprintf(stderr, "cannot find font file \"%s\"\n",
160                                fontfile);
161                exit(1);
162        }
163        while (fscanf(fp, "%d", &gn) == 1) {    /* get each glyph */
164                if (gn < 0 || gn > 127) {
165                        err = "illegal";
166                        goto fonterr;
167                }
168                if (ourfont[gn] != NULL) {
169                        err = "duplicate";
170                        goto fonterr;
171                }
172                if (fscanf(fp, "%d", &ngv) != 1 ||
173                                ngv < 0 || ngv > 255) {
174                        err = "bad # vertices for";
175                        goto fonterr;
176                }
177                g = (GLYPH *)malloc((2*ngv+1)*sizeof(GLYPH));
178                if (g == NULL)
179                        goto memerr;
180                ourfont[gn] = g;
181                *g++ = ngv;
182                ngv *= 2;
183                while (ngv--) {
184                        if (fscanf(fp, "%d", &gv) != 1 ||
185                                        gv < 0 || gv > 255) {
186                                err = "bad vertex for";
187                                goto fonterr;
188                        }
189                        *g++ = gv;
190                }
191        }
192        fclose(fp);
193        return;
194 fonterr:
195        fprintf(stderr, "%s character (%d) in font file \"%s\"\n",
196                        err, gn, fontfile);
197        exit(1);
198 memerr:
199        fprintf(stderr, "out of memory in loadfont\n");
200        exit(1);
201 }
202
203
166   gettext(fp)                     /* get text from a file */
167   FILE  *fp;
168   {
# Line 210 | 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;
226                if (len > maxline)
227                        maxline = len;
195                  nlines++;
196          }
197          return;
# Line 254 | 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 265 | 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  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines