Last active
February 11, 2022 21:57
-
-
Save arrowtype/999cc6263321ce317724ff8ac01ab81a to your computer and use it in GitHub Desktop.
RoboFont script to split glyphs from a kern group, but keep kerning (so you can fix it without disrupting it too much)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Split glyphs from a given kerning group, but keep kerning | |
so you don’t lose a bunch of almost-correct kerns. | |
(Slightly | |
E.g. If you need to split "e" glyphs out of the "o" group. | |
USAGE: | |
- 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. | |
""" | |
# --------------------------------------- | |
# CONFIGURATION BELOW | |
originalGroupName = "public.kern2.o" | |
newGroupName = "public.kern2.c" | |
newGroupGlyphs = "c ccedilla cacute ccaron" | |
# CONFIGURATION ABOVE | |
# --------------------------------------- | |
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(): | |
splitGroups(font) | |
font.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment