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.5 by greg, Fri Jun 19 14:20:22 1992 UTC vs.
Revision 2.26 by greg, Tue Jul 8 18:25:00 2014 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  "ray.h"
8 > #include "copyright.h"
9  
10 + #include  "ray.h"
11 + #include  "paths.h"
12   #include  "otypes.h"
13 <
13 > #include  "rtotypes.h"
14   #include  "font.h"
15  
16   /*
# 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  
79 < extern char  *libpath;
79 > static TLINE * tlalloc(char *s);
80 > static TEXT * gettext(OBJREC *tm);
81 > static int intext(FVECT p, OBJREC *m);
82 > static int inglyph(double x, double y, GLYPH *gl);
83  
82 extern char  *fgetword();
84  
85 < TEXT  *gettext();
86 <
87 < TLINE  *tlalloc();
88 <
89 <
89 < text(m, r)
90 < register OBJREC  *m;
91 < RAY  *r;
85 > int
86 > do_text(
87 >        OBJREC  *m,
88 >        RAY  *r
89 > )
90   {
91          FVECT  v;
92          int  foreground;
# Line 105 | Line 103 | RAY  *r;
103                  char  *modname = m->oargs.sarg[foreground ? 0 : 1];
104                  if (!strcmp(modname, VOIDID))
105                          omod = OVOID;
106 <                else if ((omod = modifier(modname)) == OVOID) {
106 >                else if ((omod = lastmod(objndx(m), modname)) == OVOID) {
107                          sprintf(errmsg, "undefined modifier \"%s\"", modname);
108                          objerror(m, USER, errmsg);
109                  }
110 <                raytexture(r, omod);
110 >                if (rayshade(r, omod)) {
111 >                        if (m->omod != OVOID)
112 >                                objerror(m, USER, "inappropriate modifier");
113 >                        return(1);
114 >                }
115          } else if (m->otype == PAT_BTEXT) {
116                  if (foreground)
117                          scalecolor(r->pcol, m->oargs.farg[9]);
# Line 127 | Line 129 | RAY  *r;
129                                          m->oargs.farg[14]);
130                  multcolor(r->pcol, cval);
131          }
132 +        return(0);
133   }
134  
135  
136 < TLINE *
137 < tlalloc(s)                      /* allocate and assign text line */
138 < char  *s;
136 > static TLINE *
137 > tlalloc(                        /* allocate and assign text line */
138 >        char  *s
139 > )
140   {
141 <        extern char  *strcpy();
142 <        register int  siz;
139 <        register TLINE  *tl;
141 >        int  siz;
142 >        TLINE  *tl;
143  
144          siz = strlen(s) + 1;
145          if ((tl=(TLINE *)malloc(sizeof(TLINE)+siz)) == NULL ||
146                          (tl->spc=(short *)malloc(siz*sizeof(short))) == NULL)
147                  error(SYSTEM, "out of memory in tlalloc");
145        tl->spc = NULL;
148          tl->next = NULL;
149          strcpy(TLSTR(tl), s);
150          return(tl);
151   }
152  
153  
154 < TEXT *
155 < gettext(tm)                     /* get text structure for material */
156 < register OBJREC  *tm;
154 > static TEXT *
155 > gettext(                        /* get text structure for material */
156 >        OBJREC  *tm
157 > )
158   {
159   #define  R      (tm->oargs.farg+3)
160   #define  D      (tm->oargs.farg+6)
158        extern char  *strcpy(), *fgets();
161          FVECT  DxR;
162          double  d;
163          FILE  *fp;
164          char  linbuf[512];
165          TEXT  *t;
166 <        register int  i;
167 <        register TLINE  *tlp;
168 <        register char  *s;
166 >        int  i;
167 >        TLINE  *tlp;
168 >        char  *s;
169  
170          if ((t = (TEXT *)tm->os) != NULL)
171                  return(t);
# Line 171 | Line 173 | register OBJREC  *tm;
173          if (tm->oargs.nsargs - tndx(tm) < 1 || tm->oargs.nfargs < sndx(tm))
174                  objerror(tm, USER, "bad # arguments");
175          if ((t = (TEXT *)malloc(sizeof(TEXT))) == NULL)
176 <                goto memerr;
176 >                error(SYSTEM, "out of memory in gettext");
177                                                  /* compute vectors */
178          fcross(DxR, D, R);
179          fcross(t->right, DxR, D);
180 <        d = DOT(D,D)/DOT(t->right,t->right);
180 >        d = DOT(t->right,t->right);
181 >        if (d <= FTINY*FTINY*FTINY*FTINY)
182 >                objerror(tm, USER, "illegal motion vector");
183 >        d = DOT(D,D)/d;
184          for (i = 0; i < 3; i++)
185                  t->right[i] *= d;
186          fcross(t->down, R, DxR);
# Line 196 | Line 201 | register OBJREC  *tm;
201                  tlp = tlp->next;
202          } else {                                /* text file */
203                  if ((s = getpath(tm->oargs.sarg[tndx(tm)],
204 <                                libpath, R_OK)) == NULL) {
204 >                                getrlibpath(), R_OK)) == NULL) {
205                          sprintf(errmsg, "cannot find text file \"%s\"",
206                                          tm->oargs.sarg[tndx(tm)]);
207                          error(USER, errmsg);
# Line 220 | Line 225 | register OBJREC  *tm;
225                                                  /* compute character spacing */
226          i = sndx(tm);
227          d = i < tm->oargs.nfargs ? tm->oargs.farg[i] : 0.0;
228 <        i = d * 256.0;
228 >        i = d * 255.0;
229 >        t->tl.width = 0;
230          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;
231                  if (i < 0)
232                          tlp->width = squeeztext(tlp->spc, TLSTR(tlp), t->f, -i);
233                  else if (i > 0)
234                          tlp->width = proptext(tlp->spc, TLSTR(tlp), t->f, i, 3);
235                  else
236                          tlp->width = uniftext(tlp->spc, TLSTR(tlp), t->f);
237 +                if (tlp->width > t->tl.width)
238 +                        t->tl.width = tlp->width;
239          }
240                                                  /* we're done */
241          tm->os = (char *)t;
242          return(t);
238 memerr:
239        error(SYSTEM, "out of memory in gettext");
243   #undef  R
244   #undef  D
245   }
246  
247  
248 < freetext(m)                     /* free text structures associated with m */
249 < OBJREC  *m;
248 > void
249 > freetext(                       /* free text structures associated with m */
250 >        OBJREC  *m
251 > )
252   {
253 <        register TEXT  *tp;
254 <        register TLINE  *tlp;
253 >        TEXT  *tp;
254 >        TLINE  *tlp;
255  
256          tp = (TEXT *)m->os;
257          if (tp == NULL)
258                  return;
259 <        for (tlp = tp->tl.next; tlp != NULL; tlp = tlp->next) {
260 <                free((char *)tlp->spc);
261 <                free((char *)tlp);
259 >        while ((tlp = tp->tl.next) != NULL) {
260 >                tp->tl.next = tlp->next;
261 >                free((void *)tlp->spc);
262 >                free((void *)tlp);
263          }
264 <        free((char *)tp);
264 >        freefont(tp->f);        /* release font reference */
265 >        free((void *)tp);
266          m->os = NULL;
267   }
268  
269  
270 < intext(p, m)                    /* check to see if p is in text glyph */
271 < FVECT  p;
272 < OBJREC  *m;
270 > static int
271 > intext(                 /* check to see if p is in text glyph */
272 >        FVECT  p,
273 >        OBJREC  *m
274 > )
275   {
276 <        register TEXT  *tp;
277 <        register TLINE  *tlp;
276 >        TEXT  *tp;
277 >        TLINE  *tlp;
278          FVECT  v;
279          double  y, x;
280 <        register int  i, h;
280 >        int  i, h;
281                                  /* first, compute position in text */
282          tp = gettext(m);
283          v[0] = p[0] - m->oargs.farg[0];
284          v[1] = p[1] - m->oargs.farg[1];
285          v[2] = p[2] - m->oargs.farg[2];
286 <        h = x = DOT(v, tp->right)*256.;
286 >        x = DOT(v, tp->right);
287 >        i = sndx(m);
288 >        if (i < m->oargs.nfargs)
289 >                x *= tp->f->mwidth + 255.*fabs(m->oargs.farg[i]);
290 >        else
291 >                x *= 255.;
292 >        h = x;
293          i = y = DOT(v, tp->down);
294          if (x < 0.0 || y < 0.0)
295                  return(0);
296          x -= (double)h;
297 <        y = ((i+1) - y)*256.;
297 >        y = ((i+1) - y)*255.;
298                                  /* find the line position */
299          for (tlp = tp->tl.next; tlp != NULL; tlp = tlp->next)
300                  if (--i < 0)
# Line 287 | Line 302 | OBJREC  *m;
302          if (tlp == NULL || h >= tlp->width)
303                  return(0);
304          for (i = 0; (h -= tlp->spc[i]) >= 0; i++)
305 <                if (h < 256 && inglyph(h+x, y,
305 >                if (h < 255 && inglyph(h+x, y,
306                                  tp->f->fg[TLSTR(tlp)[i]&0xff]))
307                          return(1);
308          return(0);
309   }
310  
311  
312 < inglyph(x, y, gl)               /* (x,y) within font glyph gl? */
313 < double  x, y;           /* real coordinates in range [0,256) */
314 < register GLYPH  *gl;
312 > static int
313 > inglyph(                /* (x,y) within font glyph gl? */
314 >        double  x,              /* real coordinates in range [0,255) */
315 >        double  y,
316 >        GLYPH  *gl
317 > )
318   {
319          int  n, ncross;
320          int  xlb, ylb;
321          int  tv;
322 <        register GORD  *p0, *p1;
322 >        GORD  *p0, *p1;
323  
324          if (gl == NULL)
325                  return(0);
# Line 319 | Line 337 | register GLYPH  *gl;
337                                          /* positive x axis cross test */
338          while (n--) {
339                  if ((p0[1]<<1 > ylb) ^ (p1[1]<<1 > ylb)) {
340 <                        tv = p0[0]<<1 > xlb | (p1[0]<<1 > xlb) << 1;
340 >                        tv = (p0[0]<<1 > xlb) | ((p1[0]<<1 > xlb) << 1);
341                          if (tv == 03)
342                                  ncross++;
343                          else if (tv)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines