summaryrefslogtreecommitdiffstats
path: root/lib/silfont/scripts/psfchangettfglyphnames.py
blob: 2c9fa37cef068f40e1cc50ba39d009289fe2d891 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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()