Last active
August 21, 2023 21:09
-
-
Save connordavenport/b324dd9571dd6aa1f36ccfb5d74aee02 to your computer and use it in GitHub Desktop.
give RF a glyphs like feature to make a component out of contour
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.subscriber import Subscriber, registerRoboFontSubscriber | |
| class makeParts(Subscriber): | |
| debug = True | |
| def glyphEditorWantsContextualMenuItems(self, info): | |
| myMenuItems = [ | |
| ("Make Component of Contour(s)", self.markPartCallback), | |
| ] | |
| info["itemDescriptions"].extend(myMenuItems) | |
| def markPartCallback(self, sender): | |
| glyph = CurrentGlyph() | |
| partName = f"_part.{glyph.name}" | |
| skipExportGlyphs = glyph.font.lib["public.skipExportGlyphs"] | |
| selectedContours = glyph.selectedContours | |
| if selectedContours: | |
| glyph.font.newGlyph(partName) | |
| for contour in selectedContours: | |
| glyph.font[partName].appendContour(contour) | |
| glyph.removeContour(contour) | |
| glyph.font[partName].width = glyph.width | |
| glyph.appendComponent(partName) | |
| skipExportGlyphs.append(partName) | |
| glyph.font.lib["public.skipExportGlyphs"] = list(set(skipExportGlyphs)) | |
| if __name__ == '__main__': | |
| registerRoboFontSubscriber(makeParts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment