How to get the list of glyphs vertical boundary values for a font? #2620
Answered
by
behdad
aminabedi68
asked this question in
Q&A
-
Hello |
Beta Was this translation helpful? Give feedback.
Answered by
behdad
May 15, 2022
Replies: 2 comments
-
Something like this? from fontTools.ttLib import TTFont
from fontTools.pens.boundsPen import ControlBoundsPen as BoundsPen
import sys
f = TTFont(sys.argv[1])
glyphs = f.getGlyphSet()
ascender = f['hhea'].ascender
descender = f['hhea'].descender
print("font ascender {ascender} descender {descender}".format(ascender=ascender, descender=descender))
for glyphname in glyphs.keys():
pen = BoundsPen(glyphs, True)
glyphs[glyphname].draw(pen)
if pen.bounds is None:
continue
(xMin, yMin, xMax, yMax) = pen.bounds
if yMax > ascender:
print("glyph {glyphname} yMax {yMax}".format(glyphname=glyphname, yMax=yMax))
if yMin < descender:
print("glyph {glyphname} yMin {yMin}".format(glyphname=glyphname, yMin=yMin)) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
aminabedi68
-
exactly! thank you @behdad this is perfect :) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Something like this?