Skip to content

Instantly share code, notes, and snippets.

@rbmntjs
Created January 3, 2017 14:51
Show Gist options
  • Save rbmntjs/bbd27a005e5c3e446103e2bf645d7162 to your computer and use it in GitHub Desktop.
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
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