from fontTools import ttLibBut what I'd like to do is to add new entries. I suppose I need to construct new NameRecord objects first in order to append them to the name table, but I have no idea how to achieve this.
ttPath = '/Volumes/test.ttf'
ttFont = ttLib.TTFont(ttPath)
nameTable = ttFont['name'].names
print nameTable
>> [<NameRecord NameID=0; PlatformID=1; LanguageID=0>, ... ]
Comments
1. Extract the name table:
ttx -t name test.ttf
2. Edit the resulting XML file (test.ttx) as you wish.
3. Merge it back into your font:
ttx -m test.ttf test-edited.ttx
There may be a way to do the same work within Python via direct manipulation of data structures. But since ttx is designed to convert things to XML and back, I think it’s more prudent to manipulate the XML.
I know TTX is great for doing this stuff, but still I’d prefer to do this directly in Python.
It will choose a free name ID (if you pass nameID=None) automatically and return it. 'names' is a dictionary with the name in multiple languages, such as {'en': 'Pale', 'de': 'Blaß', 'de-CH': 'Blass'}
Or, similar, but simpler if you don't want multilingual entries: