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 1.7 by greg, Mon Aug 5 09:32:12 1991 UTC vs.
Revision 1.8 by greg, Tue Aug 6 09:04:41 1991 UTC

# Line 65 | Line 65 | typedef struct font {
65          struct font  *next;             /* next font in list */
66   }  FONT;
67  
68 + typedef struct tline {
69 +        struct tline  *next;            /* pointer to next line */
70 +                                        /* followed by the string */
71 + }  TLINE;
72 +
73 + #define  TLSTR(l)       ((char *)(l+1))
74 +
75   typedef struct {
69        char  **t;                      /* text array */
76          FVECT  right, down;             /* right and down unit vectors */
77          FONT  *f;                       /* our font */
78 +        TLINE  tl;                      /* line list */
79   }  TEXT;
80  
81   extern char  *fgetword();
82  
83   TEXT  *gettext();
84  
85 + TLINE  *tlalloc();
86 +
87   FONT  *getfont();
88  
89   static FONT  *fontlist = NULL;          /* our font list */
# Line 124 | Line 133 | RAY  *r;
133   }
134  
135  
136 + TLINE *
137 + tlalloc(s)                      /* allocate and assign text line */
138 + char  *s;
139 + {
140 +        extern char  *strcpy();
141 +        register TLINE  *tl;
142 +
143 +        tl = (TLINE *)malloc(sizeof(TLINE)+1+strlen(s));
144 +        if (tl == NULL)
145 +                error(SYSTEM, "out of memory in tlalloc");
146 +        tl->next = NULL;
147 +        strcpy(TLSTR(tl), s);
148 +        return(tl);
149 + }
150 +
151 +
152   TEXT *
153   gettext(tm)                     /* get text structure for material */
154   register OBJREC  *tm;
# Line 135 | Line 160 | register OBJREC  *tm;
160          double  d;
161          FILE  *fp;
162          char  linbuf[512];
163 <        register TEXT  *t;
163 >        TEXT  *t;
164          register int  i;
165 +        register TLINE  *tlp;
166          register char  *s;
167  
168          if ((t = (TEXT *)tm->os) != NULL)
# Line 147 | Line 173 | register OBJREC  *tm;
173                                          tm->otype == PAT_CTEXT ? 15 : 9))
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);
# Line 159 | Line 185 | register OBJREC  *tm;
185          for (i = 0; i < 3; i++)
186                  t->down[i] *= d;
187                                                  /* get text */
188 <        t->t = (char **)malloc(2*sizeof(char **));
163 <        if (t->t == NULL)
164 <                goto memerr;
188 >        tlp = &t->tl;
189          if (tm->oargs.nsargs - tndx(tm) > 1) {  /* single line */
190                  s = linbuf;
191                  for (i = tndx(tm)+1; i < tm->oargs.nsargs; i++) {
# Line 170 | Line 194 | register OBJREC  *tm;
194                          *s++ = ' ';
195                  }
196                  *--s = '\0';
197 <                t->t[0] = savqstr(linbuf);
198 <                t->t[1] = NULL;
197 >                tlp->next = tlalloc(linbuf);
198 >                tlp = tlp->next;
199          } else {                                /* text file */
200                  if ((s = getpath(tm->oargs.sarg[tndx(tm)],
201                                  libpath, R_OK)) == NULL) {
# Line 184 | Line 208 | register OBJREC  *tm;
208                                          s);
209                          error(SYSTEM, errmsg);
210                  }
211 <                for (i=0; fgets(linbuf,sizeof(linbuf),fp)!=NULL; i++) {
211 >                while (fgets(linbuf, sizeof(linbuf), fp) != NULL) {
212                          s = linbuf + strlen(linbuf) - 1;
213                          if (*s == '\n')
214                                  *s = '\0';
215 <                        t->t=(char **)realloc((char *)t->t,
216 <                                        (i+2)*sizeof(char **));
193 <                        if (t->t == NULL)
194 <                                goto memerr;
195 <                        t->t[i] = savqstr(linbuf);
215 >                        tlp->next = tlalloc(linbuf);
216 >                        tlp = tlp->next;
217                  }
197                t->t[i] = NULL;
218                  fclose(fp);
219          }
220 +        tlp->next = NULL;
221                                                  /* get the font */
222          t->f = getfont(tm->oargs.sarg[fndx(tm)]);
223                                                  /* we're done */
224          tm->os = (char *)t;
225          return(t);
205 memerr:
206        error(SYSTEM, "out of memory in gettext");
226   #undef  R
227   #undef  D
228   }
# Line 213 | Line 232 | freetext(m)                    /* free text structures associated with
232   OBJREC  *m;
233   {
234          register TEXT  *tp;
235 <        register int  i;
235 >        register TLINE  *tlp;
236  
237          tp = (TEXT *)m->os;
238          if (tp == NULL)
239                  return;
240 <        for (i = 0; tp->t[i] != NULL; i++)
241 <                freeqstr(tp->t[i]);
223 <        free((char *)tp->t);
240 >        for (tlp = tp->tl.next; tlp != NULL; tlp = tlp->next);
241 >                free(TLSTR(tlp));
242          free((char *)tp);
243          m->os = NULL;
244   }
# Line 228 | Line 246 | OBJREC  *m;
246  
247   intext(p, m)                    /* check to see if p is in text glyph */
248   FVECT  p;
249 < register OBJREC  *m;
249 > OBJREC  *m;
250   {
251          register TEXT  *tp;
252 <        register int  i;
252 >        register TLINE  *tlp;
253          double  v[3], y, x;
254 <        int  col, lno;
254 >        int  col;
255 >        register int  lno;
256                                  /* first, compute position in text */
257          v[0] = p[0] - m->oargs.farg[0];
258          v[1] = p[1] - m->oargs.farg[1];
# Line 246 | Line 265 | register OBJREC  *m;
265          y = (lno+1) - y;
266                                  /* get the font character */
267          tp = gettext(m);
268 <        for (i = 0; i < lno; i++)
269 <                if (tp->t[i] == NULL)
270 <                        return(0);
271 <        if (col >= strlen(tp->t[i]))
268 >        for (tlp = tp->tl.next; tlp != NULL; tlp = tlp->next)
269 >                if (--lno < 0)
270 >                        break;
271 >        if (tlp == NULL || col >= strlen(TLSTR(tlp)))
272                  return(0);
273 <        return(inglyph(x, y, tp->f->fg[tp->t[i][col]]));
273 >        return(inglyph(x, y, tp->f->fg[TLSTR(tlp)[col]]));
274   }
275  
276  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines