trfn_ch.h: fix ws digraph mapping
[neatmkfn.git] / afm.c
blob53aa34c5a08c0460400f489a508a70060486a831
1 /* AFM fonts */
2 #include <ctype.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include "mkfn.h"
8 #define TOKLEN 256
10 static char *afm_charfield(char *s, char *d)
12 while (*s && !isspace(*s) && *s != ';')
13 *d++ = *s++;
14 while (isspace(*s) || *s == ';')
15 s++;
16 *d = '\0';
17 return s;
20 static int uwid(int w)
22 long div = 72000 / mkfn_res;
23 return (w < 0 ? w - div / 20 : w + div / 20) * (long) 10 / div;
25 int afm_read(void)
27 char ln[1024];
28 char ch[TOKLEN] = "", pos[TOKLEN] = "";
29 char c1[TOKLEN] = "", c2[TOKLEN] = "";
30 char wid[TOKLEN] = "", field[TOKLEN] = "";
31 char llx[TOKLEN] = "0", lly[TOKLEN] = "0";
32 char urx[TOKLEN] = "0", ury[TOKLEN] = "0";
33 char fontname[128];
34 char *s;
35 while (fgets(ln, sizeof(ln), stdin)) {
36 if (ln[0] == '#')
37 continue;
38 if (!strncmp("FontName ", ln, 8)) {
39 sscanf(ln, "FontName %s", fontname);
40 continue;
42 if (!strncmp("StartCharMetrics", ln, 16))
43 break;
45 while (fgets(ln, sizeof(ln), stdin)) {
46 if (ln[0] == '#')
47 continue;
48 if (!strncmp("EndCharMetrics", ln, 14))
49 break;
50 s = ln;
51 while (*s) {
52 s = afm_charfield(s, field);
53 if (!strcmp("C", field)) {
54 s = afm_charfield(s, pos);
55 continue;
57 if (!strcmp("WX", field)) {
58 s = afm_charfield(s, wid);
59 continue;
61 if (!strcmp("N", field)) {
62 s = afm_charfield(s, ch);
63 continue;
65 if (!strcmp("B", field)) {
66 s = afm_charfield(s, llx);
67 s = afm_charfield(s, lly);
68 s = afm_charfield(s, urx);
69 s = afm_charfield(s, ury);
70 continue;
72 if (!strcmp("L", field)) {
73 s = afm_charfield(s, c1);
74 s = afm_charfield(s, c2);
75 continue;
77 break;
79 if (ch[0] && pos[0] && wid[0])
80 mkfn_char(ch, atoi(pos), 0, uwid(atoi(wid)),
81 uwid(atoi(llx)), uwid(atoi(lly)),
82 uwid(atoi(urx)), uwid(atoi(ury)));
84 mkfn_header(fontname);
85 while (fgets(ln, sizeof(ln), stdin)) {
86 if (ln[0] == '#')
87 continue;
88 if (!strncmp("StartKernPairs", ln, 14))
89 break;
91 while (fgets(ln, sizeof(ln), stdin)) {
92 if (ln[0] == '#')
93 continue;
94 if (!strncmp("EndKernPairs", ln, 12))
95 break;
96 if (sscanf(ln, "KPX %s %s %s", c1, c2, wid) == 3)
97 mkfn_kern(c1, c2, uwid(atoi(wid)));
99 return 0;