UNSOLVED Fontparts, Kerning groups and performance.
guidoferreyra last edited by gferreira
Since this is not strictly related with RF but Fontparts, I don’t know If here is the correct place to post this. I hope to not be spamming.
I made a quick script to change kerning groups and it works on most of the cases, but it hungs up if the font is really big.
I really don’t know if I’m doing it correctly. So any help is really appreciated.
here a sample code:
from fontParts.world import * fontPath = 'myFont.ufo' font = OpenFont(fontPath, showInterface=False) glyphs = font.keys() def removeGlyphFromKerningGroups(glyph): currentGroups = font.groups.findGlyph(glyph.name) for groupName in currentGroups: group = font.groups[groupName] groupList = list(font.groups[groupName]) groupList.remove(glyph.name) font.groups[groupName] = tuple(groupList) def getKerningGroups(glyphName, side): if side == 1: groups = font.groups.side1KerningGroups else: groups = font.groups.side2KerningGroups glyphGroups =  for key in groups: for value in groups[key]: if glyphName == value: glyphGroups.append(key) return glyphGroups for thisGlyphName in glyphs: thisGlyph = font[thisGlyphName] if thisGlyphName.endswith(".sc"): basename = thisGlyphName.split(".") removeGlyphFromKerningGroups(thisGlyph) side1Groups = getKerningGroups(basename, 1) for side1Group in side1Groups: kern1Group = font.groups[side1Group] kern1GroupList = list(kern1Group) kern1GroupList.append(thisGlyph.name) font.groups[side1Group] = tuple(kern1GroupList) side2Groups = getKerningGroups(basename, 2) for side2Group in side2Groups: kern2Group = font.groups[side2Group] kern2GroupList = list(kern2Group) kern2GroupList.append(thisGlyph.name) font.groups[side2Group] = tuple(kern2GroupList) currentGroups = font.groups.findGlyph(thisGlyph.name) print (thisGlyph.name, currentGroups)
Thanks in advance.
explain 'hung' is there a traceback? do you end up in an endless loop
can you provide an dummy ufo where this happens?
a tip about performance: if you are making a lot of edits, it’s faster to work on pure Python objects and then save the result back into the font when you’re done.
you can get a font’s groups as a dict with
hope that helps!
guidoferreyra last edited by guidoferreyra