Hi.
I want to make the glyphs center in vertical height, I modified a python script,
I don’t know how to define vertical width.
How to define the vertical width in Python:sweat:
Or what other quick ways to do it.
I have a large number of glyphs that need to be centered.
import sys
import os
from GlyphsApp import *
import objc
The vertical width/TSB/BSB are used for vertical layout. If you like to center the glyph for horizontal layout, you just move the outlines. You can use layer.applyTransform((1, 0, 0, 1, X, Y)), The argument is an transformation matrix. The last two numbers are the X and Y offset.
I want to process multiple selected glyphs at once.
This can only be processed one at a time.
Can you help me?
for myGlyph in Glyphs.font.glyphs:
layer = Glyphs.font.selectedLayers[0] # current layer
from Foundation import NSMidY
bounds = Layer.bounds
centerY = NSMidY(bounds)
myAscender = Font.selectedFontMaster.ascender
myDescender = Font.selectedFontMaster.descender
mycenterY = (myAscender + myDescender) / 2.0
shift = mycenterY - centerY
Layer.applyTransform([
1, # x scale factor
0.0, # x skew factor
0.0, # y skew factor
1, # y scale factor
0.0, # x position
shift # y position
])