|
|
1.1 root 1: /* Copyright (c) 1988 AT&T
2: All Rights Reserved
3: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
4: The copyright notice above does not evidence any
5: actual or intended publication of such source code.
6:
7: Author: Chi Chung Choy
8: Revised: Michael Siemon
9: Revised: Donald Knudsen
10: */
11:
12: /* @(#)picasso:fonts.c 1.0 */
13:
14: #include "font.h"
15: #include "picasso.h"
16:
17: extern char *fontdir;
18:
19: extern FILE *fopen();
20: extern int fread(), fclose();
21:
22: int devres = 720;
23: int unitwidth = 10;
24: int nfonts = 0;
25: char **lfonts = NULL;
26:
27: TrFont *curfont; /* not used in batch picasso */
28:
29: int fontcount = 0;
30:
31: static char devfontpath[1024];
32:
33: #define NAMEMIN 6
34: char *troffname[] = {
35: "R", "Times-Roman",
36: "I", "Times-Italic",
37: "B", "Times-Bold",
38: "BI", "Times-BoldItalic",
39: "H", "Helvetica",
40: "HI", "Helvetica-Oblique",
41: "HB", "Helvetica-Bold",
42: "HX", "Helvetica-BoldOblique",
43: "CW", "Courier",
44: "CI", "Courier-Oblique",
45: "CB", "Courier-Bold",
46: "CX", "Courier-BoldOblique",
47: "PA", "Palatino-Roman",
48: "PI", "Palatino-Italic",
49: "PB", "Palatino-Bold",
50: "PX", "Palatino-BoldItalic",
51: "Hr", "Helvetica-Narrow",
52: "Hi", "Helvetica-Narrow-Oblique",
53: "Hb", "Helvetica-Narrow-Bold",
54: "Hx", "Helvetica-Narrow-BoldOblique",
55: "KR", "Bookman-Light",
56: "KI", "Bookman-LightItalic",
57: "KB", "Bookman-Demi",
58: "KX", "Bookman-DemiItalic",
59: "AR", "AvantGarde-Book",
60: "AI", "AvantGarde-BookOblique",
61: "AB", "AvantGarde-Demi",
62: "AX", "AvantGarde-DemiOblique",
63: "NR", "NewCenturySchlbk-Roman",
64: "NI", "NewCenturySchlbk-Italic",
65: "NB", "NewCenturySchlbk-Bold",
66: "NX", "NewCenturySchlbk-BoldItalic",
67: "ZD", "ZapfDingbats",
68: "ZI", "ZapfChancery-MediumItalic",
69: "GR", "Symbol",
70: (char *)0, (char *)0
71: };
72:
73: #define NDEFWID 96
74: static int defaultwidthtab[NDEFWID] = {
75: 25, 33, 41, 50, 50, 83,
76: 78, 33, 33, 33, 50, 56,
77: 25, 33, 25, 28, 50, 50,
78: 50, 50, 50, 50, 50, 50,
79: 50, 50, 28, 28, 56, 56,
80: 56, 44, 92, 72, 67, 67,
81: 72, 61, 56, 72, 72, 33,
82: 39, 72, 61, 89, 72, 72,
83: 56, 72, 67, 56, 61, 72,
84: 72, 94, 72, 72, 61, 33,
85: 28, 33, 47, 50, 33, 44,
86: 50, 44, 50, 44, 33, 50,
87: 50, 28, 28, 50, 28, 78,
88: 50, 50, 50, 50, 33, 39,
89: 28, 50, 50, 72, 50, 50,
90: 44, 48, 20, 48, 54, 0
91: };
92:
93: static void /* initialize with Times-Roman */
94: initdefaultfont()
95: {
96: int i;
97: extern int fcount, mcount; /* fake with these */
98:
99: fontinit(tostring(troffname[0]));
100: if (fontcount == 0) { /* normal initialization failed */
101: mount[0]->name = tostring(troffname[0]);
102: mount[0]->fontname = tostring(troffname[1]);
103: mount[0]->nchars = NDEFWID;
104: mount[0]->state = INMEMORY;
105: mount[0]->mounted++;
106: mount[0]->wp = (Chwid *)malloc(NDEFWID*sizeof(Chwid));
107: for (i = 0; i < NDEFWID; i++) {
108: mount[0]->wp[i].wid = defaultwidthtab[i];
109: mount[0]->wp[i].num = i + 32;
110: }
111: fontcount = 1;
112: fcount = mcount = 1;
113: }
114: }
115:
116: int
117: devinit(devname) /* -1 means error; 1 means success */
118: char *devname;
119: {
120: char filename[1024];
121: int n;
122:
123: strcpy(filename, fontdir);
124: strcat(filename, "/dev");
125: strcat(filename, devname);
126: strcpy(devfontpath, filename);
127: strcat(filename, "/DESC"); /* "{FONTDIR}/dev{devname}/DESC" */
128: if (getdesc(filename) == -1) {
129: unitwidth = 10;
130: devres = 720;
131: initdefaultfont();
132: return -1;
133: }
134: initdefaultfont();
135: for (n = 1; n < nfonts; n++)
136: fontinit(lfonts[n]);
137: return(1);
138: }
139:
140: double
141: checkfont(f)
142: double f;
143: {
144: if (f < 0 || f > fontcount-1) {
145: if (f != (int)f) {
146: yyerror("%g is not a valid font index", f);
147: }
148: return 0.;
149: }
150: return f;
151: }
152:
153: double
154: setfont(fontname) /* accepts either troff or (some) PostScript */
155: char *fontname; /* fontname, and initializes (mounts) it. */
156: {
157: int i;
158:
159: if (fontname == NULL || *fontname == '\0')
160: return 0.;
161: if (strlen(fontname) >= NAMEMIN)
162: for (i = 1; troffname[i] != (char *)0; i += 2)
163: if (strcmp(fontname, troffname[i]) == 0) {
164: free(fontname);
165: fontname = tostring(troffname[i-1]);
166: break;
167: }
168: for (i = 0; i < fontcount; i++) /* linear search */
169: if (strcmp(mount[i]->name, fontname) == 0)
170: break;
171: if (i == fontcount)
172: if ((i = fontinit(fontname)) == -1) {
173: yyerror("font %s not found", fontname);
174: i = (int)getfval("textfont");
175: }
176: free(fontname);
177: return (double)i;
178: }
179:
180: static int
181: fontinit(fontname) /* 0 if there is error and default font will be used;
182: 1+ is the fontinfo index used */
183: char *fontname;
184: {
185: char filename[1024];
186:
187: if (fontcount == MAXFONTS) /* reuse the last fontinfo slot */
188: fontcount--; /* if all the slots are used. */
189: /* (may want a yyerror msg here)*/
190: strcpy(filename, devfontpath);
191: strcat(filename, "/");
192: strcat(filename, fontname); /* "{devfontpath}/{fontname}" */
193: if (mountfont(filename, fontcount) == -1)
194: return 0;
195: fontcount++;
196: return(fontcount-1);
197: }
198:
199: double
200: getstringwidth(s, fontnum, ptsize) /* assumes no font or size changes */
201: char *s;
202: int fontnum, ptsize;
203: {
204: double width = 0.0;
205: int pos;
206:
207: fontnum = abs(fontnum); /* negatives imply font or size attrs */
208: ptsize = abs(ptsize); /* positives imply troff-style escapes*/
209: curfont = mount[fontnum];
210: for(; *s; ++s)
211: if (*s > 31 && (pos = onfont(*s, fontnum)) != -1)
212: width += chwidth(pos, fontnum);
213: return width * ptsize / (unitwidth * devres);
214: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.