Skip to content

Instantly share code, notes, and snippets.

@mekkablue
Created July 27, 2019 15:40
Show Gist options
  • Save mekkablue/eca11f5a90bf36e423017a11e9fe8bc1 to your computer and use it in GitHub Desktop.
Save mekkablue/eca11f5a90bf36e423017a11e9fe8bc1 to your computer and use it in GitHub Desktop.
Move accents to custom anchors
#MenuTitle: Move accents to custom anchors
# -*- coding: utf-8 -*-
__doc__="""
Moves acute(.case) from 'top' to 'top_acute' anchors where available. And other accents likewise.
"""
Font = Glyphs.font
selectedGlyphs = [ x.parent for x in Font.selectedLayers ]
def customAnchorName( currentAnchorName, componentName ):
pureAnchorName = currentAnchorName.split("_")[0]
pureComponentName = componentName.split(".")[0]
return "%s_%s" % ( pureAnchorName, pureComponentName )
def process( thisGlyph ):
for thisMasterID in [ m.id for m in Font.masters ]:
thisLayer = thisGlyph.layers[ thisMasterID ]
for thisComponentIndex in range( len( thisLayer.components ))[1:]:
thisComponent = thisLayer.components[ thisComponentIndex ]
componentGlyph = thisComponent.component
componentLayer = componentGlyph.layers[ thisMasterID ]
componentAnchorName = [ a.name for a in componentLayer.anchors if a.name[0] == "_" ][0][1:]
try:
newAnchorName = customAnchorName( componentAnchorName, thisComponent.componentName )
thisComponent.setAnchor_( newAnchorName )
except Exception, e:
print e
for thisGlyph in selectedGlyphs:
print "Processing", thisGlyph.name
thisGlyph.beginUndo()
process( thisGlyph )
thisGlyph.endUndo()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment