Skip to content

Instantly share code, notes, and snippets.

@connordavenport
Last active August 21, 2023 21:09
Show Gist options
  • Select an option

  • Save connordavenport/b324dd9571dd6aa1f36ccfb5d74aee02 to your computer and use it in GitHub Desktop.

Select an option

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
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