Skip to content

Instantly share code, notes, and snippets.

@weiweihuanghuang
Created October 12, 2017 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weiweihuanghuang/4c6c35fb95f50f74055abada18b88b32 to your computer and use it in GitHub Desktop.
Save weiweihuanghuang/4c6c35fb95f50f74055abada18b88b32 to your computer and use it in GitHub Desktop.
Center Glyphs
#MenuTitle: Center Glyphs Mine
# -*- coding: utf-8 -*-
__doc__="""
"""
import GlyphsApp
thisFont = Glyphs.font # frontmost font
listOfSelectedLayers = thisFont.selectedLayers # active layers of selected glyphs
def process( thisLayer ):
LSB = thisLayer.LSB
RSB = thisLayer.RSB
width = thisLayer.width
halfSB = (LSB + RSB)/2
thisLayer.LSB = int(halfSB)
thisLayer.RSB = int(halfSB)
thisLayer.width = width
thisFont.disableUpdateInterface() # suppresses UI updates in Font View
for thisLayer in listOfSelectedLayers:
thisGlyph = thisLayer.parent
numberOfLayers = len( thisGlyph.layers )
for i in range( numberOfLayers )[::-1]:
thisOtherLayer = thisGlyph.layers[i]
print "Processing", thisGlyph.name
thisGlyph.beginUndo() # begin undo grouping
process( thisOtherLayer )
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