Skip to content

Instantly share code, notes, and snippets.

@typemytype
Created March 27, 2024 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save typemytype/afc87c576193ad189378e970bed54ab4 to your computer and use it in GitHub Desktop.
Save typemytype/afc87c576193ad189378e970bed54ab4 to your computer and use it in GitHub Desktop.
add contextual menu to remove all glyph layer data for the selected glyphs
from mojo.subscriber import Subscriber, registerRoboFontSubscriber
class RemoveGlyphLayersSubscriber(Subscriber):
debug = True
def fontOverviewWantsContextualMenuItems(self, items):
if items["itemDescriptions"]:
items["itemDescriptions"].append("---")
items["itemDescriptions"].append(("Remove Layers for Glyphs", self.removeLayerForGlyphs))
def removeLayerForGlyphs(self, sender):
font = CurrentFont()
glyphNames = font.selectedGlyphNames
if not glyphNames:
glyphNames = font.keys()
removedGlyphNames = set()
for layer in font.layers:
if layer == font.defaultLayer:
continue
for glyphName in glyphNames:
if glyphName in layer:
del layer[glyphName]
removedGlyphNames.add(glyphName)
with font.holdChanges():
for glyphName in removedGlyphNames:
font[glyphName].changed()
registerRoboFontSubscriber(RemoveGlyphLayersSubscriber)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment