otf: for each rule report its script
[neatmkfn.git] / afm.c
blob50f6e084d9ae80eaf389940e5210b137dbfd3a54
1 #include <ctype.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include "trfn.h"
7 #define TOKLEN 256
9 static char *afm_charfield(char *s, char *d)
11 while (*s && !isspace(*s) && *s != ';')
12 *d++ = *s++;
13 while (isspace(*s) || *s == ';')
14 s++;
15 *d = '\0';
16 return s;
19 int afm_read(void)
21 char ln[1024];
22 char ch[TOKLEN] = "", pos[TOKLEN] = "";
23 char c1[TOKLEN] = "", c2[TOKLEN] = "";
24 char wid[TOKLEN] = "", field[TOKLEN] = "";
25 char llx[TOKLEN] = "0", lly[TOKLEN] = "0";
26 char urx[TOKLEN] = "0", ury[TOKLEN] = "0";
27 char *s;
28 while (fgets(ln, sizeof(ln), stdin)) {
29 if (ln[0] == '#')
30 continue;
31 if (!strncmp("FontName ", ln, 8)) {
32 sscanf(ln, "FontName %s", ch);
33 trfn_psfont(ch);
34 continue;
36 if (!strncmp("StartCharMetrics", ln, 16))
37 break;
39 while (fgets(ln, sizeof(ln), stdin)) {
40 if (ln[0] == '#')
41 continue;
42 if (!strncmp("EndCharMetrics", ln, 14))
43 break;
44 s = ln;
45 while (*s) {
46 s = afm_charfield(s, field);
47 if (!strcmp("C", field)) {
48 s = afm_charfield(s, pos);
49 continue;
51 if (!strcmp("WX", field)) {
52 s = afm_charfield(s, wid);
53 continue;
55 if (!strcmp("N", field)) {
56 s = afm_charfield(s, ch);
57 continue;
59 if (!strcmp("B", field)) {
60 s = afm_charfield(s, llx);
61 s = afm_charfield(s, lly);
62 s = afm_charfield(s, urx);
63 s = afm_charfield(s, ury);
64 continue;
66 if (!strcmp("L", field)) {
67 s = afm_charfield(s, c1);
68 s = afm_charfield(s, c2);
69 continue;
71 break;
73 if (ch[0] && pos[0] && wid[0])
74 trfn_char(ch, atoi(pos), 0, atoi(wid),
75 atoi(llx), atoi(lly), atoi(urx), atoi(ury));
77 while (fgets(ln, sizeof(ln), stdin)) {
78 if (ln[0] == '#')
79 continue;
80 if (!strncmp("StartKernPairs", ln, 14))
81 break;
83 while (fgets(ln, sizeof(ln), stdin)) {
84 if (ln[0] == '#')
85 continue;
86 if (!strncmp("EndKernPairs", ln, 12))
87 break;
88 if (sscanf(ln, "KPX %s %s %s", c1, c2, wid) == 3)
89 trfn_kern(c1, c2, atoi(wid));
91 return 0;