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

Comparing ray/src/common/font.c (file contents):
Revision 2.1 by greg, Sat Jun 6 07:38:40 1992 UTC vs.
Revision 2.3 by greg, Wed Jun 24 17:52:58 1992 UTC

# Line 27 | Line 27 | char  *fname;
27          char  buf[16];
28          FILE  *fp;
29          char  *pathname, *err;
30 +        unsigned  wsum, hsum, ngly;
31          int  gn, ngv;
32          register int  gv;
33          register GLYPH  *g;
# Line 50 | Line 51 | char  *fname;
51                                  pathname);
52                  error(SYSTEM, errmsg);
53          }
54 +        wsum = hsum = ngly = 0;
55          while (fgetword(buf,sizeof(buf),fp) != NULL) {  /* get each glyph */
56                  if (!isint(buf))
57                          goto nonint;
58                  gn = atoi(buf);
59 <                if (gn < 0 || gn > 255) {
59 >                if (gn < 1 || gn > 255) {
60                          err = "illegal";
61                          goto fonterr;
62                  }
# Line 71 | Line 73 | char  *fname;
73                  if (g == NULL)
74                          goto memerr;
75                  g->nverts = ngv;
76 <                g->start = g->width = 128;
76 >                g->left = g->right = g->top = g->bottom = 128;
77                  ngv *= 2;
78                  gp = gvlist(g);
79                  while (ngv--) {
# Line 82 | Line 84 | char  *fname;
84                                  goto fonterr;
85                          }
86                          *gp++ = gv;
87 <                        if (ngv & 1)            /* follow x limits */
88 <                                if (gv < g->start)
89 <                                        g->start = gv;
90 <                                else if (gv > g->width)
91 <                                        g->width = gv;
87 >                        if (ngv & 1) {          /* follow x limits */
88 >                                if (gv < g->left)
89 >                                        g->left = gv;
90 >                                else if (gv > g->right)
91 >                                        g->right = gv;
92 >                        } else {                /* follow y limits */
93 >                                if (gv < g->bottom)
94 >                                        g->bottom = gv;
95 >                                else if (gv > g->top)
96 >                                        g->top = gv;
97 >                        }
98                  }
99 <                g->width -= g->start;
99 >                if (g->right - g->left && g->top - g->bottom) {
100 >                        ngly++;
101 >                        wsum += g->right - g->left;
102 >                        hsum += g->top - g->bottom;
103 >                }
104                  f->fg[gn] = g;
105          }
106          fclose(fp);
107 +        if (ngly) {
108 +                f->mwidth = wsum / ngly;
109 +                f->mheight = hsum / ngly;
110 +        }
111          f->next = fontlist;
112          return(fontlist = f);
113   nonint:
# Line 103 | Line 119 | fonterr:
119          error(USER, errmsg);
120   memerr:
121          error(SYSTEM, "out of memory in fontglyph");
122 + }
123 +
124 +
125 + int
126 + uniftext(sp, tp, f)                     /* uniformly space text line */
127 + register short  *sp;            /* returned character spacing */
128 + register char  *tp;             /* text line */
129 + register FONT  *f;              /* font */
130 + {
131 +        int  linelen;
132 +
133 +        linelen = *sp++ = 0;
134 +        while (*tp)
135 +                if (f->fg[*tp++&0xff] == NULL)
136 +                        *sp++ = 0;
137 +                else
138 +                        linelen += *sp++ = 256;
139 +        return(linelen);
140 + }
141 +
142 +
143 + int
144 + squeeztext(sp, tp, f, cis)              /* squeeze text line */
145 + short  *sp;                     /* returned character spacing */
146 + char  *tp;                      /* text line */
147 + FONT  *f;                       /* font */
148 + int  cis;                       /* intercharacter spacing */
149 + {
150 +        int  linelen;
151 +        register GLYPH  *gp;
152 +
153 +        gp = NULL;
154 +        while (*tp && (gp = f->fg[*tp++&0xff]) == NULL)
155 +                *sp++ = 0;
156 +        cis /= 2;
157 +        linelen = *sp = cis;
158 +        while (gp != NULL) {
159 +                if (gp->nverts) {               /* regular character */
160 +                        linelen += *sp++ += cis - gp->left;
161 +                        *sp = gp->right + cis;
162 +                } else {                        /* space */
163 +                        linelen += *sp++;
164 +                        *sp = f->mwidth;
165 +                }
166 +                gp = NULL;
167 +                while (*tp && (gp = f->fg[*tp++&0xff]) == NULL) {
168 +                        linelen += *sp++;
169 +                        *sp = 0;
170 +                }
171 +        }
172 +        linelen += *sp += cis;
173 +        return(linelen);
174 + }
175 +
176 +
177 + int
178 + proptext(sp, tp, f, cis, nsi)           /* space line proportionally */
179 + short  *sp;                     /* returned character spacing */
180 + char  *tp;                      /* text line */
181 + FONT  *f;                       /* font */
182 + int  cis;                       /* target intercharacter spacing */
183 + int  nsi;                       /* minimum number of spaces for indent */
184 + {
185 +        register char  *end, *tab;
186 +        GLYPH  *gp;
187 +        short  *nsp;
188 +        int  alen, len, width;
189 +                                        /* start by squeezing it */
190 +        squeeztext(sp, tp, f, cis);
191 +                                        /* now, realign spacing */
192 +        len = 0;
193 +        width = alen = *sp++;
194 +        while (*tp) {
195 +                nsp = sp;
196 +                for (end = tp; *end; end = tab) {
197 +                        tab = end + 1;
198 +                        alen += *nsp++;
199 +                        if (f->fg[*end&0xff]) {
200 +                                while ((gp = f->fg[*tab&0xff]) != NULL &&
201 +                                                gp->nverts == 0) { /* tab in */
202 +                                        alen += *nsp++;
203 +                                        tab++;
204 +                                }
205 +                                len += tab - end;
206 +                        }
207 +                        if (tab - end > nsi)
208 +                                break;
209 +                }
210 +                len *= f->mwidth + cis;         /* compute target length */
211 +                width += len;
212 +                len -= alen;                    /* necessary adjustment */
213 +                while (sp < nsp) {
214 +                        alen = len/(nsp-sp);
215 +                        *sp++ += alen;
216 +                        len -= alen;
217 +                }
218 +                len = 0;
219 +                alen = 0;
220 +                tp = tab;
221 +        }
222 +        return(width);
223   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines