Debian Codegraph @

texk/dvipsk/afm2tfm.c

raw
1 /* $Id: afm2tfm.c 77300 2026-01-08 14:56:02Z karl $ */
2
3 /* Public domain, originally written by Tom Rokicki.
4 * This program converts AFM files to TeX TFM files, and optionally
5 * to TeX VPL files that retain all kerning and ligature information.
6 * Both files make the characters not normally encoded by TeX available
7 * by character codes greater than 127.
8 */
9
10 /* (Modified by Don Knuth from Tom Rokicki's pre-VPL version.) */
11 /* VM/CMS port by J. Hafner ([email protected]), based on
12 * the port by Alessio Guglielmi ([email protected])
13 * and Marco Prevedelli ([email protected]).
14 * This port is still in test state. No guarantees.
15 * 11/3/92: more corrections to VM/CMS port. Now it looks correct
16 * and will be supported by J. Hafner.
17 *
18 */
19 /*
20 * More changes, primarily from Karl Berry, enough for a new version
21 * number to 8.0; 1 December 1996. Note that this version computes
22 * checksums differently (more intelligently).
23 */
24
25 #ifdef KPATHSEA
26 #include "config.h"
27 #include <kpathsea/c-ctype.h>
28 #include <kpathsea/progname.h>
29 #include <kpathsea/version.h>
30 #include <math.h>
31 #else /* ! KPATHSEA */
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <ctype.h>
35 #if defined(SYSV) || defined(VMS) || defined(__THINK__) || defined(MSDOS) || defined(OS2) || defined(ATARIST) || defined(WIN32)
36 #include <string.h>
37 #else
38 #include <strings.h>
39 #endif
40 #include <math.h>
41 #ifdef ATARIST
42 #include <float.h>
43 #endif
44 #endif /* KPATHSEA */
45
46 /* JLH: added these to make the code easier to read and remove some
47 ascii<->ebcdic dependencies */
48 #define ASCII_A 65
49 #define ASCII_Z 90
50 #define ASCII_a 97
51 #define ASCII_z 122
52 #define ASCII_0 48
53 #define ASCII_9 57
54
55 #ifdef VMCMS
56 #define interesting lookstr /* for 8 character truncation conflicts */
57 #include "dvipscms.h"
58 extern FILE *cmsfopen();
59 extern char ebcdic2ascii[];
60 extern char ascii2ebcdic[];
61 #ifdef fopen
62 #undef fopen
63 #endif
64 #define fopen cmsfopen
65 #endif /* VMCMS */
66
67 #include "dvips.h"
68 /* debug.h redefines fopen to my_real_fopen, but it's still a FILE * */
69 #ifdef fopen
70 #undef fopen
71 #endif
72
73 struct encoding {
74 const char *name;
75 const char *vec[256];
76 };
77 struct encoding staticencoding = {
78 "TeX text",
79 {"Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi", "Sigma",
80 "Upsilon", "Phi", "Psi", "Omega", "arrowup", "arrowdown", "quotesingle",
81 "exclamdown", "questiondown", "dotlessi", "dotlessj", "grave", "acute",
82 "caron", "breve", "macron", "ring", "cedilla", "germandbls", "ae", "oe",
83 "oslash", "AE", "OE", "Oslash", "space", "exclam", "quotedbl", "numbersign",
84 "dollar", "percent", "ampersand", "quoteright", "parenleft", "parenright",
85 "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero", "one",
86 "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon",
87 "semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C",
88 "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
89 "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash",
90 "bracketright", "circumflex", "underscore", "quoteleft", "a", "b", "c", "d",
91 "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
92 "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright",
93 "tilde", "dieresis", "", "", "", "", "", "", "", "", "", "", "", "", "",
94 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
95 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
96 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
97 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
98 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
99 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
100 "", "", "", "", "", "", "" } };
101 /*
102 * It's easier to put this in static storage and parse it as we go
103 * than to build the structures ourselves.
104 */
105 const char *staticligkern[] = {
106 "% LIGKERN space l =: lslash ; space L =: Lslash ;",
107 "% LIGKERN question quoteleft =: questiondown ;",
108 "% LIGKERN exclam quoteleft =: exclamdown ;",
109 "% LIGKERN hyphen hyphen =: endash ; endash hyphen =: emdash ;",
110 "% LIGKERN quoteleft quoteleft =: quotedblleft ;",
111 "% LIGKERN quoteright quoteright =: quotedblright ;",
112 "% LIGKERN space {} * ; * {} space ; zero {} * ; * {} zero ;",
113 "% LIGKERN one {} * ; * {} one ; two {} * ; * {} two ;",
114 "% LIGKERN three {} * ; * {} three ; four {} * ; * {} four ;",
115 "% LIGKERN five {} * ; * {} five ; six {} * ; * {} six ;",
116 "% LIGKERN seven {} * ; * {} seven ; eight {} * ; * {} eight ;",
117 "% LIGKERN nine {} * ; * {} nine ;",
118 /* Kern accented characters the same way as their base. */
119 "% LIGKERN Aacute <> A ; aacute <> a ;",
120 "% LIGKERN Acircumflex <> A ; acircumflex <> a ;",
121 "% LIGKERN Adieresis <> A ; adieresis <> a ;",
122 "% LIGKERN Agrave <> A ; agrave <> a ;",
123 "% LIGKERN Aring <> A ; aring <> a ;",
124 "% LIGKERN Atilde <> A ; atilde <> a ;",
125 "% LIGKERN Ccedilla <> C ; ccedilla <> c ;",
126 "% LIGKERN Eacute <> E ; eacute <> e ;",
127 "% LIGKERN Ecircumflex <> E ; ecircumflex <> e ;",
128 "% LIGKERN Edieresis <> E ; edieresis <> e ;",
129 "% LIGKERN Egrave <> E ; egrave <> e ;",
130 "% LIGKERN Iacute <> I ; iacute <> i ;",
131 "% LIGKERN Icircumflex <> I ; icircumflex <> i ;",
132 "% LIGKERN Idieresis <> I ; idieresis <> i ;",
133 "% LIGKERN Igrave <> I ; igrave <> i ;",
134 "% LIGKERN Ntilde <> N ; ntilde <> n ;",
135 "% LIGKERN Oacute <> O ; oacute <> o ;",
136 "% LIGKERN Ocircumflex <> O ; ocircumflex <> o ;",
137 "% LIGKERN Odieresis <> O ; odieresis <> o ;",
138 "% LIGKERN Ograve <> O ; ograve <> o ;",
139 "% LIGKERN Oslash <> O ; oslash <> o ;",
140 "% LIGKERN Otilde <> O ; otilde <> o ;",
141 "% LIGKERN Scaron <> S ; scaron <> s ;",
142 "% LIGKERN Uacute <> U ; uacute <> u ;",
143 "% LIGKERN Ucircumflex <> U ; ucircumflex <> u ;",
144 "% LIGKERN Udieresis <> U ; udieresis <> u ;",
145 "% LIGKERN Ugrave <> U ; ugrave <> u ;",
146 "% LIGKERN Yacute <> Y ; yacute <> y ;",
147 "% LIGKERN Ydieresis <> Y ; ydieresis <> y ;",
148 "% LIGKERN Zcaron <> Z ; zcaron <> z ;",
149 /*
150 * These next are only included for deficient afm files that
151 * have the lig characters but not the lig commands.
152 */
153 "% LIGKERN f i =: fi ; f l =: fl ; f f =: ff ; ff i =: ffi ;",
154 "% LIGKERN ff l =: ffl ;",
155 0 };
156 /*
157 * The above layout corresponds to TeX Typewriter Type and is compatible
158 * with TeX Text because the position of ligatures is immaterial.
159 */
160 struct encoding *outencoding = 0;
161 struct encoding *inencoding = 0;
162 char *outenname = NULL,
163 *inenname = NULL;/* the file names for input and output encodings */
164 int boundarychar = -1; /* the boundary character */
165 int ignoreligkern; /* do we look at ligkern info in the encoding? */
166 /*
167 * This is what we store Adobe data in.
168 */
169 struct adobeinfo {
170 struct adobeinfo *next;
171 int adobenum, texnum, width;
172 const char *adobename;
173 int llx, lly, urx, ury;
174 struct lig *ligs;
175 struct kern *kerns;
176 struct adobeptr *kern_equivs;
177 struct pcc *pccs;
178 int wptr, hptr, dptr, iptr;
179 } *adobechars, *adobeptrs[256], *texptrs[256],
180 *uppercase[256], *lowercase[256];
181 int nexttex[256]; /* for characters encoded multiple times in output */
182 /*
183 * These are the eight ligature ops, in VPL terms and in METAFONT terms.
184 */
185 const char *vplligops[] = {
186 "LIG", "/LIG", "/LIG>", "LIG/", "LIG/>", "/LIG/", "/LIG/>", "/LIG/>>", 0
187 };
188 const char *encligops[] = {
189 "=:", "|=:", "|=:>", "=:|", "=:|>", "|=:|", "|=:|>", "|=:|>>", 0
190 };
191 struct lig {
192 struct lig *next;
193 const char *succ, *sub;
194 short op, boundleft;
195 };
196 struct kern {
197 struct kern *next;
198 const char *succ;
199 int delta;
200 };
201 struct adobeptr {
202 struct adobeptr *next;
203 struct adobeinfo *ch;
204 };
205 struct pcc {
206 struct pcc *next;
207 const char * partname;
208 int xoffset, yoffset;
209 };
210
211 FILE *afmin, *vplout, *tfmout;
212 #define MAXNAME 256
213 char inname[MAXNAME], outname[MAXNAME]; /* names of input and output files */
214 char tmpstr[MAXNAME]; /* a buffer for one string */
215 #define INBUFSIZE 1024
216 char buffer[INBUFSIZE+10]; /* input buffer (modified while parsing) */
217 char obuffer[INBUFSIZE+10]; /* unmodified copy of input buffer */
218 char *param; /* current position in input buffer */
219 const char *fontname = "Unknown";
220 const char *codingscheme = "Unspecified";
221 #ifdef VMCMS
222 char *ebfontname;
223 char *ebcodingscheme;
224 #endif
225 float italicangle = 0.0;
226 char fixedpitch;
227 char makevpl;
228 char pedantic;
229 int noaccentheightadjust;
230 int xheight = 400;
231 int fontspace;
232 int bc, ec;
233 long cksum;
234 float efactor = 1.0, slant = 0.0;
235 float capheight = 0.8;
236 char *efactorparam, *slantparam;
237 double newslant;
238 char titlebuf[500];
239
240 static void
241 error(const char *s)
242 {
243 fprintf(stderr, "%s\n", s);
244 if (obuffer[0]) {
245 fprintf(stderr, "%s\n", obuffer);
246 while (param > buffer) {
247 fprintf(stderr, " ");
248 param--;
249 }
250 fprintf(stderr, "^\n");
251 }
252 if (*s == '!')
253 exit(1);
254 }
255
256 static int
257 transform(register int x, register int y)
258 {
259 register double acc;
260 acc = efactor * x + slant *y;
261 return (int)(acc>=0? floor(acc+0.5) : ceil(acc-0.5) );
262 }
263
264 static int
265 texlive_getline(void) {
266 register char *p;
267 register int c;
268
269 param = buffer;
270 for (p=buffer; (c=getc(afmin)) != EOF;) {
271 if (p - buffer >= INBUFSIZE)
272 error("! input line too long; perhaps input file is malformed?");
273 *p++ = c;
274 if (c == '\r') {
275 c = getc(afmin);
276 if (c != EOF) {
277 if (c == '\n') {
278 *p++ = c;
279 } else {
280 ungetc(c, afmin);
281 }
282 }
283 break;
284 } else if (c == '\n') {
285 break;
286 }
287 }
288 *p = 0;
289 strcpy(obuffer, buffer);
290 if (p == buffer && c == EOF)
291 return(0);
292 else
293 return(1);
294 }
295
296 const char *interesting[] = { "FontName", "ItalicAngle", "IsFixedPitch",
297 "XHeight", "C", "KPX", "CC", "EncodingScheme", NULL};
298 #define FontName (0)
299 #define ItalicAngle (1)
300 #define IsFixedPitch (2)
301 #define XHeight (3)
302 #define C (4)
303 #define KPX (5)
304 #define CC (6)
305 #define EncodingScheme (7)
306 #define NONE (-1)
307 static int
308 interest(const char *s)
309 {
310 register const char **p;
311 register int n;
312
313 for (p=interesting, n=0; *p; p++, n++)
314 if (strcmp(s, *p)==0)
315 return(n);
316 return(NONE);
317 }
318
319 static char *
320 mymalloc(unsigned long len)
321 {
322 register char *p;
323 int i;
324
325 #ifdef SMALLMALLOC
326 if (len > 65500L)
327 error("! can't allocate more than 64K!");
328 #endif
329 p = (char *) malloc((unsigned)len);
330 if (p==NULL)
331 error("! out of memory");
332 for (i=0; i<len; i++)
333 p[i] = 0;
334 return(p);
335 }
336
337 static char *
338 newstring(char *s)
339 {
340 char *q = mymalloc((unsigned long)(strlen(s) + 1));
341 strcpy(q, s);
342 return q;
343 }
344
345 static char *
346 paramnewstring(void) {
347 register char *p, *q;
348
349 p = param;
350 while (*p > ' ')
351 p++;
352 if (*p != 0)
353 *p++ = 0;
354 q = newstring(param);
355 while (*p && *p <= ' ')
356 p++;
357 param = p;
358 return(q);
359 }
360
361 static char *
362 paramstring(void) {
363 register char *p, *q;
364
365 p = param;
366 while (*p > ' ')
367 p++;
368 q = param;
369 if (*p != 0)
370 *p++ = 0;
371 while (*p && *p <= ' ')
372 p++;
373 param = p;
374 return(q);
375 }
376
377 static int
378 paramnum(void) {
379 register char *p;
380 int i;
381
382 p = paramstring();
383 if (sscanf(p, "%d", &i) != 1)
384 error("! integer expected");
385 return(i);
386 }
387
388 static float
389 paramfloat(void) {
390 register char *p;
391 float i;
392
393 p = paramstring();
394 if (sscanf(p, "%f", &i) != 1)
395 error("! number expected");
396 return(i);
397 }
398
399 static struct adobeinfo *
400 newchar(void) {
401 register struct adobeinfo *ai;
402
403 ai = (struct adobeinfo *)mymalloc((unsigned long)sizeof(struct adobeinfo));
404 ai->adobenum = -1;
405 ai->texnum = -1;
406 ai->width = -1;
407 ai->adobename = NULL;
408 ai->llx = -1;
409 ai->lly = -1;
410 ai->urx = -1;
411 ai->ury = -1;
412 ai->ligs = NULL;
413 ai->kerns = NULL;
414 ai->kern_equivs = NULL;
415 ai->pccs = NULL;
416 ai->next = adobechars;
417 adobechars = ai;
418 return(ai);
419 }
420
421 static struct kern *
422 newkern(void) {
423 register struct kern *nk;
424
425 nk = (struct kern *)mymalloc((unsigned long)sizeof(struct kern));
426 nk->next = NULL;
427 nk->succ = NULL;
428 nk->delta = 0;
429 return(nk);
430 }
431
432 static struct pcc *
433 newpcc(void) {
434 register struct pcc *np;
435
436 np = (struct pcc *)mymalloc((unsigned long)sizeof(struct pcc));
437 np->next = NULL;
438 np->partname = NULL;
439 np->xoffset = 0;
440 np->yoffset = 0;
441 return(np);
442 }
443
444 static struct lig *
445 newlig(void) {
446 register struct lig *nl;
447
448 nl = (struct lig *)mymalloc((unsigned long)sizeof(struct lig));
449 nl->next = NULL;
450 nl->succ = NULL;
451 nl->sub = NULL;
452 nl->op = 0; /* the default =: op */
453 nl->boundleft = 0;
454 return(nl);
455 }
456
457 static void
458 expect(const char *s)
459 {
460 if (strcmp(paramstring(), s) != 0) {
461 fprintf(stderr, "%s expected: ", s);
462 error("! syntax error");
463 }
464 }
465
466 static void
467 handlechar(void) { /* an input line beginning with C */
468 register struct adobeinfo *ai;
469 register struct lig *nl;
470
471 ai = newchar();
472 ai->adobenum = paramnum();
473 expect(";");
474 expect("WX");
475 ai->width = transform(paramnum(),0);
476 if (ai->adobenum >= 0 && ai->adobenum < 256) {
477 adobeptrs[ai->adobenum] = ai;
478 }
479 expect(";");
480 /* Ignore vertical metrics information */
481 if (*param == 'W' && *(param + 1) == 'Y') {
482 expect("WY");
483 paramnum();
484 expect(";");
485 }
486 expect("N");
487 ai->adobename = paramnewstring();
488 expect(";");
489 expect("B");
490 ai->llx = paramnum();
491 ai->lly = paramnum();
492 ai->llx = transform(ai->llx, ai->lly);
493 ai->urx = paramnum();
494 ai->ury = paramnum();
495 ai->urx = transform(ai->urx, ai->ury);
496 /* We need to avoid negative heights or depths. They break accents in
497 math mode, among other things. */
498 if (ai->lly > 0)
499 ai->lly = 0;
500 if (ai->ury < 0)
501 ai->ury = 0;
502 expect(";");
503 /* Now look for ligatures (which aren't present in fixedpitch fonts) */
504 while (*param == 'L' && !fixedpitch) {
505 expect("L");
506 nl = newlig();
507 nl->succ = paramnewstring();
508 nl->sub = paramnewstring();
509 nl->next = ai->ligs;
510 ai->ligs = nl;
511 expect(";");
512 }
513 }
514
515 static struct adobeinfo *
516 findadobe(const char *p)
517 {
518 register struct adobeinfo *ai;
519
520 for (ai=adobechars; ai; ai = ai->next)
521 if (strcmp(p, ai->adobename)==0)
522 return(ai);
523 return(NULL);
524 }
525
526
527 /*
528 * The following comment no longer applies; we rely on the LIGKERN
529 * entries to kill space kerns. Also, the same applies to numbers.
530 *
531 * We ignore kerns before and after space characters, because (1) TeX
532 * is using the space only for Polish ligatures, and (2) TeX's
533 * boundarychar mechanisms are not oriented to kerns (they apply
534 * to both spaces and punctuation) so we don't want to use them.
535 */
536 static void
537 handlekern(void) { /* an input line beginning with KPX */
538 register struct adobeinfo *ai;
539 register char *p;
540 register struct kern *nk;
541
542 p = paramstring();
543 ai = findadobe(p);
544 if (ai == NULL)
545 error("kern char not found");
546 else {
547 nk = newkern();
548 nk->succ = paramnewstring();
549 nk->delta = transform(paramnum(),0);
550 nk->next = ai->kerns;
551 ai->kerns = nk;
552 }
553 }
554
555 static void
556 handleconstruct(void) { /* an input line beginning with CC */
557 register struct adobeinfo *ai;
558 register char *p;
559 register struct pcc *np;
560 register int n;
561 struct pcc *npp = NULL;
562
563 p = paramstring();
564 ai = findadobe(p);
565 if (ai == NULL)
566 error("! composite character name not found");
567 n = paramnum();
568 expect(";");
569 while (n--) {
570 if (strcmp(paramstring(),"PCC") != 0) return;
571 /* maybe I should expect("PCC") instead, but I'm playing it safe */
572 np = newpcc();
573 np->partname = paramnewstring();
574 if (findadobe(np->partname)==NULL) return;
575 np->xoffset = paramnum();
576 np->yoffset = paramnum();
577 np->xoffset = transform(np->xoffset, np->yoffset);
578 if (npp) npp->next = np;
579 else ai->pccs = np;
580 npp = np;
581 expect(";");
582 }
583 }
584
585 static struct encoding *readencoding(char *);
586
587 #if 0
588 /* Not used */
589 static void
590 makeaccentligs(void) {
591 register struct adobeinfo *ai, *aci;
592 register char *p;
593 register struct lig *nl;
594 for (ai=adobechars; ai; ai=ai->next) {
595 p = ai->adobename;
596 if (strlen(p)>2)
597 if ((aci=findadobe(p+1)) && (aci->adobenum > 127)) {
598 nl = newlig();
599 nl->succ = mymalloc((unsigned long)2);
600 *(nl->succ + 1) = 0;
601 *(nl->succ) = *p;
602 nl->sub = ai->adobename;
603 nl->next = aci->ligs;
604 aci->ligs = nl;
605 }
606 }
607 }
608 #endif
609
610 static void
611 readadobe(void) {
612 struct adobeinfo *ai;
613 #ifdef VMCMS
614 int i;
615 #endif
616
617 /*
618 * We allocate a placeholder boundary char.
619 */
620 ai = newchar();
621 ai->adobenum = -1;
622 ai->adobename = "||"; /* boundary character name */
623 while (texlive_getline()) {
624 switch(interest(paramstring())) {
625 case FontName:
626 fontname = paramnewstring();
627 #ifdef VMCMS
628 /* fontname comes in as ebcdic but we need it asciified for tfm file
629 so we save it in ebfontname and change it in fontname */
630 ebfontname = newstring(fontname);
631 i=0;
632 while(fontname[i] != '\0') {
633 fontname[i]=ebcdic2ascii[fontname[i]];
634 i++;
635 };
636 #endif
637 break;
638 case EncodingScheme:
639 codingscheme = paramnewstring();
640 #ifdef VMCMS
641 /* for codingscheme, we do the same as we did for fontname */
642 ebcodingscheme = newstring(codingscheme);
643 i=0;
644 while(codingscheme[i] != '\0') {
645 codingscheme[i]=ebcdic2ascii[codingscheme[i]];
646 i++;
647 }
648 #endif
649 break;
650 case ItalicAngle:
651 italicangle = paramfloat();
652 break;
653 case IsFixedPitch:
654 if (*param == 't' || *param == 'T')
655 fixedpitch = 1;
656 else
657 fixedpitch = 0;
658 break;
659 case XHeight:
660 xheight = paramnum();
661 break;
662 case C:
663 handlechar();
664 break;
665 case KPX:
666 handlekern();
667 break;
668 case CC:
669 handleconstruct();
670 break;
671 default:
672 break;
673 }
674 }
675 fclose(afmin);
676 afmin = 0;
677 }
678 /*
679 * Re-encode the adobe font. Assumes that the header file will
680 * also contain the appropriate instructions!
681 */
682 static void
683 handlereencoding(void) {
684 if (inenname) {
685 int i;
686 struct adobeinfo *ai;
687 const char *p;
688
689 ignoreligkern = 1;
690 inencoding = readencoding(inenname);
691 for (i=0; i<256; i++)
692 if (0 != (ai=adobeptrs[i])) {
693 ai->adobenum = -1;
694 adobeptrs[i] = NULL;
695 }
696 for (i=0; i<256; i++) {
697 p = inencoding->vec[i];
698 if (p && *p && strcmp(p, ".notdef") != 0 && 0 != (ai = findadobe(p))) {
699 ai->adobenum = i;
700 adobeptrs[i] = ai;
701 }
702 }
703 codingscheme = inencoding->name;
704 }
705 ignoreligkern = 0;
706 if (outenname) {
707 outencoding = readencoding(outenname);
708 } else {
709 outencoding = readencoding((char *)0);
710 }
711 }
712
713 /*
714 * This routine reverses a list. We use it because we accumulate the
715 * adobeinfo list in reverse order, but when we go to map the
716 * characters, we would prefer to use the original ordering. It just
717 * makes more sense.
718 */
719 static struct adobeinfo *
720 revlist (struct adobeinfo *p)
721 {
722 struct adobeinfo *q = 0, *t;
723
724 while (p) {
725 t = p->next;
726 p->next = q;
727 q = p;
728 p = t;
729 }
730 return q;
731 }
732
733 static void
734 assignchars(void) {
735 register const char **p;
736 register int i, j;
737 register struct adobeinfo *ai, *pai;
738 int nextfree = 128;
739 struct pcc *pcp;
740
741 /*
742 * First, we assign all those that match perfectly.
743 */
744 for (i=0, p=outencoding->vec; i<256; i++, p++)
745 if (*p && strcmp(*p, ".notdef") != 0 &&
746 (ai=findadobe(*p)) && (ai->adobenum >= 0 || ai->pccs != NULL)) {
747 if (ai->texnum >= 0)
748 nexttex[i] = ai->texnum; /* linked list */
749 ai->texnum = i;
750 texptrs[i] = ai;
751 }
752 if (pedantic)
753 return;
754 /*
755 * Next, we assign all the others, retaining the adobe positions, possibly
756 * multiply assigning characters. Unless the output encoding was
757 * precisely specified.
758 */
759 for (ai=adobechars; ai; ai=ai->next)
760 if (ai->adobenum >= 0 && ai->adobenum <256
761 && ai->texnum < 0 && texptrs[ai->adobenum] == 0) {
762 ai->texnum = ai->adobenum;
763 texptrs[ai->adobenum] = ai;
764 }
765 /*
766 * Finally, we map all remaining characters into free locations beginning
767 * with 128, if we know how to construct those characters. We need to
768 * make sure the component pieces are mapped.
769 */
770 adobechars = revlist(adobechars);
771 for (ai=adobechars; ai; ai=ai->next)
772 if (ai->texnum<0 && (ai->adobenum>=0 || ai->pccs != NULL)) {
773 while (texptrs[nextfree]) {
774 nextfree=(nextfree+1)&255;
775 if (nextfree==128) goto finishup; /* all slots full */
776 }
777 ai->texnum = nextfree;
778 texptrs[nextfree] = ai;
779 }
780 finishup:
781 /*
782 * We now check all of the composite characters. If any of the
783 * components are not mapped, we unmap the composite character.
784 */
785 for (i=0; i<256; i++) {
786 ai = texptrs[i];
787 if (ai && ai->pccs != NULL && ai->texnum >= 0) {
788 for (pcp = ai->pccs; pcp; pcp = pcp->next) {
789 pai = findadobe(pcp->partname);
790 if (pai == NULL || pai->texnum < 0) {
791 texptrs[ai->texnum] = 0;
792 ai->texnum = -1;
793 break;
794 }
795 }
796 }
797 }
798 /*
799 * Now, if any of the characters are encoded multiple times, we want
800 * ai->texnum to be the first one assigned, since that is most likely
801 * to be the most important one. So we reverse the above lists.
802 */
803 for (ai=adobechars; ai; ai=ai->next)
804 if (ai->texnum >= 0 && ai->texnum < 256) {
805 j = -1;
806 while (nexttex[ai->texnum] >= 0) {
807 i = nexttex[ai->texnum];
808 nexttex[ai->texnum] = j;
809 j = ai->texnum;
810 ai->texnum = i;
811 }
812 nexttex[ai->texnum] = j;
813 }
814 }
815
816 static void
817 upmap(void) { /* Compute uppercase mapping, when making a small caps font */
818 register struct adobeinfo *ai, *Ai;
819 register const char *p;
820 register char *q;
821 register struct pcc *np, *nq;
822 int i;
823 char lwr[50];
824
825 /* JLH: changed some lines below to be ascii<->ebcdic independent
826 any reason we don't use 'isupper'?.
827 Looks like we should use isupper to me --karl. */
828 for (Ai=adobechars; Ai; Ai=Ai->next) {
829 p = Ai->adobename;
830 if (isupper ((unsigned char)*p)) {
831 q = lwr;
832 for (; *p; p++)
833 *q++ = TOLOWER (*p);
834 *q = '\0'; /* changed this too! */
835
836 if (0 != (ai=findadobe(lwr))) {
837 for (i = ai->texnum; i >= 0; i = nexttex[i])
838 uppercase[i] = Ai;
839 for (i = Ai->texnum; i >= 0; i = nexttex[i])
840 lowercase[i] = ai;
841 }
842 }
843 }
844 /* Note that, contrary to the normal true/false conventions,
845 * uppercase[i] is NULL and lowercase[i] is non-NULL when i is the
846 * ASCII code of an uppercase letter; and vice versa for lowercase letters */
847
848 if (0 != (ai=findadobe("germandbls")))
849 if (0 != (Ai=findadobe("S"))) { /* we also construct SS */
850 for (i=ai->texnum; i >= 0; i = nexttex[i])
851 uppercase[i] = ai;
852 ai->adobenum = -1;
853 ai->width = Ai->width << 1;
854 ai->llx = Ai->llx;
855 ai->lly = Ai->lly;
856 ai->urx = Ai->width + Ai->urx;
857 ai->ury = Ai->ury;
858 ai->kerns = Ai->kerns;
859 np = newpcc();
860 np->partname = "S";
861 nq = newpcc();
862 nq->partname = "S";
863 nq->xoffset = Ai->width;
864 np->next = nq;
865 ai->pccs = np;
866 }
867 if ((ai=findadobe("dotlessi")))
868 for (i=ai->texnum; i >= 0; i = nexttex[i])
869 uppercase[i] = findadobe("I");
870 if ((ai=findadobe("dotlessj")))
871 for (i=ai->texnum; i >= 0; i = nexttex[i])
872 uppercase[i] = findadobe("J");
873 }
874 /* The logic above seems to work well enough, but it leaves useless characters
875 * like `fi' and `fl' in the font if they were present initially,
876 * and it omits characters like `dotlessj' if they are absent initially */
877
878 /* Now we turn to computing the TFM file */
879
880 int lf, lh, nw, nh, nd, ni, nl, nk, ne, np;
881
882 static void
883 write16(register short what)
884 {
885 fputc(what >> 8, tfmout);
886 fputc(what & 255, tfmout);
887 }
888
889 static void
890 writearr(register long *p, register int n)
891 {
892 while (n) {
893 write16((short)(*p >> 16));
894 write16((short)(*p & 65535));
895 p++;
896 n--;
897 }
898 }
899
900 static void
901 makebcpl(register long *p, register const char *s, register int n)
902 {
903 register long t;
904 register long sc;
905
906 if (strlen(s) < n)
907 n = strlen(s);
908 t = ((long)n) << 24;
909 sc = 16;
910 while (n > 0) {
911 t |= ((long)(*(unsigned const char *)s++)) << sc;
912 sc -= 8;
913 if (sc < 0) {
914 *p++ = t;
915 t = 0;
916 sc = 24;
917 }
918 n--;
919 }
920 *p++ = t;
921 }
922
923 int source[257];
924 int unsort[257];
925
926 /*
927 * Next we need a routine to reduce the number of distinct dimensions
928 * in a TFM file. Given an array what[0]...what[oldn-1], we want to
929 * group its elements into newn clusters, in such a way that the maximum
930 * difference between elements of a cluster is as small as possible.
931 * Furthermore, what[0]=0, and this value must remain in a cluster by
932 * itself. Data such as `0 4 6 7 9' with newn=3 shows that an iterative
933 * scheme in which 6 is first clustered with 7 will not work. So we
934 * borrow a neat algorithm from METAFONT to find the true optimum.
935 * Memory location what[oldn] is set to 0x7fffffffL for convenience.
936 */
937 long nextd; /* smallest value that will give a different mincover */
938 static int
939 mincover(long *what,
940 register long d) /* tells how many clusters result, given max difference d */
941 {
942 register int m;
943 register long l;
944 register long *p;
945
946 nextd = 0x7fffffffL;
947 p = what+1;
948 m = 1;
949 while (*p<0x7fffffffL) {
950 m++;
951 l = *p;
952 while (*++p <= l+d);
953 if (*p-l < nextd) nextd = *p-l;
954 }
955 return (m);
956 }
957
958 static void
959 remap(long * what, int oldn, int newn)
960 {
961 register int i, j;
962 register long d, l;
963
964 what[oldn] = 0x7fffffffL;
965 for (i=oldn-1; i>0; i--) {
966 d = what[i];
967 for (j=i; what[j+1]<d; j++) {
968 what[j] = what[j+1];
969 source[j] = source[j+1];
970 }
971 what[j] = d;
972 source[j] = i;
973 } /* Tom, don't let me ever catch you using bubblesort again! -- Don */
974
975 i = mincover(what, 0L);
976 d = nextd;
977 while (mincover(what,d+d)>newn) d += d;
978 while (mincover(what,d)>newn) d = nextd;
979
980 i = 1;
981 j = 0;
982 while (i<oldn) {
983 j++;
984 l = what[i];
985 unsort[source[i]] = j;
986 while (what[++i] <= l+d) {
987 unsort[source[i]] = j;
988 if (i-j == oldn-newn) d = 0;
989 }
990 what[j] = (l+what[i-1])/2;
991 }
992 }
993
994 static long
995 checksum(void) {
996 int i;
997 unsigned long s1 = 0, s2 = 0;
998 const char *p;
999 struct adobeinfo *ai;
1000
1001 for (i=0; i<256; i++)
1002 if (0 != (ai=adobeptrs[i])) {
1003 s1 = ((s1 << 1) ^ (s1>>31)) ^ ai->width; /* cyclic left shift */
1004 s1 &= 0xffffffff; /* in case we're on a 64-bit machine */
1005 for (p=ai->adobename; *p; p++)
1006 #ifndef VMCMS
1007 s2 = (s2 * 3) + *p;
1008 #else
1009 s2 = (s2 * 3) + ebcdic2ascii[*p];
1010 #endif
1011 }
1012 s1 = (s1 << 1) ^ s2;
1013 return s1;
1014 }
1015
1016 /*
1017 * The next routine simply scales something.
1018 * Input is in 1000ths of an em. Output is in FIXFACTORths of 1000.
1019 */
1020 #define FIXFACTOR (0x100000L) /* 2^{20}, the unit fixnum */
1021 static long
1022 scale(long what)
1023 {
1024 return(((what / 1000) << 20) +
1025 (((what % 1000) << 20) + 500) / 1000);
1026 }
1027
1028 long *header, *charinfo, *width, *height, *depth, *ligkern, *kern, *tparam,
1029 *italic;
1030 long *tfmdata;
1031
1032 static void
1033 buildtfm(void) {
1034 register int i, j;
1035 register struct adobeinfo *ai;
1036
1037 header = tfmdata;
1038 cksum = checksum();
1039 header[0] = cksum;
1040 header[1] = 0xa00000; /* 10pt design size */
1041 makebcpl(header+2, codingscheme, 39);
1042 makebcpl(header+12, fontname, 19);
1043 lh = 17;
1044 charinfo = header + lh;
1045
1046 for (i=0; i<256 && adobeptrs[i]==NULL; i++);
1047 bc = i;
1048 for (i=255; i>=0 && adobeptrs[i]==NULL; i--);
1049 ec = i;
1050 if (ec < bc)
1051 error("! no Adobe characters");
1052
1053 width = charinfo + (ec - bc + 1);
1054 width[0] = 0;
1055 nw++;
1056 for (i=bc; i<=ec; i++)
1057 if (0 != (ai=adobeptrs[i])) {
1058 width[nw]=ai->width;
1059 for (j=1; width[j]!=ai->width; j++);
1060 ai->wptr = j;
1061 if (j==nw)
1062 nw++;
1063 }
1064 if (nw>256)
1065 error("! 256 chars with different widths");
1066 depth = width + nw;
1067 depth[0] = 0;
1068 nd = 1;
1069 for (i=bc; i<=ec; i++)
1070 if (0 != (ai=adobeptrs[i])) {
1071 depth[nd] = -ai->lly;
1072 for (j=0; depth[j]!=-ai->lly; j++);
1073 ai->dptr = j;
1074 if (j==nd)
1075 nd++;
1076 }
1077 if (nd > 16) {
1078 remap(depth, nd, 16);
1079 nd = 16;
1080 for (i=bc; i<=ec; i++)
1081 if (0 != (ai=adobeptrs[i]))
1082 ai->dptr = unsort[ai->dptr];
1083 }
1084 height = depth + nd;
1085 height[0] = 0;
1086 nh = 1;
1087 for (i=bc; i<=ec; i++)
1088 if (0 != (ai=adobeptrs[i])) {
1089 height[nh]=ai->ury;
1090 for (j=0; height[j]!=ai->ury; j++);
1091 ai->hptr = j;
1092 if (j==nh)
1093 nh++;
1094 }
1095 if (nh > 16) {
1096 remap(height, nh, 16);
1097 nh = 16;
1098 for (i=bc; i<=ec; i++)
1099 if (0 != (ai=adobeptrs[i]))
1100 ai->hptr = unsort[ai->hptr];
1101 }
1102 italic = height + nh;
1103 italic[0] = 0;
1104 ni = 1;
1105 for (i=bc; i<=ec; i++)
1106 if (0 != (ai=adobeptrs[i])) {
1107 italic[ni] = ai->urx - ai->width;
1108 if (italic[ni]<0)
1109 italic[ni] = 0;
1110 for (j=0; italic[j]!=italic[ni]; j++);
1111 ai->iptr = j;
1112 if (j==ni)
1113 ni++;
1114 }
1115 if (ni > 64) {
1116 remap(italic, ni, 64);
1117 ni = 64;
1118 for (i=bc; i<=ec; i++)
1119 if (0 != (ai=adobeptrs[i]))
1120 ai->iptr = unsort[ai->iptr];
1121 }
1122
1123 for (i=bc; i<=ec; i++)
1124 if (0 != (ai=adobeptrs[i]))
1125 charinfo[i-bc] = ((long)(ai->wptr)<<24) +
1126 ((long)(ai->hptr)<<20) +
1127 ((long)(ai->dptr)<<16) +
1128 ((long)(ai->iptr)<<10);
1129
1130 ligkern = italic + ni;
1131 nl = 0; /* ligatures and kerns omitted from raw Adobe font */
1132 kern = ligkern + nl;
1133 nk = 0;
1134
1135 newslant = (double)slant - efactor * tan(italicangle*(3.1415926535/180.0));
1136 tparam = kern + nk;
1137 tparam[0] = (long)(FIXFACTOR * newslant + 0.5);
1138 tparam[1] = scale((long)fontspace);
1139 tparam[2] = (fixedpitch ? 0 : scale((long)(300*efactor+0.5)));
1140 tparam[3] = (fixedpitch ? 0 : scale((long)(100*efactor+0.5)));
1141 tparam[4] = scale((long)xheight);
1142 tparam[5] = scale((long)(1000*efactor+0.5));
1143 np = 6;
1144 }
1145
1146 static void
1147 writesarr(long *what, int len)
1148 {
1149 register long *p;
1150 int i;
1151
1152 p = what;
1153 i = len;
1154 while (i) {
1155 *p = scale(*p);
1156 scale(*p); /* need this kludge for some compilers */
1157 p++;
1158 i--;
1159 }
1160 writearr(what, len);
1161 }
1162
1163 static void
1164 writetfm(void) {
1165 lf = 6 + lh + (ec - bc + 1) + nw + nh + nd + ni + nl + nk + ne + np;
1166 write16((short)lf);
1167 write16((short)lh);
1168 write16((short)bc);
1169 write16((short)ec);
1170 write16((short)nw);
1171 write16((short)nh);
1172 write16((short)nd);
1173 write16((short)ni);
1174 write16((short)nl);
1175 write16((short)nk);
1176 write16((short)ne);
1177 write16((short)np);
1178 writearr(header, lh);
1179 writearr(charinfo, ec-bc+1);
1180 writesarr(width, nw);
1181 writesarr(height, nh);
1182 writesarr(depth, nd);
1183 writesarr(italic, ni);
1184 writearr(ligkern, nl);
1185 writesarr(kern, nk);
1186 writearr(tparam, np);
1187 }
1188
1189 /* OK, the TFM file is done! Now for our next trick, the VPL file. */
1190
1191 /* For TeX we want to compute a character height that works properly
1192 with accents. We only do this if the xheight has a reasonable value
1193 (>50), and only if the -a flag is not given. Furthermore, we never
1194 return a height less than the height of the original character.
1195
1196 The idea of this routine is to adjust the heights of bare characters
1197 (say, t) so that the result of using the \accent primitive (say, \"t)
1198 is the same as a precomposed tdieresis character. This is done in
1199 the vpl output, so the vf+tfm generated from the vpl are affected,
1200 but not the original tfm.
1201
1202 This idea is reasonable, but the downside is that changing the height
1203 of the base character at all, but especially downward, has
1204 undesirable consequences: when putting a rule over the character or
1205 constructing a math bar-over accent, for example, the rule will be
1206 too close to (or too far from, if the height is increased) the
1207 character.
1208
1209 Furthermore, these days, except when using the original CM fonts,
1210 precomposed accent glyphs are widely available and used. And afm2tfm
1211 is not used much with the original CM fonts, as they don't come with
1212 afm files :).
1213
1214 In any case, there is one situation where adjusting the height of the
1215 base character by looking at the standalone accent is definitely
1216 wrong: the dcaron, tcaron, and [Ll]caron glyphs. In these cases, the
1217 usual check-above shape is replaced by (approximately) an apostrophe
1218 to the right of the character. Therefore looking at the standalone
1219 check glyph is inapplicable.
1220
1221 In general, it seems wrong to ever decrease the height from the
1222 original, since that will almost certainly result in crashes with
1223 \bar and the like. That seems worse than a mispositioned accent.
1224 So the routine returns the original height if the heuristic would
1225 decrease it.
1226
1227 Nevertheless, despite all the above, the original behavior has been
1228 around for so many years that it seems bad to change it now. So
1229 adjustments upward are still made, unless -a is given.
1230
1231 The following list of accents doesn't need to be complete. */
1232 const char *accents[] = { "acute", "tilde", "caron", "dieresis", NULL };
1233
1234 static int
1235 texheight(struct adobeinfo *ai)
1236 {
1237 const char **p;
1238 struct adobeinfo *aci, *acci;
1239 /* The `ai' argument is the base letter, e.g., "d".
1240 `aci' is the accent, e.g., "caron".
1241 `acci' is the pre-composed accented letter, e.g., "dcaron". */
1242
1243 /* If -a was given, or the xheight is too small, or the character
1244 name is more than one letter long, return the original height. */
1245 if (noaccentheightadjust
1246 || xheight <= 50
1247 || *(ai->adobename + 1))
1248 return ai->ury;
1249
1250 for (p = accents; *p; p++) { /* otherwise we look for accented letters */
1251 aci = findadobe(*p);
1252 if (aci) {
1253 strcpy(buffer, ai->adobename);
1254 strcat(buffer, *p);
1255 acci = findadobe(buffer);
1256 if (acci) {
1257 /* height heuristic since \accent assumes x-height positioning */
1258 int guess = acci->ury - aci->ury + xheight;
1259 if (guess > ai->ury) { /* ignore guess if it reduces height */
1260 return guess;
1261 }
1262 }
1263 }
1264 }
1265
1266 /* didn't find anything to adjust, return original */
1267 return ai->ury;
1268 }
1269
1270 /* modified tgr to eliminate varargs problems */
1271
1272 #define vout(s) fprintf(vplout, s)
1273 int level; /* the depth of parenthesis nesting in VPL file being written */
1274 static void
1275 vlevout(void)
1276 {
1277 register int l = level;
1278 while (l--) vout(" ");
1279 }
1280 static void
1281 vlevnlout(void)
1282 {
1283 vout("\n");
1284 vlevout();
1285 }
1286 #define voutln(str) {fprintf(vplout,"%s\n",str);vlevout();}
1287 #define voutln2(f,s) {fprintf(vplout,f,s);vlevnlout();}
1288 #define voutln3(f,a,b) {fprintf(vplout,f,a,b);vlevnlout();}
1289 #define voutln4(f,a,b,c) {fprintf(vplout,f,a,b,c);vlevnlout();}
1290 static void
1291 vleft(void)
1292 {
1293 level++;
1294 vout("(");
1295 }
1296
1297 static void
1298 vright(void)
1299 {
1300 level--;
1301 voutln(")");
1302 }
1303
1304 int forceoctal = 0;
1305
1306 char vcharbuf[100];
1307 static char *
1308 vchar(int c)
1309 {
1310 if (forceoctal == 0 && ISALNUM (c))
1311 sprintf(vcharbuf,"C %c",
1312 #ifndef VMCMS
1313 c);
1314 #else
1315 ascii2ebcdic[c]);
1316 #endif
1317 else sprintf(vcharbuf,"O %o", (unsigned)c);
1318 return vcharbuf;
1319 }
1320
1321 char vnamebuf[1000];
1322 static char *
1323 vname(int c)
1324 {
1325 if (!forceoctal && ISALNUM (c)) {
1326 vnamebuf[0] = 0;
1327 } else if (c >= 0 && c < 256) {
1328 snprintf (vnamebuf, sizeof (vnamebuf),
1329 " (comment %s)", texptrs[c]->adobename);
1330 }
1331 return vnamebuf;
1332 }
1333
1334 static void
1335 writevpl(void)
1336 {
1337 register int i, j, k;
1338 register struct adobeinfo *ai;
1339 register struct lig *nlig;
1340 register struct kern *nkern;
1341 register struct pcc *npcc;
1342 struct adobeinfo *asucc, *asub, *api;
1343 struct adobeptr *kern_eq;
1344 int xoff, yoff, ht;
1345 char unlabeled;
1346
1347 voutln2("(VTITLE Created by %s)", titlebuf);
1348 voutln("(COMMENT Please edit that VTITLE if you edit this file)");
1349 snprintf(obuffer, sizeof(obuffer), "TeX-%s%s%s%s", outname,
1350 (efactor==1.0? "" : "-E"), (slant==0.0? "" : "-S"),
1351 (makevpl==1? "" : "-CSC"));
1352 if (strlen(obuffer)>19) { /* too long, will retain first 9 and last 10 */
1353 register char *p, *q;
1354 for (p = &obuffer[9], q = &obuffer[strlen(obuffer)-10]; p<&obuffer[19];
1355 p++, q++) *p = *q;
1356 obuffer[19] = '\0';
1357 }
1358 voutln2("(FAMILY %s)" , obuffer);
1359 {
1360 char tbuf[300];
1361 const char *base_encoding =
1362 #ifndef VMCMS
1363 codingscheme;
1364 #else
1365 ebcodingscheme;
1366 #endif
1367
1368 if (strcmp (outencoding->name, base_encoding) == 0) {
1369 snprintf(tbuf, sizeof(tbuf), "%s", outencoding->name);
1370 } else {
1371 snprintf(tbuf, sizeof(tbuf), "%s + %s", base_encoding,
1372 outencoding->name);
1373 }
1374
1375 if (strlen(tbuf) > 39) {
1376 error("Coding scheme too long; shortening to 39 characters.");
1377 tbuf[39] = 0;
1378 }
1379 voutln2("(CODINGSCHEME %s)", tbuf);
1380 }
1381 voutln("(DESIGNSIZE R 10.0)");
1382 voutln("(DESIGNUNITS R 1000)");
1383 voutln("(COMMENT DESIGNSIZE (1 em) IS IN POINTS)");
1384 voutln("(COMMENT OTHER DIMENSIONS ARE MULTIPLES OF DESIGNSIZE/1000)");
1385 /* Let vptovf compute the checksum. */
1386 /* voutln2("(CHECKSUM O %lo)",cksum ^ 0xffffffff); */
1387 if (boundarychar >= 0)
1388 voutln2("(BOUNDARYCHAR O %lo)", (unsigned long)boundarychar);
1389 vleft(); voutln("FONTDIMEN");
1390 if (newslant)
1391 voutln2("(SLANT R %f)", newslant);
1392 voutln2("(SPACE D %d)", fontspace);
1393 if (! fixedpitch) {
1394 voutln2("(STRETCH D %d)", transform(200,0));
1395 voutln2("(SHRINK D %d)", transform(100,0));
1396 }
1397 voutln2("(XHEIGHT D %d)", xheight);
1398 voutln2("(QUAD D %d)", transform(1000,0));
1399 voutln2("(EXTRASPACE D %d)", fixedpitch ? fontspace : transform(111, 0));
1400 vright();
1401 vleft(); voutln("MAPFONT D 0");
1402 voutln2("(FONTNAME %s)", outname);
1403 /* voutln2("(FONTCHECKSUM O %lo)", (unsigned long)cksum); */
1404 vright();
1405 if (makevpl>1) {
1406 vleft(); voutln("MAPFONT D 1");
1407 voutln2("(FONTNAME %s)", outname);
1408 voutln2("(FONTAT D %d)", (int)(1000.0*capheight+0.5));
1409 /* voutln2("(FONTCHECKSUM O %lo)", (unsigned long)cksum); */
1410 vright();
1411 }
1412
1413 for (i=0; i<256 && texptrs[i]==NULL; i++);
1414 bc = i;
1415 for (i=255; i>=0 && texptrs[i]==NULL; i--);
1416 ec = i;
1417
1418 vleft(); voutln("LIGTABLE");
1419 ai = findadobe("||");
1420 unlabeled = 1;
1421 for (nlig=ai->ligs; nlig; nlig=nlig->next)
1422 if (0 != (asucc=findadobe(nlig->succ))) {
1423 if (0 != (asub=findadobe(nlig->sub)))
1424 if (asucc->texnum>=0)
1425 if (asub->texnum>=0) {
1426 if (unlabeled) {
1427 voutln("(LABEL BOUNDARYCHAR)");
1428 unlabeled = 0;
1429 }
1430 for (j = asucc->texnum; j >= 0; j = nexttex[j]) {
1431 voutln4("(%s %s O %o)", vplligops[nlig->op],
1432 vchar(j), (unsigned)asub->texnum);
1433 }
1434 }
1435 }
1436 if (! unlabeled) voutln("(STOP)");
1437 for (i=bc; i<=ec; i++)
1438 if ((ai=texptrs[i]) && ai->texnum == i) {
1439 unlabeled = 1;
1440 if (uppercase[i]==NULL) /* omit ligatures from smallcap lowercase */
1441 for (nlig=ai->ligs; nlig; nlig=nlig->next)
1442 if (0 != (asucc=findadobe(nlig->succ)))
1443 if (0 != (asub=findadobe(nlig->sub)))
1444 if (asucc->texnum>=0)
1445 if (asub->texnum>=0) {
1446 if (unlabeled) {
1447 for (j = ai->texnum; j >= 0; j = nexttex[j])
1448 voutln3("(LABEL %s)%s", vchar(j), vname(j));
1449 unlabeled = 0;
1450 }
1451 for (j = asucc->texnum; j >= 0; j = nexttex[j]) {
1452 voutln4("(%s %s O %o)", vplligops[nlig->op],
1453 vchar(j), (unsigned)asub->texnum);
1454 if (nlig->boundleft)
1455 break;
1456 }
1457 }
1458 for (nkern = (uppercase[i] ? uppercase[i]->kerns : ai->kerns);
1459 nkern; nkern=nkern->next)
1460 if (0 != (asucc=findadobe(nkern->succ)))
1461 for (j = asucc->texnum; j >= 0; j = nexttex[j]) {
1462 if (uppercase[j]==NULL) {
1463 if (unlabeled) {
1464 for (k = ai->texnum; k >= 0; k = nexttex[k])
1465 voutln3("(LABEL %s)%s", vchar(k), vname(k));
1466 unlabeled = 0;
1467 }
1468 /* If other characters have the same kerns as this
1469 one, output the label here. This makes the TFM
1470 file much smaller than if we output all the
1471 kerns again under a different label. */
1472 for (kern_eq = ai->kern_equivs; kern_eq;
1473 kern_eq = kern_eq->next) {
1474 k = kern_eq->ch->texnum;
1475 if (k >= 0 && k < 256)
1476 voutln3("(LABEL %s)%s", vchar(k), vname(k));
1477 }
1478 ai->kern_equivs = 0; /* Only output those labels once. */
1479 if (uppercase[i]) {
1480 if (lowercase[j]) {
1481 for (k=lowercase[j]->texnum; k >= 0; k = nexttex[k])
1482 voutln4("(KRN %s R %.1f)%s", vchar(k),
1483 capheight*nkern->delta, vname(k));
1484 } else voutln4("(KRN %s R %.1f)%s",
1485 vchar(j), capheight*nkern->delta, vname(j));
1486 } else {
1487 voutln4("(KRN %s R %d)%s", vchar(j),
1488 nkern->delta, vname(j));
1489 if (lowercase[j])
1490 for (k=lowercase[j]->texnum; k >= 0; k = nexttex[k])
1491 voutln4("(KRN %s R %.1f)%s", vchar(k),
1492 capheight*nkern->delta, vname(k));
1493 }
1494 }
1495 }
1496 if (! unlabeled) voutln("(STOP)");
1497 }
1498 vright();
1499
1500 for (i=bc; i<=ec; i++)
1501 if (0 != (ai=texptrs[i])) {
1502 vleft(); fprintf(vplout, "CHARACTER %s", vchar(i));
1503 if (*vcharbuf=='C') {
1504 voutln("");
1505 } else
1506 voutln2(" (comment %s)", ai->adobename);
1507 if (uppercase[i]) {
1508 ai=uppercase[i];
1509 voutln2("(CHARWD R %.1f)", capheight * (ai->width));
1510 if (0 != (ht=texheight(ai)))
1511 voutln2("(CHARHT R %.1f)", capheight * ht);
1512 if (ai->lly)
1513 voutln2("(CHARDP R %.1f)", -capheight * ai->lly);
1514 if (ai->urx > ai->width)
1515 voutln2("(CHARIC R %.1f)", capheight * (ai->urx - ai->width));
1516 } else {
1517 voutln2("(CHARWD R %d)", ai->width);
1518 if (0 != (ht=texheight(ai)))
1519 voutln2("(CHARHT R %d)", ht);
1520 if (ai->lly)
1521 voutln2("(CHARDP R %d)", -ai->lly);
1522 if (ai->urx > ai->width)
1523 voutln2("(CHARIC R %d)", ai->urx - ai->width);
1524 }
1525 if (ai->adobenum != i || uppercase[i]) {
1526 vleft(); voutln("MAP");
1527 if (uppercase[i]) voutln("(SELECTFONT D 1)");
1528 if (ai->pccs && ai->adobenum < 0) {
1529 xoff = 0; yoff = 0;
1530 for (npcc = ai->pccs; npcc; npcc=npcc->next)
1531 if (0 != (api=findadobe(npcc->partname)))
1532 if (api->texnum>=0) {
1533 if (npcc->xoffset != xoff) {
1534 if (uppercase[i]) {
1535 voutln2("(MOVERIGHT R %.1f)",
1536 capheight * (npcc->xoffset - xoff));
1537 } else voutln2("(MOVERIGHT R %d)",
1538 npcc->xoffset - xoff);
1539 xoff = npcc->xoffset;
1540 }
1541 if (npcc->yoffset != yoff) {
1542 if (uppercase[i]) {
1543 voutln2("(MOVEUP R %.1f)",
1544 capheight * (npcc->yoffset - yoff));
1545 } else voutln2("(MOVEUP R %d)",
1546 npcc->yoffset - yoff);
1547 yoff = npcc->yoffset;
1548 }
1549 voutln2("(SETCHAR O %o)", (unsigned)api->adobenum);
1550 xoff += texptrs[api->texnum]->width;
1551 }
1552 } else voutln2("(SETCHAR O %o)", (unsigned)ai->adobenum);
1553 vright();
1554 }
1555 vright();
1556 }
1557 if (level) error("! I forgot to match the parentheses");
1558 }
1559
1560 #ifdef KPATHSEA
1561 static void
1562 version(FILE *f)
1563 {
1564 fputs ("afm2tfm(k) (dvips(k) 2026.1) 8.4\n", f);
1565 fprintf (f, "%s\n", kpathsea_version_string);
1566 fputs ("Copyright 2026 Radical Eye Software.\n\
1567 There is NO warranty. You may redistribute this software\n\
1568 under the terms of the GNU General Public License\n\
1569 and the Dvips copyright.\n\
1570 For more information about these matters, see the files\n\
1571 named COPYING and afm2tfm.c.\n\
1572 Original author of afm2tfm: T. Rokicki.\n", f);
1573 }
1574
1575 #define USAGE "\
1576 Convert an Adobe font metric file to TeX font metric format.\n\
1577 \n\
1578 -a omit heuristic adjustment of heights for accents\n\
1579 -c REAL use REAL for height of small caps made with -V [0.8]\n\
1580 -e REAL widen (extend) characters by a factor of REAL\n\
1581 -O use octal for all character codes in the vpl file\n\
1582 -p ENCFILE read/download ENCFILE for the PostScript encoding\n\
1583 -s REAL oblique (slant) characters by REAL, generally <<1\n\
1584 -t ENCFILE read ENCFILE for the encoding of the vpl file\n\
1585 -T ENCFILE equivalent to -p ENCFILE -t ENCFILE\n\
1586 -u output only characters from encodings, nothing extra\n\
1587 -v FILE[.vpl] make a VPL file for conversion to VF\n\
1588 -V SCFILE[.vpl] like -v, but synthesize smallcaps as lowercase\n\
1589 --help print this message and exit.\n\
1590 --version print version number and exit.\n\
1591 "
1592
1593 static void
1594 usage(FILE *f)
1595 {
1596 fputs ("Usage: afm2tfm FILE[.afm] [OPTION]... [FILE[.tfm]]\n", f);
1597 fputs (USAGE, f);
1598 putc ('\n', f);
1599 fputs (kpse_bug_address, f);
1600 }
1601 #else /* ! KPATHSEA */
1602 static void
1603 usage(FILE *f)
1604 {
1605 fprintf(f,
1606 "afm2tfm 8.1, Copyright 1990-97 by Radical Eye Software\n");
1607 fprintf(f,
1608 "Usage: afm2tfm foo[.afm] [-O] [-u] [-v|-V bar[.vpl]]\n");
1609 fprintf(f,
1610 " [-e expansion] [-s slant] [-c capheight]\n");
1611 fprintf(f,
1612 " [-p|-t|-T encodingfile] [foo[.tfm]]\n");
1613 }
1614 #endif
1615
1616 #define CHECKARG3 if (argc < 4) { usage(stderr); exit(1); }
1617
1618 static void
1619 openfiles(int argc, char **argv)
1620 {
1621 #ifndef KPATHSEA
1622 register int lastext;
1623 #else
1624 const char *q;
1625 #endif
1626 register int i;
1627 const char *p;
1628 int arginc;
1629
1630 tfmout = (FILE *)NULL;
1631
1632 if (argc == 1) {
1633 usage(stdout);
1634 exit(0);
1635 }
1636
1637 #if defined(MSDOS) || defined(OS2) || defined(ATARIST)
1638 /* Make VPL file identical to that created under Unix */
1639 snprintf(titlebuf, sizeof(titlebuf), "afm2tfm %s", argv[1]);
1640 #else
1641 #ifdef VMCMS
1642 /* Make VPL file identical to that created under Unix */
1643 snprintf(titlebuf, sizeof(titlebuf), "afm2tfm %s", argv[1]);
1644 #else
1645 snprintf(titlebuf, sizeof(titlebuf), "%s %s", argv[0], argv[1]);
1646 #endif
1647 #endif
1648 if(strlen(argv[1]) >= MAXNAME - 4)
1649 error("! too long input file name");
1650 strcpy(inname, argv[1]);
1651 #ifdef KPATHSEA
1652 if (find_suffix(inname) == NULL)
1653 strcat(inname, ".afm");
1654 #else
1655 lastext = -1;
1656 for (i=0; inname[i]; i++)
1657 if (inname[i] == '.')
1658 lastext = i;
1659 else if (inname[i] == '/' || inname[i] == ':')
1660 lastext = -1;
1661 if (lastext == -1) strcat(inname, ".afm");
1662 #endif
1663 while (argc>2 && *argv[2]=='-') {
1664 arginc = 2;
1665 i = argv[2][1];
1666 if (i == '/')
1667 i = argv[2][2] - 32; /* /a ==> A for VMS */
1668 switch (i) {
1669 case 'V': makevpl++;
1670 case 'v': makevpl++;
1671 CHECKARG3
1672 if(strlen(argv[3]) >= MAXNAME - 4)
1673 error("! too long output VPL file name");
1674 strcpy(outname, argv[3]);
1675 #ifdef KPATHSEA
1676 if (find_suffix(outname) == NULL)
1677 strcat(outname, ".vpl");
1678 #else
1679 lastext = -1;
1680 for (i=0; outname[i]; i++)
1681 if (outname[i] == '.')
1682 lastext = i;
1683 else if (outname[i] == '/' || outname[i] == ':')
1684 lastext = -1;
1685 if (lastext == -1) strcat(outname, ".vpl");
1686 #endif
1687 #ifndef VMCMS
1688 #ifndef ATARIST
1689 if ((vplout=fopen(outname, WRITEBIN))==NULL)
1690 #else
1691 if ((vplout=fopen(outname, "w"))==NULL)
1692 #endif
1693 #else
1694 if ((vplout=fopen(outname, "w"))==NULL)
1695 #endif
1696 error("! can't open vpl output file");
1697 break;
1698 case 'a':
1699 noaccentheightadjust = 1;
1700 arginc = 1;
1701 break;
1702 case 'c':
1703 CHECKARG3
1704 if (sscanf(argv[3], "%f", &capheight)==0 || capheight<0.01)
1705 error("! Bad small caps height");
1706 break;
1707 case 'e': CHECKARG3
1708 if (sscanf(argv[3], "%f", &efactor)==0 || efactor<0.01)
1709 error("! Bad extension factor");
1710 efactorparam = argv[3];
1711 break;
1712 case 'O':
1713 forceoctal = 1;
1714 arginc = 1;
1715 break;
1716 case 'P':
1717 case 'p':
1718 CHECKARG3
1719 inenname = argv[3];
1720 break;
1721 case 's':
1722 CHECKARG3
1723 if (sscanf(argv[3], "%f", &slant)==0)
1724 error("! Bad slant parameter");
1725 slantparam = argv[3];
1726 break;
1727 case 'T':
1728 CHECKARG3
1729 inenname = outenname = argv[3];
1730 break;
1731 case 't':
1732 CHECKARG3
1733 outenname = argv[3];
1734 break;
1735 case 'u':
1736 pedantic = 1;
1737 arginc = 1;
1738 break;
1739 default: fprintf(stderr, "Unknown option %s %s ignored.\n", argv[2], argv[3]);
1740 }
1741 for (i=0; i<arginc; i++) {
1742 snprintf(titlebuf + strlen(titlebuf),
1743 sizeof(titlebuf) - strlen(titlebuf), " %s", argv[2]);
1744 argv++;
1745 argc--;
1746 }
1747 }
1748
1749 #ifdef KPATHSEA
1750 afmin = kpse_open_file (inname, kpse_afm_format);
1751 #else /* ! KPATHSEA */
1752 if ((afmin=fopen(inname, "r"))==NULL)
1753 error("! can't open afm input file");
1754 #endif /* KPATHSEA */
1755 SET_BINARY(fileno(afmin));
1756
1757 if (argc>3 || (argc==3 && *argv[2]=='-')) {
1758 error("! need at most two non-option arguments");
1759 usage(stderr);
1760 }
1761
1762 if (argc == 2) strcpy(outname, inname);
1763 else strcpy(outname, argv[2]);
1764
1765 #ifdef KPATHSEA
1766 if ((p = find_suffix(outname)) != NULL)
1767 outname[p-outname-1] = 0;
1768 strcat(outname, ".tfm");
1769 if (tfmout == NULL && (tfmout=fopen(outname, WRITEBIN))==NULL)
1770 error("! can't open tfm output file");
1771 /*
1772 * Now we strip off any directory information, so we only use the
1773 * base name in the vf file.
1774 */
1775 if (p == NULL)
1776 p = find_suffix(outname);
1777 outname[p-outname-1] = 0;
1778
1779 q = xbasename(outname);
1780 strcpy(tmpstr, q); /* be careful, q and outname are overlapping */
1781 strcpy(outname, tmpstr);
1782 #else
1783 lastext = -1;
1784 for (i=0; outname[i]; i++)
1785 if (outname[i] == '.')
1786 lastext = i;
1787 else if (outname[i] == '/' || outname[i] == ':' || outname[i] == '\\')
1788 lastext = -1;
1789 if (argc == 2) {
1790 outname[lastext] = 0;
1791 lastext = -1;
1792 }
1793 if (lastext == -1) {
1794 lastext = strlen(outname);
1795 strcat(outname, ".tfm");
1796 }
1797 if (tfmout == NULL && (tfmout=fopen(outname, WRITEBIN))==NULL)
1798 error("! can't open tfm output file");
1799 outname[lastext] = 0;
1800 /*
1801 * Now we strip off any directory information, so we only use the
1802 * base name in the vf file. We accept any of /, :, or \ as directory
1803 * delimiters, so none of these are available for use inside the
1804 * base name; this shouldn't be a problem.
1805 */
1806 for (i=0, lastext=0; outname[i]; i++)
1807 if (outname[i] == '/' || outname[i] == ':' || outname[i] == '\\')
1808 lastext = i + 1;
1809 if (lastext)
1810 strcpy(outname, outname + lastext);
1811 #endif
1812 }
1813 /*
1814 * Some routines to remove kerns that match certain patterns.
1815 */
1816 static struct kern *
1817 rmkernmatch(struct kern *k, char *s)
1818 {
1819 struct kern *nkern;
1820
1821 while (k && strcmp(k->succ, s)==0)
1822 k = k->next;
1823 if (k) {
1824 for (nkern = k; nkern; nkern = nkern->next)
1825 while (nkern->next && strcmp(nkern->next->succ, s)==0)
1826 nkern->next = nkern->next->next;
1827 }
1828 return k;
1829 }
1830 /*
1831 * Recursive to one level.
1832 */
1833 static void
1834 rmkern(char *s1, char *s2, struct adobeinfo *ai)
1835 {
1836 if (ai == 0) {
1837 if (strcmp(s1, "*") == 0) {
1838 for (ai=adobechars; ai; ai = ai->next)
1839 rmkern(s1, s2, ai);
1840 return;
1841 } else {
1842 ai = findadobe(s1);
1843 if (ai == 0)
1844 return;
1845 }
1846 }
1847 if (strcmp(s2, "*")==0)
1848 ai->kerns = 0; /* drop them on the floor */
1849 else
1850 ai->kerns = rmkernmatch(ai->kerns, s2);
1851 }
1852
1853 /* Make the kerning for character S1 equivalent to that for S2.
1854 If either S1 or S2 do not exist, do nothing.
1855 If S1 already has kerning, do nothing. */
1856 static void
1857 addkern(char *s1, char *s2)
1858 {
1859 struct adobeinfo *ai1 = findadobe (s1);
1860 struct adobeinfo *ai2 = findadobe (s2);
1861 if (ai1 && ai2 && !ai1->kerns) {
1862 /* Put the new one at the head of the list, since order is immaterial. */
1863 struct adobeptr *ap
1864 = (struct adobeptr *) mymalloc((unsigned long)sizeof(struct adobeptr));
1865 ap->next = ai2->kern_equivs;
1866 ap->ch = ai1;
1867 ai2->kern_equivs = ap;
1868 }
1869 }
1870 int sawligkern;
1871 /*
1872 * Reads a ligkern line, if this is one. Assumes the first character
1873 * passed is `%'.
1874 */
1875 static void
1876 checkligkern(char *s)
1877 {
1878 char *oparam = param;
1879 char *mlist[5];
1880 int n;
1881
1882 s++;
1883 while (*s && *s <= ' ')
1884 s++;
1885 if (strncmp(s, "LIGKERN", 7)==0) {
1886 sawligkern = 1;
1887 s += 7;
1888 while (*s && *s <= ' ')
1889 s++;
1890 param = s;
1891 while (*param) {
1892 for (n=0; n<5;) {
1893 if (*param == 0)
1894 break;
1895 mlist[n] = paramstring();
1896 if (strcmp(mlist[n], ";") == 0)
1897 break;
1898 n++;
1899 }
1900 if (n > 4)
1901 error("! too many parameters in lig kern data");
1902 if (n < 3)
1903 error("! too few parameters in lig kern data");
1904 if (n == 3 && strcmp(mlist[1], "{}") == 0) { /* rmkern command */
1905 rmkern(mlist[0], mlist[2], (struct adobeinfo *)0);
1906 } else if (n == 3 && strcmp(mlist[1], "<>") == 0) { /* addkern */
1907 addkern(mlist[0], mlist[2]);
1908 } else if (n == 3 && strcmp(mlist[0], "||") == 0 &&
1909 strcmp(mlist[1], "=") == 0) { /* bc command */
1910 struct adobeinfo *ai = findadobe("||");
1911
1912 if (boundarychar != -1)
1913 error("! multiple boundary character commands?");
1914 if (sscanf(mlist[2], "%d", &n) != 1)
1915 error("! expected number assignment for boundary char");
1916 if (n < 0 || n > 255)
1917 error("! boundary character number must be 0..255");
1918 boundarychar = n;
1919 if (ai == 0)
1920 error("! internal error: boundary char");
1921 ai->texnum = n; /* prime the pump, so to speak, for lig/kerns */
1922 } else if (n == 4) {
1923 int op = -1;
1924 struct adobeinfo *ai;
1925
1926 for (n=0; encligops[n]; n++)
1927 if (strcmp(mlist[2], encligops[n])==0) {
1928 op = n;
1929 break;
1930 }
1931 if (op < 0)
1932 error("! bad ligature op specified");
1933 if (0 != (ai = findadobe(mlist[0]))) {
1934 struct lig *lig;
1935
1936 if (findadobe(mlist[2])) /* remove coincident kerns */
1937 rmkern(mlist[0], mlist[1], ai);
1938 if (strcmp(mlist[3], "||") == 0)
1939 error("! you can't lig to the boundary character!");
1940 if (! fixedpitch) { /* fixed pitch fonts get *0* ligs */
1941 for (lig=ai->ligs; lig; lig = lig->next)
1942 if (strcmp(lig->succ, mlist[1]) == 0)
1943 break; /* we'll re-use this structure */
1944 if (lig == 0) {
1945 lig = newlig();
1946 lig->succ = newstring(mlist[1]);
1947 lig->next = ai->ligs;
1948 ai->ligs = lig;
1949 }
1950 lig->sub = newstring(mlist[3]);
1951 lig->op = op;
1952 if (strcmp(mlist[1], "||")==0) {
1953 lig->boundleft = 1;
1954 if (strcmp(mlist[0], "||")==0)
1955 error("! you can't lig boundarychar boundarychar!");
1956 } else
1957 lig->boundleft = 0;
1958 }
1959 }
1960 } else
1961 error("! bad form in LIGKERN command");
1962 }
1963 }
1964 param = oparam;
1965 }
1966 /*
1967 * Here we get a token from the AFM file. We parse just as much PostScript
1968 * as we expect to find in an encoding file. We allow commented lines and
1969 * names like 0, .notdef, _foo_. We do not allow //abc.
1970 */
1971 char smbuffer[100]; /* for tokens */
1972 static char *
1973 gettoken(void) {
1974 char *p, *q;
1975
1976 while (1) {
1977 while (param == 0 || *param == 0) {
1978 if (texlive_getline() == 0)
1979 error("! premature end in encoding file");
1980 for (p=buffer; *p; p++)
1981 if (*p == '%') {
1982 if (ignoreligkern == 0)
1983 checkligkern(p);
1984 *p = 0;
1985 break;
1986 }
1987 }
1988 while (*param && *param <= ' ')
1989 param++;
1990 if (*param) {
1991 if (*param == '[' || *param == ']' ||
1992 *param == '{' || *param == '}') {
1993 smbuffer[0] = *param++;
1994 smbuffer[1] = 0;
1995 return smbuffer;
1996 } else if (*param == '/' || *param == '-' || *param == '_' ||
1997 *param == '.' ||
1998 ('0' <= *param && *param <= '9') ||
1999 ('a' <= *param && *param <= 'z') ||
2000 ('A' <= *param && *param <= 'Z')) {
2001 smbuffer[0] = *param;
2002 for (p=param+1, q=smbuffer+1;
2003 *p == '-' || *p == '_' || *p == '.' ||
2004 ('0' <= *p && *p <= '9') ||
2005 ('a' <= *p && *p <= 'z') ||
2006 ('A' <= *p && *p <= 'Z'); p++, q++)
2007 *q = *p;
2008 *q = 0;
2009 param = p;
2010 return smbuffer;
2011 }
2012 }
2013 }
2014 }
2015 static void
2016 getligkerndefaults(void) {
2017 int i;
2018
2019 for (i=0; staticligkern[i]; i++) {
2020 strcpy(buffer, staticligkern[i]);
2021 strcpy(obuffer, staticligkern[i]);
2022 param = buffer;
2023 checkligkern(buffer);
2024 }
2025 }
2026 /*
2027 * This routine reads in an encoding file, given the name. It returns
2028 * the final total structure. It performs a number of consistency checks.
2029 */
2030 static struct encoding *
2031 readencoding(char *enc)
2032 {
2033 char *p;
2034 int i;
2035 struct encoding *e =
2036 (struct encoding *)mymalloc((unsigned long)sizeof(struct encoding));
2037
2038 sawligkern = 0;
2039 if (afmin)
2040 error("! oops; internal afmin error");
2041 if (enc) {
2042 #ifdef KPATHSEA
2043 afmin = kpse_open_file(enc, kpse_enc_format);
2044 #else
2045 afmin = fopen(enc, "r");
2046 #endif
2047 SET_BINARY(fileno(afmin));
2048 param = 0;
2049 if (afmin == 0)
2050 #ifdef KPATHSEA
2051 FATAL1 ("couldn't open encoding file `%s'", enc);
2052 #else
2053 error("! couldn't open that encoding file");
2054 #endif
2055 p = gettoken();
2056 if (*p != '/' || p[1] == 0)
2057 error("! first token in encoding must be literal encoding name");
2058 e->name = newstring(p+1);
2059 p = gettoken();
2060 if (strcmp(p, "["))
2061 error("! second token in encoding must be mark ([) token");
2062 for (i=0; i<256; i++) {
2063 p = gettoken();
2064 if (*p != '/' || p[1] == 0)
2065 error("! tokens 3 to 257 in encoding must be literal names");
2066 e->vec[i] = newstring(p+1);
2067 }
2068 p = gettoken();
2069 if (strcmp(p, "]"))
2070 error("! token 258 in encoding must be make-array (])");
2071 while (texlive_getline()) {
2072 for (p=buffer; *p; p++)
2073 if (*p == '%') {
2074 if (ignoreligkern == 0)
2075 checkligkern(p);
2076 *p = 0;
2077 break;
2078 }
2079 }
2080 fclose(afmin);
2081 afmin = 0;
2082 if (ignoreligkern == 0 && sawligkern == 0)
2083 getligkerndefaults();
2084 } else {
2085 e = &staticencoding;
2086 getligkerndefaults();
2087 }
2088 param = 0;
2089 return e;
2090 }
2091 /*
2092 * This routine prints out the line that needs to be added to psfonts.map.
2093 */
2094 static void
2095 conspsfonts(void) {
2096 #ifndef VMCMS
2097 printf("%s %s", outname,
2098 fontname);
2099 #else /* VM/CMS: fontname is ascii, so we use ebfontname */
2100 printf("%s %s", outname,
2101 ebfontname);
2102 #endif
2103 if (slantparam || efactorparam || inenname) {
2104 printf(" \"");
2105 if (slantparam)
2106 printf(" %s SlantFont", slantparam);
2107 if (efactorparam)
2108 printf(" %s ExtendFont", efactorparam);
2109 if (inenname)
2110 printf(" %s ReEncodeFont", inencoding->name);
2111 printf(" \"");
2112 if (inenname)
2113 printf(" <%s", inenname);
2114 }
2115 printf("\n");
2116 }
2117 #ifndef VMS
2118 int
2119 #endif
2120 main(int argc, char **argv)
2121 {
2122 int i;
2123
2124 #ifdef KPATHSEA
2125 kpse_set_program_name (argv[0], "afm2tfm");
2126
2127 if (argc == 1) {
2128 fputs ("afm2tfm: Need at least one file argument.\n", stderr);
2129 fputs ("Try `afm2tfm --help' for more information.\n", stderr);
2130 exit(1);
2131 }
2132 if (argc == 2) {
2133 if (strcmp (argv[1], "--help") == 0) {
2134 usage (stdout);
2135 exit (0);
2136 } else if (strcmp (argv[1], "--version") == 0) {
2137 version (stdout);
2138 exit (0);
2139 }
2140 }
2141 #endif /* KPATHSEA */
2142 for (i=0; i<256; i++)
2143 nexttex[i] = -1; /* encoding chains have length 0 */
2144 tfmdata = (long *)mymalloc((unsigned long)40000L);
2145 openfiles(argc, argv);
2146 readadobe();
2147 if (fontspace == 0) {
2148 struct adobeinfo *ai;
2149
2150 if (0 != (ai = findadobe("space")))
2151 fontspace = ai->width;
2152 else if (adobeptrs[32])
2153 fontspace = adobeptrs[32]->width;
2154 else
2155 fontspace = transform(500, 0);
2156 }
2157 handlereencoding();
2158 buildtfm();
2159 writetfm();
2160 conspsfonts();
2161 if (makevpl) {
2162 assignchars();
2163 if (makevpl>1) upmap();
2164 writevpl();
2165 }
2166 return 0;
2167 /*NOTREACHED*/
2168 }
2169