-
-
Save ryanbugden/109636cce4a50fa38f9ff6562ea9392a to your computer and use it in GitHub Desktop.
Little script to test alternate glyphs in context. Type a test string with blanks (_). See that test string with blanks replaced by selected glyphs.
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
| # menuTitle: Test Alt Glyphs in Space Center | |
| from mojo.UI import getDefault, setDefault, preferencesChanged, AskString, OpenSpaceCenter | |
| ''' | |
| Little script to test alternate glyphs in context. Type a test string with blanks (_). See that test string with blanks replaced by selected glyphs. | |
| ''' | |
| # attempt to remember the last thing you entered | |
| try: | |
| placeholder = getDefault("testStringForAlts") | |
| except: | |
| placeholder = "_" | |
| test_string = AskString("Enter test string. Selected glyphs replace “_”", value=placeholder, title='Test Alternate Glyphs in Context') | |
| if test_string != None: | |
| f = CurrentFont() | |
| sc_text = '' | |
| i = 0 | |
| for g_name in f.selectedGlyphNames: | |
| g = f[g_name] | |
| # avoid using slashed glyph names if we can | |
| replacement = f"/{g_name} " | |
| if g.unicode: | |
| replacement = str(chr(g.unicode)) | |
| sc_text += test_string.replace("_", replacement) | |
| if i != len(f.selectedGlyphNames) - 1: | |
| sc_text += "\\n" | |
| i += 1 | |
| sc = OpenSpaceCenter(f, True) | |
| sc.setRaw(sc_text) | |
| # save what you entered for the future | |
| setDefault("testStringForAlts", test_string, validate=True) | |
| preferencesChanged() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment