otf: otf file support
[neatmkfn.git] / mkfn.c
blob395b0c3d72aa4af5caf2b6465d4313b603167ed6
1 /*
2 * NEATMKFN - GENERATE NEATROFF FONT DESCRIPTIONS
4 * Copyright (C) 2012-2016 Ali Gholami Rudi <ali at rudi dot ir>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <stdio.h>
19 #include <string.h>
20 #include <stdlib.h>
21 #include "trfn.h"
23 #define LEN(a) ((sizeof(a) / sizeof((a)[0])))
25 static char *trfn_scripts; /* filtered scripts */
26 static char *trfn_langs; /* filtered languages */
28 /* OpenType specifies a specific feature order for different scripts */
29 static char *scriptorder[][2] = {
30 {"latn", "ccmp,liga,clig,dist,kern,mark,mkmk"},
31 {"cyrl", "ccmp,liga,clig,dist,kern,mark,mkmk"},
32 {"grek", "ccmp,liga,clig,dist,kern,mark,mkmk"},
33 {"armn", "ccmp,liga,clig,dist,kern,mark,mkmk"},
34 {"geor", "ccmp,liga,clig,dist,kern,mark,mkmk"},
35 {"runr", "ccmp,liga,clig,dist,kern,mark,mkmk"},
36 {"ogam", "ccmp,liga,clig,dist,kern,mark,mkmk"},
37 {"arab", "ccmp,isol,fina,medi,init,rlig,calt,liga,dlig,cswh,mset,curs,kern,mark,mkmk"},
38 {"bugi", "locl,ccmp,rlig,liga,clig,calt,kern,dist,mark,mkmk"},
39 {"hang", "ccmp,ljmo,vjmo,tjmo"},
40 {"hebr", "ccmp,dlig,kern,mark"},
41 {"bng2", "locl,nukt,akhn,rphf,blwf,half,pstf,vatu,cjct,init,pres,abvs,blws,psts,haln,calt,kern,dist,abvm,blwm"},
42 {"dev2", "locl,nukt,akhn,rphf,blwf,half,pstf,vatu,cjct,init,pres,abvs,blws,psts,haln,calt,kern,dist,abvm,blwm"},
43 {"gjr2", "locl,nukt,akhn,rphf,blwf,half,pstf,vatu,cjct,init,pres,abvs,blws,psts,haln,calt,kern,dist,abvm,blwm"},
44 {"gur2", "locl,nukt,akhn,rphf,blwf,half,pstf,vatu,cjct,init,pres,abvs,blws,psts,haln,calt,kern,dist,abvm,blwm"},
45 {"knd2", "locl,nukt,akhn,rphf,blwf,half,pstf,vatu,cjct,init,pres,abvs,blws,psts,haln,calt,kern,dist,abvm,blwm"},
46 {"mlym", "locl,nukt,akhn,rphf,blwf,half,pstf,vatu,cjct,init,pres,abvs,blws,psts,haln,calt,kern,dist,abvm,blwm"},
47 {"ory2", "locl,nukt,akhn,rphf,blwf,half,pstf,vatu,cjct,init,pres,abvs,blws,psts,haln,calt,kern,dist,abvm,blwm"},
48 {"tml2", "locl,nukt,akhn,rphf,blwf,half,pstf,vatu,cjct,init,pres,abvs,blws,psts,haln,calt,kern,dist,abvm,blwm"},
49 {"tml2", "locl,nukt,akhn,rphf,blwf,half,pstf,vatu,cjct,init,pres,abvs,blws,psts,haln,calt,kern,dist,abvm,blwm"},
50 {"telu", "locl,nukt,akhn,rphf,blwf,half,pstf,vatu,cjct,init,pres,abvs,blws,psts,haln,calt,kern,dist,abvm,blwm"},
51 {"java", "locl,pref,abvf,blwf,pstf,pres,abvs,blws,psts,ccmp,rlig,liga,clig,calt,kern,dist,mark,mkmk"},
52 {"khmr", "pref,blwf,abvf,pstf,pres,blws,abvs,psts,clig,dist,blwm,abvm,mkmk"},
53 {"lao ", "ccmp,kern,mark,mkmk"},
54 {"mym2", "locl,rphf,pref,blwf,pstf,pres,abvs,blws,psts,kern,dist,mark,mkmk"},
55 {"sinh", "locl,ccmp,akhn,rphf,vatu,pstf,pres,abvs,blws,psts,kern,dist,abvm,blwm"},
56 {"syrc", "stch,ccmp,isol,fina,fin2,fin3,medi,med2,init,rlig,calt,liga,dlig,kern,mark,mkmk"},
57 {"thaa", "kern,mark"},
58 {"thai", "ccmp,kern,mark,mkmk"},
59 {"tibt", "ccmp,abvs,blws,calt,liga,kern,abvm,blwm,mkmk"},
62 /* return 1 if the given script is to be included */
63 int trfn_script(char *script, int nscripts)
65 /* fill trfn_scripts (if unspecified) in the first call */
66 if (!trfn_scripts) {
67 if (nscripts == 1 || !script)
68 return 1;
69 if (!strcmp("DFLT", script))
70 trfn_scripts = "DFLT";
71 else
72 trfn_scripts = "latn";
74 if (!strcmp("help", trfn_scripts))
75 fprintf(stderr, "script: %s\n", script ? script : "");
76 if (strchr(script, ' '))
77 *strchr(script, ' ') = '\0';
78 return !!strstr(trfn_scripts, script);
81 /* return 1 if the given language is to be included */
82 int trfn_lang(char *lang, int nlangs)
84 if (!trfn_langs)
85 return nlangs == 1 || !lang;
86 if (!lang)
87 lang = "";
88 if (!strcmp("help", trfn_langs))
89 fprintf(stderr, "lang: %s\n", lang);
90 if (strchr(lang, ' '))
91 *strchr(lang, ' ') = '\0';
92 return !!strstr(trfn_langs, lang);
95 /* return the rank of the given feature, for the current script */
96 int trfn_featrank(char *scrp, char *feat)
98 static char **order;
99 int i;
100 if (!order || strcmp(scrp, order[0])) {
101 order = NULL;
102 for (i = 0; i < LEN(scriptorder); i++)
103 if (!strcmp(scrp, scriptorder[i][0]))
104 order = scriptorder[i];
106 if (order && strstr(order[1], feat))
107 return strstr(order[1], feat) - order[1];
108 return 1000;
111 int otf_read(void);
112 int afm_read(void);
113 void otf_feat(int res, int kmin, int warn);
115 static char *usage =
116 "Usage: mktrfn [options] <input >output\n"
117 "Options:\n"
118 " -a \tread an AFM file (default)\n"
119 " -o \tread an OTF file\n"
120 " -s \tspecial font\n"
121 " -p name \toverride font postscript name\n"
122 " -t name \tset font troff name\n"
123 " -r res \tset device resolution (720)\n"
124 " -k kmin \tspecify the minimum amount of kerning (0)\n"
125 " -b \tinclude glyph bounding boxes\n"
126 " -l \tsuppress the ligatures line\n"
127 " -n \tsuppress glyph positions\n"
128 " -S scrs \tcomma-separated list of scripts to include (help to list)\n"
129 " -L langs\tcomma-separated list of languages to include (help to list)\n"
130 " -w \twarn about unsupported font features\n";
132 int main(int argc, char *argv[])
134 int afm = 1;
135 int res = 720;
136 int spc = 0;
137 int kmin = 0;
138 int bbox = 0;
139 int warn = 0;
140 int ligs = 1;
141 int pos = 1;
142 int i;
143 for (i = 1; i < argc && argv[i][0] == '-'; i++) {
144 switch (argv[i][1]) {
145 case 'a':
146 afm = 1;
147 break;
148 case 'b':
149 bbox = 1;
150 break;
151 case 'k':
152 kmin = atoi(argv[i][2] ? argv[i] + 2 : argv[++i]);
153 break;
154 case 'l':
155 ligs = 0;
156 break;
157 case 'L':
158 trfn_langs = argv[i][2] ? argv[i] + 2 : argv[++i];
159 break;
160 case 'n':
161 pos = 0;
162 break;
163 case 'o':
164 afm = 0;
165 break;
166 case 'p':
167 trfn_psfont(argv[i][2] ? argv[i] + 2 : argv[++i]);
168 break;
169 case 'r':
170 res = atoi(argv[i][2] ? argv[i] + 2 : argv[++i]);
171 break;
172 case 's':
173 spc = 1;
174 break;
175 case 'S':
176 trfn_scripts = argv[i][2] ? argv[i] + 2 : argv[++i];
177 break;
178 case 't':
179 trfn_trfont(argv[i][2] ? argv[i] + 2 : argv[++i]);
180 break;
181 case 'w':
182 warn = 1;
183 break;
184 default:
185 printf("%s", usage);
186 return 0;
189 trfn_init(res, spc, kmin, bbox, ligs, pos);
190 if (afm)
191 afm_read();
192 else
193 otf_read();
194 trfn_print();
195 if (!afm)
196 otf_feat(res, kmin, warn);
197 trfn_done();
198 return 0;