Skip to content

How to get the list of glyphs vertical boundary values for a font? #2620

Answered by behdad
aminabedi68 asked this question in Q&A
Discussion options

You must be logged in to vote

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(g…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by aminabedi68
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants