summaryrefslogtreecommitdiffstats
path: root/lib/silfont/scripts/psfdeflang.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-03-02 20:01:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-03-02 20:01:10 +0000
commitda875fcb62c801b8d19b3d4d984ad963574fb356 (patch)
tree3d85503747c56c2a387b291524442946f4bebb73 /lib/silfont/scripts/psfdeflang.py
parentInitial commit. (diff)
downloadpysilfont-upstream/1.6.0.tar.xz
pysilfont-upstream/1.6.0.zip
Adding upstream version 1.6.0.upstream/1.6.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/silfont/scripts/psfdeflang.py')
-rwxr-xr-xlib/silfont/scripts/psfdeflang.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/silfont/scripts/psfdeflang.py b/lib/silfont/scripts/psfdeflang.py
new file mode 100755
index 0000000..3a1ac26
--- /dev/null
+++ b/lib/silfont/scripts/psfdeflang.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+__doc__ = '''Switch default language in a font'''
+__url__ = 'http://github.com/silnrsi/pysilfont'
+__copyright__ = 'Copyright (c) 2019 SIL International (http://www.sil.org)'
+__license__ = 'Released under the MIT License (http://opensource.org/licenses/MIT)'
+__author__ = 'Martin Hosken'
+
+from silfont.core import execute
+
+argspec = [
+ ('ifont',{'help': 'Input TTF'}, {'type': 'infont'}),
+ ('ofont',{'help': 'Output TTF','nargs': '?' }, {'type': 'outfont'}),
+ ('-L','--lang', {'help': 'Language to switch to'}, {}),
+ ('-l','--log',{'help': 'Optional log file'}, {'type': 'outfile', 'def': '_deflang.log', 'optlog': True}),
+]
+
+def long2tag(x):
+ res = []
+ while x:
+ res.append(chr(x & 0xFF))
+ x >>= 8
+ return "".join(reversed(res))
+
+def doit(args):
+ infont = args.ifont
+ ltag = args.lang.lower()
+ if 'Sill' in infont and 'Feat' in infont:
+ if ltag in infont['Sill'].langs:
+ changes = dict((long2tag(x[0]), x[1]) for x in infont['Sill'].langs[ltag])
+ for g, f in infont['Feat'].features.items():
+ if g in changes:
+ f.default = changes[g]
+ otltag = ltag + (" " * (4 - len(ltag)))
+ for k in ('GSUB', 'GPOS'):
+ try:
+ t = infont[k].table
+ except KeyError:
+ continue
+ for srec in t.ScriptList.ScriptRecord:
+ for lrec in srec.Script.LangSysRecord:
+ if lrec.LangSysTag.lower() == otltag:
+ srec.Script.DefaultLangSys = lrec.LangSys
+ return infont
+
+def cmd() : execute('FT', doit, argspec)
+if __name__ == "__main__" : cmd()
+