-
-
Save arialcrime/14ad81b5b1640d600a03b090de6d0f2e to your computer and use it in GitHub Desktop.
A RoboFont script to expand kerning groups from base glyph to their composites.
This file contains hidden or 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
| from mojo.UI import CurrentWindow | |
| from simpleKerning import * | |
| """ | |
| A RoboFont script to expand kerning groups from base glyph to their composites. | |
| You need the simple kerning extension installed for this to work. | |
| 1. Select base glyph(s) (with contours) which are already grouped | |
| 2. Run the script | |
| 3. The groups will be expanded to the composites, if: | |
| - Their width is same as the base glyph | |
| - They're not already grouped | |
| """ | |
| cw = CurrentWindow().doodleWindowName | |
| f = CurrentFont() | |
| g = CurrentGlyph() | |
| groups = f.groups | |
| glyphToGroupMap = getGlyphToGroupDictionary(groups) | |
| compMap = f.getReverseComponentMapping() | |
| selection = [] | |
| if cw == 'FontWindow': | |
| f = CurrentFont() | |
| s = f.selectedGlyphs | |
| for gn in s: | |
| selection.append(gn) | |
| elif cw == 'GlyphWindow': | |
| g = CurrentGlyph() | |
| if g is not None: | |
| selection.append(g) | |
| selectedGlyphNames = [g.name for g in selection if g.name in glyphToGroupMap] | |
| def getComps(glyphName, compMap): | |
| """ | |
| Get all the related components recursively. | |
| """ | |
| result = set() | |
| inputGlyphs = set([glyphName]) | |
| while inputGlyphs: | |
| glyphName = inputGlyphs.pop() | |
| comps = compMap.get(glyphName, set()) - result - inputGlyphs | |
| if comps: | |
| result.update(comps) | |
| inputGlyphs.update(comps) | |
| return result | |
| newGroups = dict(groups) | |
| for glyphName in selectedGlyphNames: | |
| baseGlyphGroups = glyphToGroupMap.get(glyphName, []) | |
| baseGlyphWidth = f[glyphName].width | |
| for compGlyphName in getComps(glyphName, compMap): | |
| compGroups = glyphToGroupMap.get(compGlyphName, []) | |
| compGlyph = f[compGlyphName] | |
| if not compGroups: | |
| if compGlyph.width == baseGlyphWidth: | |
| for gr in baseGlyphGroups: | |
| members = list(newGroups[gr]) | |
| members.append(compGlyphName) | |
| newGroups[gr] = members | |
| compGlyph.prepareUndo("Mark glyph with changed groups") | |
| compGlyph.markColor = (0.3364, 0.9951, 0.5913, 1) | |
| else: | |
| compGlyph.prepareUndo("Mark glyph with unchanged groups") | |
| compGlyph.markColor = (1, 0.8907, 0.1478, 1) | |
| compGlyph.performUndo() | |
| f.groups.clear() | |
| f.groups.update(newGroups) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment