2 * mktrfn - produce troff font descriptions
4 * Copyright (C) 2012-2014 Ali Gholami Rudi <ali at rudi dot ir>
6 * This program is released under the Modified BSD license.
18 static void otfdump_read(void)
23 char c1
[TOKLEN
], c2
[TOKLEN
];
25 while (scanf("%s", cmd
) == 1) {
26 if (!strcmp("name", cmd
)) {
30 if (!strcmp("char", cmd
)) {
31 scanf("%s width %s", ch
, wid
);
32 trfn_char(ch
, NULL
, atoi(wid
), 0, 0, 0, 0);
34 if (!strcmp("kernpair", cmd
)) {
35 scanf("%s %s width %s", c1
, c2
, wid
);
36 trfn_kern(c1
, c2
, atoi(wid
));
38 if (!strcmp("feature", cmd
)) {
39 scanf("%s substitution %s %s", name
, c1
, c2
);
45 static char *afm_charfield(char *s
, char *d
)
47 while (*s
&& !isspace(*s
) && *s
!= ';')
49 while (isspace(*s
) || *s
== ';')
55 static void afm_read(void)
58 char ch
[TOKLEN
] = "", pos
[TOKLEN
] = "";
59 char c1
[TOKLEN
] = "", c2
[TOKLEN
] = "";
60 char wid
[TOKLEN
] = "", field
[TOKLEN
] = "";
61 char llx
[TOKLEN
] = "0", lly
[TOKLEN
] = "0";
62 char urx
[TOKLEN
] = "0", ury
[TOKLEN
] = "0";
64 while (fgets(ln
, sizeof(ln
), stdin
)) {
67 if (!strncmp("FontName ", ln
, 8)) {
68 sscanf(ln
, "FontName %s", ch
);
72 if (!strncmp("StartCharMetrics", ln
, 16))
75 while (fgets(ln
, sizeof(ln
), stdin
)) {
78 if (!strncmp("EndCharMetrics", ln
, 14))
82 s
= afm_charfield(s
, field
);
83 if (!strcmp("C", field
)) {
84 s
= afm_charfield(s
, pos
);
87 if (!strcmp("WX", field
)) {
88 s
= afm_charfield(s
, wid
);
91 if (!strcmp("N", field
)) {
92 s
= afm_charfield(s
, ch
);
95 if (!strcmp("B", field
)) {
96 s
= afm_charfield(s
, llx
);
97 s
= afm_charfield(s
, lly
);
98 s
= afm_charfield(s
, urx
);
99 s
= afm_charfield(s
, ury
);
102 if (!strcmp("L", field
)) {
103 s
= afm_charfield(s
, c1
);
104 s
= afm_charfield(s
, c2
);
109 if (ch
[0] && pos
[0] && wid
[0])
110 trfn_char(ch
, pos
, atoi(wid
),
111 atoi(llx
), atoi(lly
), atoi(urx
), atoi(ury
));
113 while (fgets(ln
, sizeof(ln
), stdin
)) {
116 if (!strncmp("StartKernPairs", ln
, 14))
119 while (fgets(ln
, sizeof(ln
), stdin
)) {
122 if (!strncmp("EndKernPairs", ln
, 12))
124 if (sscanf(ln
, "KPX %s %s %s", c1
, c2
, wid
) == 3)
125 trfn_kern(c1
, c2
, atoi(wid
));
130 "Usage: mktrfn [options] <input >output\n"
132 " -a \tread an AFM file (default)\n"
133 " -o \tread the output of otfdump\n"
134 " -s \tspecial font\n"
135 " -p name \toverride font postscript name\n"
136 " -t name \tset font troff name\n"
137 " -r res \tset device resolution (720)\n"
138 " -k kmin \tspecify the minimum amount of kerning (0)\n"
139 " -b \tinclude glyph bounding box\n";
141 int main(int argc
, char *argv
[])
149 for (i
= 1; i
< argc
&& argv
[i
][0] == '-'; i
++) {
150 switch (argv
[i
][1]) {
155 kmin
= atoi(argv
[i
][2] ? argv
[i
] + 2 : argv
[++i
]);
161 trfn_psfont(argv
[i
][2] ? argv
[i
] + 2 : argv
[++i
]);
164 res
= atoi(argv
[i
][2] ? argv
[i
] + 2 : argv
[++i
]);
170 trfn_trfont(argv
[i
][2] ? argv
[i
] + 2 : argv
[++i
]);
180 trfn_init(res
, spc
, kmin
, bbox
);