ref: 4802c9e118575b0779009b2a8eb258f68bd45a69
parent: eafe97d58c0d49a7fb74d222f88cbfaf47e8b474
author: Ali Gholami Rudi <ali@rudi.ir>
date: Mon Aug 4 06:23:53 EDT 2014
mkfn: filter the scripts and languages to include
--- a/mkfn.c
+++ b/mkfn.c
@@ -15,6 +15,9 @@
#define TOKLEN 256
+static char *trfn_scripts; /* filtered scripts */
+static char *trfn_langs; /* filtered languages */
+
static char *afm_charfield(char *s, char *d)
{
while (*s && !isspace(*s) && *s != ';')
@@ -100,6 +103,33 @@
return 0;
}
+/* return 1 if script script is to be included */
+int trfn_script(char *script, int nscripts)
+{
+ if (!trfn_scripts)
+ return nscripts == 1 || !script ||
+ !strcmp("DFLT", script) || !strcmp("latn", script);
+ if (!strcmp("help", trfn_scripts))
+ fprintf(stderr, "script: %s\n", script ? script : "");
+ if (strchr(script, ' '))
+ *strchr(script, ' ') = '\0';
+ return !!strstr(trfn_scripts, script);
+}
+
+/* return 1 if language lang is to be included */
+int trfn_lang(char *lang, int nlangs)
+{
+ if (!trfn_langs)
+ return nlangs == 1 || !lang;
+ if (!lang)
+ lang = "";
+ if (!strcmp("help", trfn_langs))
+ fprintf(stderr, "lang: %s\n", lang);
+ if (strchr(lang, ' '))
+ *strchr(lang, ' ') = '\0';
+ return !!strstr(trfn_langs, lang);
+}
+
int otf_read(void);
void otf_feat(int res, int kmin);
@@ -113,7 +143,9 @@
" -t name \tset font troff name\n"
" -r res \tset device resolution (720)\n"
" -k kmin \tspecify the minimum amount of kerning (0)\n"
- " -b \tinclude glyph bounding box\n";
+ " -b \tinclude glyph bounding boxes\n"
+ " -S scrs \tcomma-separated list of scripts to include (help to list)\n"
+ " -L langs\tcomma-separated list of languages to include (help to list)\n";
int main(int argc, char *argv[])
{
@@ -131,6 +163,9 @@
case 'k':
kmin = atoi(argv[i][2] ? argv[i] + 2 : argv[++i]);
break;
+ case 'L':
+ trfn_langs = argv[i][2] ? argv[i] + 2 : argv[++i];
+ break;
case 'o':
afm = 0;
break;
@@ -142,6 +177,9 @@
break;
case 's':
spc = 1;
+ break;
+ case 'S':
+ trfn_scripts = argv[i][2] ? argv[i] + 2 : argv[++i];
break;
case 't':
trfn_trfont(argv[i][2] ? argv[i] + 2 : argv[++i]);
--- a/otf.c
+++ b/otf.c
@@ -451,18 +451,27 @@
void *scripts = gpos + U16(gpos, 4);
int nscripts, nlangs;
void *script;
- void *grec;
+ void *grec, *lrec;
+ char tag[8];
int i, j;
nscripts = U16(scripts, 0);
for (i = 0; i < nscripts; i++) {
grec = scripts + 2 + 6 * i;
+ memcpy(tag, grec, 4);
+ tag[4] = '\0';
+ if (!trfn_script(tag, nscripts))
+ continue;
script = scripts + U16(grec, 4);
- if (U16(script, 0))
- otf_gposlang(otf, gpos, script + U16(script, 0));
nlangs = U16(script, 2);
- for (j = 0; j < nlangs; j++)
- otf_gposlang(otf, gpos, script +
- U16(script, 4 + 6 * j + 4));
+ if (U16(script, 0) && trfn_lang(NULL, nlangs + (U16(script, 0) != 0)))
+ otf_gposlang(otf, gpos, script + U16(script, 0));
+ for (j = 0; j < nlangs; j++) {
+ lrec = script + 4 + 6 * j;
+ memcpy(tag, lrec, 4);
+ tag[4] = '\0';
+ if (trfn_lang(tag, nlangs + (U16(script, 0) != 0)))
+ otf_gposlang(otf, gpos, script + U16(lrec, 4));
+ }
}
}
@@ -577,16 +586,27 @@
void *scripts = gsub + U16(gsub, 4);
int nscripts, nlangs;
void *script;
+ void *grec, *lrec;
+ char tag[8];
int i, j;
nscripts = U16(scripts, 0);
for (i = 0; i < nscripts; i++) {
+ grec = scripts + 2 + 6 * i;
+ memcpy(tag, grec, 4);
+ tag[4] = '\0';
+ if (!trfn_script(tag, nscripts))
+ continue;
script = scripts + U16(scripts + 2 + 6 * i, 4);
nlangs = U16(script, 2);
- if (U16(script, 0))
+ if (U16(script, 0) && trfn_lang(NULL, nlangs + (U16(script, 0) != 0)))
otf_gsublang(otf, gsub, script + U16(script, 0));
- for (j = 0; j < nlangs; j++)
- otf_gsublang(otf, gsub, script +
- U16(script, 4 + 6 * j + 4));
+ for (j = 0; j < nlangs; j++) {
+ lrec = script + 4 + 6 * j;
+ memcpy(tag, lrec, 4);
+ tag[4] = '\0';
+ if (trfn_lang(tag, nlangs + (U16(script, 0) != 0)))
+ otf_gsublang(otf, gsub, script + U16(lrec, 4));
+ }
}
}
--- a/trfn.h
+++ b/trfn.h
@@ -5,3 +5,5 @@
void trfn_print(void);
void trfn_char(char *c, int n, int u, int wid, int llx, int lly, int urx, int ury);
void trfn_kern(char *c1, char *c2, int x);
+int trfn_script(char *script, int nscripts);
+int trfn_lang(char *lang, int nlangs);