I'm trying to write a macro that will sort the glyphs of a font. Is there any way to do that without creating an encoding file on disk first?
This works:
from jkFontTools import sortedGlyphListFromFont
encodingPath = r".../sortEncoding.enc"
myGlyphOrder = sortedGlyphListFromFont(fl.font)
f = open(encodingPath, "w")
f.write("%%FONTLAB ENCODING: 3001976; Temp. Sort Encoding\n")
for i in range(len(myGlyphOrder)):
f.write(myGlyphOrder[i].name+"\n")
f.close()
fl.font.encoding.Load(encodingPath)
fl.CallCommand(fl_cmd.FontModeNames)
fl.CallCommand(fl_cmd.FontSortByCodepage)
fl.UpdateFont()
But I'm trying to do something like this ...
from jkFontTools import sortedGlyphListFromFont
myGlyphOrder = sortedGlyphListFromFont(fl.font)
e = Encoding()
for i in range(len(myGlyphOrder)):
er = EncodingRecord()
er.name = myGlyphOrder[i].name
e.append(er)
fl.font.encoding = e
fl.CallCommand(fl_cmd.FontModeNames)
fl.CallCommand(fl_cmd.FontSortByCodepage)
fl.UpdateFont()
... which doesn't work because fl.font.encoding is read-only.