gen.sh: pass font path to mkfn
[neatmkfn.git] / mkfn.c
blobb63e7d1aacf2e619cc485b41792c92514fb6f49f
1 /*
2 * NEATMKFN - GENERATE NEATROFF FONT DESCRIPTIONS
4 * Copyright (C) 2012-2018 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 1;
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 " -f path \tset font path\n"
124 " -r res \tset device resolution (720)\n"
125 " -k kmin \tspecify the minimum amount of kerning (0)\n"
126 " -b \tinclude glyph bounding boxes\n"
127 " -l \tsuppress the ligatures line\n"
128 " -n \tsuppress glyph positions\n"
129 " -S scrs \tcomma-separated list of scripts to include (help to list)\n"
130 " -L langs\tcomma-separated list of languages to include (help to list)\n"
131 " -w \twarn about unsupported font features\n";
133 int main(int argc, char *argv[])
135 int afm = 1;
136 int res = 720;
137 int spc = 0;
138 int kmin = 0;
139 int bbox = 0;
140 int warn = 0;
141 int ligs = 1;
142 int pos = 1;
143 int i;
144 for (i = 1; i < argc && argv[i][0] == '-'; i++) {
145 switch (argv[i][1]) {
146 case 'a':
147 afm = 1;
148 break;
149 case 'b':
150 bbox = 1;
151 break;
152 case 'f':
153 trfn_pspath(argv[i][2] ? argv[i] + 2 : argv[++i]);
154 break;
155 case 'k':
156 kmin = atoi(argv[i][2] ? argv[i] + 2 : argv[++i]);
157 break;
158 case 'l':
159 ligs = 0;
160 break;
161 case 'L':
162 trfn_langs = argv[i][2] ? argv[i] + 2 : argv[++i];
163 break;
164 case 'n':
165 pos = 0;
166 break;
167 case 'o':
168 afm = 0;
169 break;
170 case 'p':
171 trfn_psfont(argv[i][2] ? argv[i] + 2 : argv[++i]);
172 break;
173 case 'r':
174 res = atoi(argv[i][2] ? argv[i] + 2 : argv[++i]);
175 break;
176 case 's':
177 spc = 1;
178 break;
179 case 'S':
180 trfn_scripts = argv[i][2] ? argv[i] + 2 : argv[++i];
181 break;
182 case 't':
183 trfn_trfont(argv[i][2] ? argv[i] + 2 : argv[++i]);
184 break;
185 case 'w':
186 warn = 1;
187 break;
188 default:
189 printf("%s", usage);
190 return 0;
193 trfn_init(res, spc, kmin, bbox, ligs, pos);
194 if (afm)
195 afm_read();
196 else
197 otf_read();
198 trfn_print();
199 if (!afm)
200 otf_feat(res, kmin, warn);
201 trfn_done();
202 return 0;