Skip to content

Instantly share code, notes, and snippets.

@mekkablue
Created July 27, 2019 14:06
Show Gist options
  • Save mekkablue/67edaf2213bba1ee6b5fd905228b07a0 to your computer and use it in GitHub Desktop.
Save mekkablue/67edaf2213bba1ee6b5fd905228b07a0 to your computer and use it in GitHub Desktop.
Align All Components
#MenuTitle: Align All Components
# -*- coding: utf-8 -*-
__doc__="""
Fakes auto-alignment in glyphs that cannot be auto-aligned.
"""
thisFont = Glyphs.font # frontmost font
listOfSelectedLayers = thisFont.selectedLayers # active layers of selected glyphs
def process( thisLayer ):
advance = 0.0
thisFontMasterID = thisLayer.associatedFontMaster().id
for thisComponent in thisLayer.components:
thisComponent.position = NSPoint( advance, 0.0 )
advance += thisComponent.component.layers[thisFontMasterID].width
thisLayer.width = advance
thisFont.disableUpdateInterface() # suppresses UI updates in Font View
for thisLayer in listOfSelectedLayers:
thisGlyph = thisLayer.parent
print "Aligning components in:", thisGlyph.name
thisGlyph.beginUndo() # begin undo grouping
process( thisLayer )
thisGlyph.endUndo() # end undo grouping
thisFont.enableUpdateInterface() # re-enables UI updates in Font View
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment