Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
RoboFont script to split glyphs from a kern group, but keep kerning (so you can fix it without disrupting it too much)
Split glyphs from a given kerning group, but keep kerning
so you don’t lose a bunch of almost-correct kerns.
E.g. If you need to split "e" glyphs out of the "o" group.
- set originalGroupName (group to split from)
- set newGroupName (new group to make)
- set names of glyphs to split out as a space-seperated list.
(Option + Command + C to copy these from font view.)
Will run on all open fonts.
Assumes kerning groups are named in conventional way, i.e. "public.kern1.glyphName" for left side of kern pair.
# ---------------------------------------
originalGroupName = "public.kern2.o"
newGroupName = "public.kern2.c"
newGroupGlyphs = "c ccedilla cacute ccaron"
# ---------------------------------------
def splitGroups(font):
# make originalGroupName without newGroupGlyphNames
cleanedOrginalGroup = [gname for gname in font.groups[originalGroupName] if gname not in newGroupGlyphs.split()]
# update groups from new group info
font.groups.update({originalGroupName: cleanedOrginalGroup, newGroupName: newGroupGlyphs.split()})
# copy kerning for originalGroupName
for (left, right), value in font.kerning.items():
if originalGroupName.split(".")[1] == "kern1":
if left == originalGroupName:
font.kerning[newGroupName, right] = value
if originalGroupName.split(".")[1] == "kern2":
if right == originalGroupName:
font.kerning[left, newGroupName] = value
for font in AllFonts():
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment