1 /* Unicode | PostScript
2 * start end | offset font name
3 * 0x0000 0x00ff 0x00 LucidaSansUnicode00
13 /* Postscript font names, e.g., `LucidaSansUnicode00'
14 * names may only be added because reference to the
15 * names is made by indexing into this table.
17 static struct pfnament *pfnafontmtab = 0;
18 static int pfnamcnt = 0;
19 int curpostfontid = -1;
21 int curtrofffontid = -1;
22 static int curfontpos = -1;
23 static int fontheight = 0;
24 static int fontslant = 0;
26 /* This is troffs mounted font table. It is an anachronism resulting
27 * from the design of the APS typesetter. fontmnt is the
28 * number of positions available. fontmnt is really 11, but
29 * should not be limited.
34 struct troffont *troffontab = 0;
39 mountfont(int pos, char *fontname) {
42 if (debug) Bprint(Bstderr, "mountfont(%d, %s)\n", pos, fontname);
43 if (pos < 0 || pos >= fontmnt)
44 error(FATAL, "cannot mount a font at position %d,\n can only mount into postions 0-%d\n",
48 fontmtab[pos] = galloc(fontmtab[pos], i+1, "mountfont():fontmtab");
49 strcpy(fontmtab[pos], fontname);
50 if (curfontpos == pos) curfontpos = -1;
55 if (curfontpos == fontpos) return;
57 if (fontmtab[fontpos] == 0)
58 error(FATAL, "Font at position %d was not initialized, botch!\n", fontpos);
60 curtrofffontid = findtfn(fontmtab[fontpos], 1);
61 if (debug) Bprint(Bstderr, "settrfont()-> curtrofffontid=%d\n", curtrofffontid);
63 if (curtrofffontid < 0) {
66 error(WARNING, "fontpos=%d\n", fontpos);
67 for (i=0; i<fontmnt; i++)
69 error(WARNING, "fontmtab[%d]=0x0\n", i);
71 error(WARNING, "fontmtab[%d]=%s\n", i, fontmtab[i]);
77 setpsfont(int psftid, int fontsize) {
78 if (psftid == curpostfontid && fontsize == curfontsize) return;
79 if (psftid >= pfnamcnt)
80 error(FATAL, "Postscript font index=%d used but not defined, there are only %d fonts\n",
85 Bprint(Bstdout, "%d /%s f\n", fontsize, pfnafontmtab[psftid].str);
86 if ( fontheight != 0 || fontslant != 0 )
87 Bprint(Bstdout, "%d %d changefont\n", fontslant, (fontheight != 0) ? fontheight : fontsize);
88 pfnafontmtab[psftid].used = 1;
89 curpostfontid = psftid;
90 curfontsize = fontsize;
94 /* find index of PostScript font name in table
95 * returns -1 if name is not in table
96 * If insflg is not zero
97 * and the name is not found in the table, insert it.
100 findpfn(char *fontname, int insflg) {
104 for (i=0; i<pfnamcnt; i++) {
105 if (strcmp(pfnafontmtab[i].str, fontname) == 0)
109 tp = galloc(pfnafontmtab, sizeof(struct pfnament)*(pfnamcnt+1), "findpfn():pfnafontmtab");
112 pfnafontmtab = (struct pfnament *)tp;
113 i = strlen(fontname);
114 pfnafontmtab[pfnamcnt].str = galloc(0, i+1, "findpfn():pfnafontmtab[].str");
115 strncpy(pfnafontmtab[pfnamcnt].str, fontname, i);
116 pfnafontmtab[pfnamcnt].str[i] = '\0';
117 pfnafontmtab[pfnamcnt].used = 0;
123 char postroffdirname[] = "#9/postscript/troff"; /* "/sys/lib/postscript/troff/"; */
124 char troffmetricdirname[] = "#9/troff/font"; /* "/sys/lib/troff/font/devutf/"; */
127 readpsfontdesc(char *fontname, int trindex) {
128 static char *filename = 0;
131 int errorflg = 0, line =1, rv;
132 int start, end, offset;
133 int startfont, endfont, startchar, endchar, pfid;
136 /* struct charent *cp[]; */
138 if (debug) Bprint(Bstderr, "readpsfontdesc(%s,%d)\n", fontname, trindex);
139 filename=galloc(filename, strlen(postroffdirname)+1+strlen(fontname)+1, "readpsfontdesc: cannot allocate memory\n");
140 sprint(filename, "%s/%s", postroffdirname, fontname);
142 bfd = Bopen(unsharp(filename), OREAD);
144 error(WARNING, "cannot open file %s\n", filename);
147 Bfd = bfd; /* &(bfd->Biobufhdr); */
151 if ((rv=Bgetfield(Bfd, 'd', &start, 0)) == 0) {
153 error(WARNING, "file %s:%d illegal start value\n", filename, line);
154 } else if (rv < 0) break;
155 if ((rv=Bgetfield(Bfd, 'd', &end, 0)) == 0) {
157 error(WARNING, "file %s:%d illegal end value\n", filename, line);
158 } else if (rv < 0) break;
159 if ((rv=Bgetfield(Bfd, 'd', &offset, 0)) < 0) {
161 error(WARNING, "file %s:%d illegal offset value\n", filename, line);
163 if ((rv=Bgetfield(Bfd, 's', psfontnam, 128)) == 0) {
165 error(WARNING, "file %s:%d illegal fontname value\n", filename, line);
166 } else if (rv < 0) break;
169 struct psfent *psfentp;
170 startfont = RUNEGETGROUP(start);
171 startchar = RUNEGETCHAR(start);
172 endfont = RUNEGETGROUP(end);
173 endchar = RUNEGETCHAR(end);
174 pfid = findpfn(psfontnam, 1);
175 if (startfont != endfont) {
176 error(WARNING, "font descriptions must not cross 256 glyph block boundary\n");
180 tp = &(troffontab[trindex]);
181 tp->psfmap = galloc(tp->psfmap, ++(tp->psfmapsize)*sizeof(struct psfent), "readpsfontdesc():psfmap");
182 psfentp = &(tp->psfmap[tp->psfmapsize-1]);
183 psfentp->start = start;
185 psfentp->offset = offset;
186 psfentp->psftid = pfid;
188 Bprint(Bstderr, "\tpsfmap->start=0x%x\n", start);
189 Bprint(Bstderr, "\tpsfmap->end=0x%x\n", end);
190 Bprint(Bstderr, "\tpsfmap->offset=0x%x\n", offset);
191 Bprint(Bstderr, "\tpsfmap->pfid=0x%x\n", pfid);
194 for (i=startchar; i<=endchar; i++) {
195 tp->charent[startfont][i].postfontid = pfid;
196 tp->charent[startfont][i].postcharid = i + offset - startchar;
200 Bprint(Bstderr, "%x %x ", start, end);
201 if (offset) Bprint(Bstderr, "%x ", offset);
202 Bprint(Bstderr, "%s\n", psfontnam);
206 } while(errorflg != 1);
212 readtroffmetric(char *fontname, int trindex) {
213 static char *filename = 0;
216 int errorflg = 0, line =1, rv;
218 char stoken[128], *str;
220 Rune troffchar, quote;
221 int width, flag, charnum, thisfont, thischar;
224 if (debug) Bprint(Bstderr, "readtroffmetric(%s,%d)\n", fontname, trindex);
225 filename=galloc(filename, strlen(troffmetricdirname)+4+strlen(devname)+1+strlen(fontname)+1, "readtroffmetric():filename");
226 sprint(filename, "%s/dev%s/%s", troffmetricdirname, devname, fontname);
228 bfd = Bopen(unsharp(filename), OREAD);
230 error(WARNING, "cannot open file %s\n", filename);
233 Bfd = bfd; /* &(bfd->Biobufhdr); */
235 /* deal with the few lines at the beginning of the
236 * troff font metric files.
238 if ((rv=Bgetfield(Bfd, 's', stoken, 128)) == 0) {
240 error(WARNING, "file %s:%d illegal token\n", filename, line);
241 } else if (rv < 0) break;
243 Bprint(Bstderr, "%s\n", stoken);
246 if (strcmp(stoken, "name") == 0) {
247 if ((rv=Bgetfield(Bfd, 's', stoken, 128)) == 0) {
249 error(WARNING, "file %s:%d illegal token\n", filename, line);
250 } else if (rv < 0) break;
251 } else if (strcmp(stoken, "named") == 0) {
253 } else if (strcmp(stoken, "fontname") == 0) {
254 if ((rv=Bgetfield(Bfd, 's', stoken, 128)) == 0) {
256 error(WARNING, "file %s:%d illegal token\n", filename, line);
257 } else if (rv < 0) break;
258 } else if (strcmp(stoken, "spacewidth") == 0) {
259 if ((rv=Bgetfield(Bfd, 'd', &ntoken, 0)) == 0) {
261 error(WARNING, "file %s:%d illegal token\n", filename, line);
262 } else if (rv < 0) break;
263 troffontab[trindex].spacewidth = ntoken;
264 thisfont = RUNEGETGROUP(' ');
265 thischar = RUNEGETCHAR(' ');
266 for (cp = &(troffontab[trindex].charent[thisfont][thischar]); *cp != 0; cp = &((*cp)->next))
268 if (strcmp((*cp)->name, " ") == 0)
271 if (*cp == 0) *cp = galloc(0, sizeof(struct charent), "readtroffmetric:charent");
272 (*cp)->postfontid = thisfont;
273 (*cp)->postcharid = thischar;
274 (*cp)->troffcharwidth = ntoken;
275 (*cp)->name = galloc(0, 2, "readtroffmetric: char name");
277 strcpy((*cp)->name, " ");
278 } else if (strcmp(stoken, "special") == 0) {
279 troffontab[trindex].special = TRUE;
280 } else if (strcmp(stoken, "charset") == 0) {
287 } while(!errorflg && rv>=0);
288 while(!errorflg && rv>=0) {
289 if ((rv=Bgetfield(Bfd, 's', stoken, 128)) == 0) {
291 error(WARNING, "file %s:%d illegal rune token <0x%x> rv=%d\n", filename, line, troffchar, rv);
292 } else if (rv < 0) break;
293 if (utflen(stoken) > 1) specharflag = TRUE;
294 else specharflag = FALSE;
295 /* if this character is a quote we have to use the previous characters info */
296 if ((rv=Bgetfield(Bfd, 'r', "e, 0)) == 0) {
298 error(WARNING, "file %s:%d illegal width or quote token <0x%x> rv=%d\n", filename, line, quote, rv);
299 } else if (rv < 0) break;
301 /* need some code here */
308 if ((rv=Bgetfield(Bfd, 'd', &width, 0)) == 0) {
310 error(WARNING, "file %s:%d illegal width token <0x%x> rv=%d\n", filename, line, troffchar, rv);
311 } else if (rv < 0) break;
312 if ((rv=Bgetfield(Bfd, 'd', &flag, 0)) == 0) {
314 error(WARNING, "file %s:%d illegal flag token <0x%x> rv=%d\n", filename, line, troffchar, rv);
315 } else if (rv < 0) break;
316 if ((rv=Bgetfield(Bfd, 'd', &charnum, 0)) == 0) {
318 error(WARNING, "file %s:%d illegal character number token <0x%x> rv=%d\n", filename, line, troffchar, rv);
319 } else if (rv < 0) break;
321 str = Brdline(Bfd, '\n');
322 /* stash the crap from the end of the line for debugging */
325 Bprint(Bstderr, "premature EOF\n");
328 str[Blinelen(Bfd)-1] = '\0';
331 chartorune(&troffchar, stoken);
334 Bprint(Bstderr, "%s %d %d 0x%x %s # special\n",stoken, width, flag, charnum, str);
336 if (strcmp(stoken, "---") == 0) {
337 thisfont = RUNEGETGROUP(charnum);
338 thischar = RUNEGETCHAR(charnum);
341 thisfont = RUNEGETGROUP(troffchar);
342 thischar = RUNEGETCHAR(troffchar);
344 for (cp = &(troffontab[trindex].charent[thisfont][thischar]); *cp != 0; cp = &((*cp)->next))
346 if (debug) Bprint(Bstderr, "installing <%s>, found <%s>\n", stoken, (*cp)->name);
347 if (strcmp((*cp)->name, stoken) == 0)
350 if (*cp == 0) *cp = galloc(0, sizeof(struct charent), "readtroffmetric:charent");
351 (*cp)->postfontid = RUNEGETGROUP(charnum);
352 (*cp)->postcharid = RUNEGETCHAR(charnum);
353 (*cp)->troffcharwidth = width;
354 (*cp)->name = galloc(0, strlen(stoken)+1, "readtroffmetric: char name");
356 strcpy((*cp)->name, stoken);
359 Bprint(Bstderr, "%s", stoken);
361 Bputrune(Bstderr, troffchar);
362 Bprint(Bstderr, " %d %d 0x%x %s # psfontid=0x%x pscharid=0x%x thisfont=0x%x thischar=0x%x\n",
363 width, flag, charnum, str,
374 /* find index of troff font name in table
375 * returns -1 if name is not in table
376 * returns -2 if it cannot allocate memory
377 * returns -3 if there is a font mapping problem
378 * If insflg is not zero
379 * and the name is not found in the table, insert it.
382 findtfn(char *fontname, BOOLEAN insflg) {
387 if (fontname==0) fprint(2, "findtfn(0x%x,%d)\n", fontname, insflg);
388 else fprint(2, "findtfn(%s,%d)\n", fontname, insflg);
390 for (i=0; i<troffontcnt; i++) {
391 if (troffontab[i].trfontid==0) {
392 error(WARNING, "findtfn:troffontab[%d].trfontid=0x%x, botch!\n",
393 i, troffontab[i].trfontid);
396 if (strcmp(troffontab[i].trfontid, fontname) == 0)
400 tp = (struct troffont *)galloc(troffontab, sizeof(struct troffont)*(troffontcnt+1), "findtfn: struct troffont:");
404 tp = &(troffontab[troffontcnt]);
405 i = strlen(fontname);
406 tp->trfontid = galloc(0, i+1, "findtfn: trfontid:");
408 /* initialize new troff font entry with name and numeric fields to 0 */
409 strncpy(tp->trfontid, fontname, i);
410 tp->trfontid[i] = '\0';
415 for (i=0; i<NUMOFONTS; i++)
416 for (j=0; j<FONTSIZE; j++)
417 tp->charent[i][j] = 0;
419 if (!readtroffmetric(fontname, troffontcnt-1))
421 if (!readpsfontdesc(fontname, troffontcnt-1))
423 return(troffontcnt-1);
432 Bprint(Bstdout, "%s", TRAILER);
433 Bprint(Bstdout, "done\n");
434 Bprint(Bstdout, "%s", DOCUMENTFONTS);
436 for (i=0; i<pfnamcnt; i++)
437 if (pfnafontmtab[i].used)
438 Bprint(Bstdout, " %s", pfnafontmtab[i].str);
439 Bprint(Bstdout, "\n");
441 Bprint(Bstdout, "%s %d\n", PAGES, pages_printed);
445 /* Set slant to n degrees. Disable slanting if n is 0. */
452 /* Set character height to n points. Disabled if n is 0 or the current size. */
456 fontheight = (n == fontsize) ? 0 : n;