fontParts
fontParts copied to clipboard
Why was glyph.center() removed?
I used to use glyph.center() a lot, and am surprised it’s deprecated:
Traceback (most recent call last):
File "<untitled>", line 2, in <module>
File "/Applications/RoboFont.app/Contents/Resources/lib/python3.6/fontParts/base/deprecated.py", line 326, in center
fontParts.base.deprecated.RemovedWarning: 'Glyph.center()'
What is the reason for the removal? Is there a replacement?
it was part of a robofab clean up, where lots of ambiguous callbacks and api where removed.
see https://github.com/robotools/fontParts/blob/master/Lib/fontParts/base/deprecated.py
A lot of those old RoboFab methods were the result of me having a project that needed a few lines of code and I dumbly thought "I'll just put this in the object instead of writing a script!" It made RoboFab really crufty, so I removed those things. Here's the replacement:
width = glyph.width
xMin, yMin, xMax, yMax = glyph.bounds
glyph.leftMargin = int(round((width - (xMax - xMin)) / 2))
glyph.width = width
(Untested. 😁)