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 */ |
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) |
70 |
|
int argc; |
71 |
|
char *argv[]; |
72 |
|
{ |
60 |
– |
double atof(); |
73 |
|
int an; |
74 |
|
|
75 |
|
for (an = 1; an < argc && argv[an][0] == '-'; an++) |
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); |
131 |
|
|
132 |
|
/* create bit map */ |
133 |
|
makemap(); |
118 |
– |
/* load font file */ |
119 |
– |
loadfont(); |
134 |
|
/* convert text to bitmap */ |
135 |
|
maptext(); |
136 |
|
/* print header */ |
163 |
|
} |
164 |
|
|
165 |
|
|
152 |
– |
loadfont() /* load the font file */ |
153 |
– |
{ |
154 |
– |
FILE *fp; |
155 |
– |
char *err; |
156 |
– |
int gn, ngv, gv; |
157 |
– |
register GLYPH *g; |
158 |
– |
|
159 |
– |
if ((fp = fropen(fontfile)) == NULL) { |
160 |
– |
fprintf(stderr, "cannot find font file \"%s\"\n", |
161 |
– |
fontfile); |
162 |
– |
exit(1); |
163 |
– |
} |
164 |
– |
while (fscanf(fp, "%d", &gn) == 1) { /* get each glyph */ |
165 |
– |
if (gn < 0 || gn > 127) { |
166 |
– |
err = "illegal"; |
167 |
– |
goto fonterr; |
168 |
– |
} |
169 |
– |
if (ourfont[gn] != NULL) { |
170 |
– |
err = "duplicate"; |
171 |
– |
goto fonterr; |
172 |
– |
} |
173 |
– |
if (fscanf(fp, "%d", &ngv) != 1 || |
174 |
– |
ngv < 0 || ngv > 255) { |
175 |
– |
err = "bad # vertices for"; |
176 |
– |
goto fonterr; |
177 |
– |
} |
178 |
– |
g = (GLYPH *)malloc((2*ngv+1)*sizeof(GLYPH)); |
179 |
– |
if (g == NULL) |
180 |
– |
goto memerr; |
181 |
– |
ourfont[gn] = g; |
182 |
– |
*g++ = ngv; |
183 |
– |
ngv *= 2; |
184 |
– |
while (ngv--) { |
185 |
– |
if (fscanf(fp, "%d", &gv) != 1 || |
186 |
– |
gv < 0 || gv > 255) { |
187 |
– |
err = "bad vertex for"; |
188 |
– |
goto fonterr; |
189 |
– |
} |
190 |
– |
*g++ = gv; |
191 |
– |
} |
192 |
– |
} |
193 |
– |
fclose(fp); |
194 |
– |
return; |
195 |
– |
fonterr: |
196 |
– |
fprintf(stderr, "%s character (%d) in font file \"%s\"\n", |
197 |
– |
err, gn, fontfile); |
198 |
– |
exit(1); |
199 |
– |
memerr: |
200 |
– |
fprintf(stderr, "out of memory in loadfont\n"); |
201 |
– |
exit(1); |
202 |
– |
} |
203 |
– |
|
204 |
– |
|
166 |
|
gettext(fp) /* get text from a file */ |
167 |
|
FILE *fp; |
168 |
|
{ |
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; |
227 |
– |
if (len > maxline) |
228 |
– |
maxline = len; |
195 |
|
nlines++; |
196 |
|
} |
197 |
|
return; |
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: |
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 |
|
|