Created
January 3, 2017 14:51
-
-
Save rbmntjs/bbd27a005e5c3e446103e2bf645d7162 to your computer and use it in GitHub Desktop.
A simple Python script to generate a dumb OpenType feature based on a selected glyph suffix
This file contains 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
f = CurrentFont() | |
# Set these values for the feature you want | |
# It should be based on a suffix, for easy cheap magic | |
setname = 'StylisticAlternates' | |
suffix = '.salt' | |
# The rest is automatic; copy-paste the output | |
base = [] # Base glyphs that match the suffix | |
subset = [] # Glyph names to sort | |
for glyph in f: | |
if suffix in glyph.name: | |
base.append(glyph) | |
for i in base: # Read the objects in the base set | |
subset.append(i.name) # Put their names as strings into the subset | |
subset.sort() # Sort the glyph names | |
print 'lookup feature' + setname + ' {' | |
print ' lookupflag 0;' | |
for g in subset: | |
name = f[g].name # Read glyph as an object again | |
clean = f[g].name.replace(suffix, '') | |
print ' sub \\' + clean + ' by \\' + name + ';' | |
print '} feature' + setname + ';' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment