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

Comparing ray/src/rt/text.c (file contents):
Revision 2.4 by greg, Fri Jun 19 13:07:48 1992 UTC vs.
Revision 2.22 by greg, Tue May 13 17:58:33 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  text.c - functions for text patterns and mixtures.
9 *
10 *     11/12/86
6   */
7  
8 + #include "copyright.h"
9 +
10   #include  "ray.h"
11  
12   #include  "otypes.h"
# Line 45 | Line 42 | static char SCCSid[] = "$SunId$ LBL";
42   *              [spacing]
43   *
44   *  Colortext is identical, except colors are given rather than
45 < *  brightnesses.  Mixtext has foreground and background modifiers:
45 > *  brightnesses.
46   *
47 + *  Mixtext has foreground and background modifiers:
48 + *
49   *      modifier mixtext id
50   *      4+ foremod backmod fontfile text..
51   *      0
# Line 77 | Line 76 | typedef struct {
76          TLINE  tl;                      /* line list */
77   }  TEXT;
78  
80 extern char  *libpath;
81
82 extern char  *fgetword();
83
79   TEXT  *gettext();
80  
81   TLINE  *tlalloc();
82  
83  
84 < text(m, r)
84 > do_text(m, r)
85   register OBJREC  *m;
86   RAY  *r;
87   {
# Line 105 | Line 100 | RAY  *r;
100                  char  *modname = m->oargs.sarg[foreground ? 0 : 1];
101                  if (!strcmp(modname, VOIDID))
102                          omod = OVOID;
103 <                else if ((omod = modifier(modname)) == OVOID) {
103 >                else if ((omod = lastmod(objndx(m), modname)) == OVOID) {
104                          sprintf(errmsg, "undefined modifier \"%s\"", modname);
105                          objerror(m, USER, errmsg);
106                  }
107 <                raytexture(r, omod);
107 >                if (rayshade(r, omod)) {
108 >                        if (m->omod != OVOID)
109 >                                objerror(m, USER, "inappropriate modifier");
110 >                        return(1);
111 >                }
112          } else if (m->otype == PAT_BTEXT) {
113                  if (foreground)
114                          scalecolor(r->pcol, m->oargs.farg[9]);
# Line 127 | Line 126 | RAY  *r;
126                                          m->oargs.farg[14]);
127                  multcolor(r->pcol, cval);
128          }
129 +        return(0);
130   }
131  
132  
# Line 134 | Line 134 | TLINE *
134   tlalloc(s)                      /* allocate and assign text line */
135   char  *s;
136   {
137        extern char  *strcpy();
137          register int  siz;
138          register TLINE  *tl;
139  
# Line 142 | Line 141 | char  *s;
141          if ((tl=(TLINE *)malloc(sizeof(TLINE)+siz)) == NULL ||
142                          (tl->spc=(short *)malloc(siz*sizeof(short))) == NULL)
143                  error(SYSTEM, "out of memory in tlalloc");
145        tl->spc = NULL;
144          tl->next = NULL;
145          strcpy(TLSTR(tl), s);
146          return(tl);
# Line 155 | Line 153 | register OBJREC  *tm;
153   {
154   #define  R      (tm->oargs.farg+3)
155   #define  D      (tm->oargs.farg+6)
158        extern char  *strcpy(), *fgets();
156          FVECT  DxR;
157          double  d;
158          FILE  *fp;
# Line 171 | Line 168 | register OBJREC  *tm;
168          if (tm->oargs.nsargs - tndx(tm) < 1 || tm->oargs.nfargs < sndx(tm))
169                  objerror(tm, USER, "bad # arguments");
170          if ((t = (TEXT *)malloc(sizeof(TEXT))) == NULL)
171 <                goto memerr;
171 >                error(SYSTEM, "out of memory in gettext");
172                                                  /* compute vectors */
173          fcross(DxR, D, R);
174          fcross(t->right, DxR, D);
175 <        d = DOT(D,D)/DOT(t->right,t->right);
175 >        d = DOT(t->right,t->right);
176 >        if (d <= FTINY*FTINY*FTINY*FTINY)
177 >                objerror(tm, USER, "illegal motion vector");
178 >        d = DOT(D,D)/d;
179          for (i = 0; i < 3; i++)
180                  t->right[i] *= d;
181          fcross(t->down, R, DxR);
# Line 196 | Line 196 | register OBJREC  *tm;
196                  tlp = tlp->next;
197          } else {                                /* text file */
198                  if ((s = getpath(tm->oargs.sarg[tndx(tm)],
199 <                                libpath, R_OK)) == NULL) {
199 >                                getrlibpath(), R_OK)) == NULL) {
200                          sprintf(errmsg, "cannot find text file \"%s\"",
201                                          tm->oargs.sarg[tndx(tm)]);
202                          error(USER, errmsg);
# Line 220 | Line 220 | register OBJREC  *tm;
220                                                  /* compute character spacing */
221          i = sndx(tm);
222          d = i < tm->oargs.nfargs ? tm->oargs.farg[i] : 0.0;
223 <        i = d * 256.0;
223 >        i = d * 255.0;
224 >        t->tl.width = 0;
225          for (tlp = t->tl.next; tlp != NULL; tlp = tlp->next) {
225                if ((tlp->spc = (short *)malloc(
226                                (strlen(TLSTR(tlp))+1)*sizeof(short))) == NULL)
227                        goto memerr;
226                  if (i < 0)
227                          tlp->width = squeeztext(tlp->spc, TLSTR(tlp), t->f, -i);
228                  else if (i > 0)
229                          tlp->width = proptext(tlp->spc, TLSTR(tlp), t->f, i, 3);
230                  else
231                          tlp->width = uniftext(tlp->spc, TLSTR(tlp), t->f);
232 +                if (tlp->width > t->tl.width)
233 +                        t->tl.width = tlp->width;
234          }
235                                                  /* we're done */
236          tm->os = (char *)t;
237          return(t);
238 memerr:
239        error(SYSTEM, "out of memory in gettext");
238   #undef  R
239   #undef  D
240   }
# Line 251 | Line 249 | OBJREC  *m;
249          tp = (TEXT *)m->os;
250          if (tp == NULL)
251                  return;
252 <        for (tlp = tp->tl.next; tlp != NULL; tlp = tlp->next) {
253 <                free((char *)tlp->spc);
254 <                free((char *)tlp);
252 >        while ((tlp = tp->tl.next) != NULL) {
253 >                tp->tl.next = tlp->next;
254 >                free((void *)tlp->spc);
255 >                free((void *)tlp);
256          }
257 <        free((char *)tp);
257 >        freefont(tp->f);        /* release font reference */
258 >        free((void *)tp);
259          m->os = NULL;
260   }
261  
# Line 274 | Line 274 | OBJREC  *m;
274          v[0] = p[0] - m->oargs.farg[0];
275          v[1] = p[1] - m->oargs.farg[1];
276          v[2] = p[2] - m->oargs.farg[2];
277 <        h = x = DOT(v, tp->right)*256.;
277 >        x = DOT(v, tp->right);
278 >        i = sndx(m);
279 >        if (i < m->oargs.nfargs)
280 >                x *= tp->f->mwidth + 255.*fabs(m->oargs.farg[i]);
281 >        else
282 >                x *= 255.;
283 >        h = x;
284          i = y = DOT(v, tp->down);
285          if (x < 0.0 || y < 0.0)
286                  return(0);
287          x -= (double)h;
288 <        y = ((i+1) - y)*256.;
288 >        y = ((i+1) - y)*255.;
289                                  /* find the line position */
290          for (tlp = tp->tl.next; tlp != NULL; tlp = tlp->next)
291                  if (--i < 0)
# Line 287 | Line 293 | OBJREC  *m;
293          if (tlp == NULL || h >= tlp->width)
294                  return(0);
295          for (i = 0; (h -= tlp->spc[i]) >= 0; i++)
296 <                if (h < 256 && inglyph(h+x, y,
296 >                if (h < 255 && inglyph(h+x, y,
297                                  tp->f->fg[TLSTR(tlp)[i]&0xff]))
298                          return(1);
299          return(0);
# Line 295 | Line 301 | OBJREC  *m;
301  
302  
303   inglyph(x, y, gl)               /* (x,y) within font glyph gl? */
304 < double  x, y;
304 > double  x, y;           /* real coordinates in range [0,255) */
305   register GLYPH  *gl;
306   {
307          int  n, ncross;
308 <        int  xtc, ytc;
308 >        int  xlb, ylb;
309 >        int  tv;
310          register GORD  *p0, *p1;
311  
312          if (gl == NULL)
313                  return(0);
314 <        xtc = x + 0.5;                  /* compute test coordinates */
315 <        ytc = y + 0.5;
316 <        if (gl->left > xtc || gl->right < xtc ||
317 <                        gl->bottom > ytc || gl->top < ytc)
318 <                return(0);      /* outside extent */
314 >        xlb = x;
315 >        ylb = y;
316 >        if (gl->left > xlb || gl->right <= xlb ||       /* check extent */
317 >                        gl->bottom > ylb || gl->top <= ylb)
318 >                return(0);
319 >        xlb = xlb<<1 | 1;               /* add 1/2 to test points... */
320 >        ylb = ylb<<1 | 1;               /* ...so no equal comparisons */
321          n = gl->nverts;                 /* get # of vertices */
322          p0 = gvlist(gl) + 2*(n-1);      /* connect last to first */
323          p1 = gvlist(gl);
324          ncross = 0;
325                                          /* positive x axis cross test */
326          while (n--) {
327 <                if ((p0[1] > ytc) ^ (p1[1] > ytc))
328 <                        if (p0[0] > xtc && p1[0] > xtc)
327 >                if ((p0[1]<<1 > ylb) ^ (p1[1]<<1 > ylb)) {
328 >                        tv = p0[0]<<1 > xlb | (p1[0]<<1 > xlb) << 1;
329 >                        if (tv == 03)
330                                  ncross++;
331 <                        else if (p0[0] > xtc || p1[0] > xtc)
331 >                        else if (tv)
332                                  ncross += (p1[1] > p0[1]) ^
333                                                  ((p0[1]-y)*(p1[0]-x) >
334                                                  (p0[0]-x)*(p1[1]-y));
335 +                }
336                  p0 = p1;
337                  p1 += 2;
338          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines