summaryrefslogtreecommitdiffstats
path: root/lib/silfont/scripts/psfchangettfglyphnames.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/silfont/scripts/psfchangettfglyphnames.py')
-rw-r--r--lib/silfont/scripts/psfchangettfglyphnames.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/silfont/scripts/psfchangettfglyphnames.py b/lib/silfont/scripts/psfchangettfglyphnames.py
new file mode 100644
index 0000000..2c9fa37
--- /dev/null
+++ b/lib/silfont/scripts/psfchangettfglyphnames.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+__doc__ = 'Rename the glyphs in a ttf file based on production names in a UFO'
+__url__ = 'http://github.com/silnrsi/pysilfont'
+__copyright__ = 'Copyright (c) 2017 SIL International (http://www.sil.org)'
+__license__ = 'Released under the MIT License (http://opensource.org/licenses/MIT)'
+__author__ = 'Alan Ward'
+
+# Rename the glyphs in a ttf file based on production names in a UFO
+# using same technique as fontmake.
+# Production names come from ufo.lib.public.postscriptNames according to ufo2ft comments
+# but I don't know exactly where in the UFO that is
+
+from silfont.core import execute
+import defcon, fontTools.ttLib, ufo2ft
+
+argspec = [
+ ('iufo', {'help': 'Input UFO folder'}, {}),
+ ('ittf', {'help': 'Input ttf file name'}, {}),
+ ('ottf', {'help': 'Output ttf file name'}, {})]
+
+def doit(args):
+ ufo = defcon.Font(args.iufo)
+ ttf = fontTools.ttLib.TTFont(args.ittf)
+
+ args.logger.log('Renaming the input ttf glyphs based on production names in the UFO', 'P')
+ postProcessor = ufo2ft.PostProcessor(ttf, ufo)
+ ttf = postProcessor.process(useProductionNames=True, optimizeCFF=False)
+
+ args.logger.log('Saving the output ttf file', 'P')
+ ttf.save(args.ottf)
+
+ args.logger.log('Done', 'P')
+
+def cmd(): execute(None, doit, argspec)
+if __name__ == '__main__': cmd()