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 char *afm_charfield(char *s
, char *d
)
20 while (*s
&& !isspace(*s
) && *s
!= ';')
22 while (isspace(*s
) || *s
== ';')
28 static int afm_read(void)
31 char ch
[TOKLEN
] = "", pos
[TOKLEN
] = "";
32 char c1
[TOKLEN
] = "", c2
[TOKLEN
] = "";
33 char wid
[TOKLEN
] = "", field
[TOKLEN
] = "";
34 char llx
[TOKLEN
] = "0", lly
[TOKLEN
] = "0";
35 char urx
[TOKLEN
] = "0", ury
[TOKLEN
] = "0";
37 while (fgets(ln
, sizeof(ln
), stdin
)) {
40 if (!strncmp("FontName ", ln
, 8)) {
41 sscanf(ln
, "FontName %s", ch
);
45 if (!strncmp("StartCharMetrics", ln
, 16))
48 while (fgets(ln
, sizeof(ln
), stdin
)) {
51 if (!strncmp("EndCharMetrics", ln
, 14))
55 s
= afm_charfield(s
, field
);
56 if (!strcmp("C", field
)) {
57 s
= afm_charfield(s
, pos
);
60 if (!strcmp("WX", field
)) {
61 s
= afm_charfield(s
, wid
);
64 if (!strcmp("N", field
)) {
65 s
= afm_charfield(s
, ch
);
68 if (!strcmp("B", field
)) {
69 s
= afm_charfield(s
, llx
);
70 s
= afm_charfield(s
, lly
);
71 s
= afm_charfield(s
, urx
);
72 s
= afm_charfield(s
, ury
);
75 if (!strcmp("L", field
)) {
76 s
= afm_charfield(s
, c1
);
77 s
= afm_charfield(s
, c2
);
82 if (ch
[0] && pos
[0] && wid
[0])
83 trfn_char(ch
, atoi(pos
), 0, atoi(wid
),
84 atoi(llx
), atoi(lly
), atoi(urx
), atoi(ury
));
86 while (fgets(ln
, sizeof(ln
), stdin
)) {
89 if (!strncmp("StartKernPairs", ln
, 14))
92 while (fgets(ln
, sizeof(ln
), stdin
)) {
95 if (!strncmp("EndKernPairs", ln
, 12))
97 if (sscanf(ln
, "KPX %s %s %s", c1
, c2
, wid
) == 3)
98 trfn_kern(c1
, c2
, atoi(wid
));
104 void otf_feat(int res
, int kmin
);
107 "Usage: mktrfn [options] <input >output\n"
109 " -a \tread an AFM file (default)\n"
110 " -o \tread an OTF file\n"
111 " -s \tspecial font\n"
112 " -p name \toverride font postscript name\n"
113 " -t name \tset font troff name\n"
114 " -r res \tset device resolution (720)\n"
115 " -k kmin \tspecify the minimum amount of kerning (0)\n"
116 " -b \tinclude glyph bounding box\n";
118 int main(int argc
, char *argv
[])
126 for (i
= 1; i
< argc
&& argv
[i
][0] == '-'; i
++) {
127 switch (argv
[i
][1]) {
132 kmin
= atoi(argv
[i
][2] ? argv
[i
] + 2 : argv
[++i
]);
138 trfn_psfont(argv
[i
][2] ? argv
[i
] + 2 : argv
[++i
]);
141 res
= atoi(argv
[i
][2] ? argv
[i
] + 2 : argv
[++i
]);
147 trfn_trfont(argv
[i
][2] ? argv
[i
] + 2 : argv
[++i
]);
157 trfn_init(res
, spc
, kmin
, bbox
);