Skip to content

Instantly share code, notes, and snippets.

@ryanbugden
Created March 21, 2023 17:05
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 ryanbugden/44fad560553ce2c4ab1606c88bd113d0 to your computer and use it in GitHub Desktop.
Save ryanbugden/44fad560553ce2c4ab1606c88bd113d0 to your computer and use it in GitHub Desktop.
A font overview contextual menu item that allows you to toggle skip-export for selected glyphs. Install as start-up script.
from mojo.subscriber import Subscriber, registerFontOverviewSubscriber
class ToggleSkipExportMenu(Subscriber):
'''
A contextual menu item:
Go through all selected glyphs, and change whether they are set to export or non-export,
based on the opposite of the state of the first glyph.
2023.03.21
'''
def fontOverviewWantsContextualMenuItems(self, info):
self.f = CurrentFont()
if self.f is None:
return
if not self.f.selectedGlyphNames:
return
myMenuItems = [
("Toggle Skip-Export", self.skip_export_selected_glyphs)
]
info['itemDescriptions'].extend(myMenuItems)
def skip_export_selected_glyphs(self, sender):
# check to see if the public.skipExportGlyphs key is in the lib. if not, make it
try:
# stephen’s duplicate-clean-up step, but sandwiched in here
self.f.lib['public.skipExportGlyphs'] = list(set(self.f.lib['public.skipExportGlyphs']))
except:
self.f.lib['public.skipExportGlyphs'] = []
# starting empty lists to print out later when filled
non_exp = []
exp = []
# check first glyph of selection, and plan to set everything to the opposite state of that
if self.f.selectedGlyphNames[0] in self.f.lib['public.skipExportGlyphs']:
make_nonExp = False
else:
make_nonExp = True
# let's change states
for g_name in self.f.selectedGlyphNames: # self.f.selection is deprecated
g = self.f[g_name]
if make_nonExp == True:
if not g_name in self.f.lib['public.skipExportGlyphs']:
self.f.lib['public.skipExportGlyphs'].append(g_name)
non_exp.append(g_name)
elif make_nonExp == False:
if g_name in self.f.lib['public.skipExportGlyphs']:
self.f.lib['public.skipExportGlyphs'].remove(g_name)
exp.append(g_name)
g.changed()
# print results
if exp != []:
print("NEWLY SET TO EXPORT:")
print(exp)
print()
if non_exp != []:
print("NEWLY SET TO NON-EXPORT:")
print(non_exp)
print()
if __name__ == "__main__":
registerFontOverviewSubscriber(ToggleSkipExportMenu)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment