Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Compute ymax and ymin of a font
#!/usr/bin/env python
import sys
import fontforge
if __name__ == '__main__':
if len(sys.argv) != 2 and len(sys.argv) != 4:
print('usage: {} <font> [<code-point-start> <code-point-end>]'.format(sys.argv[0]))
font =[1])
selection = font.selection
if len(sys.argv) == 2:
start, end = int(sys.argv[2], 0), int(sys.argv[3], 0)'ranges', 'unicode'), start, end)
highest = max(selection.byGlyphs, key=lambda g: g.boundingBox()[3])
lowest = min(selection.byGlyphs, key=lambda g: g.boundingBox()[1])
print('ymax = {} (U+{:04X})'.format(highest.boundingBox()[3], highest.unicode))
print('ymin = {} (U+{:04X})'.format(lowest.boundingBox()[1], lowest.unicode))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment