Last active
December 28, 2015 12:48
-
-
Save kaorimatz/7502763 to your computer and use it in GitHub Desktop.
Compute ymax and ymin of a font
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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])) | |
sys.exit(1) | |
font = fontforge.open(sys.argv[1]) | |
selection = font.selection | |
if len(sys.argv) == 2: | |
selection.all() | |
else: | |
start, end = int(sys.argv[2], 0), int(sys.argv[3], 0) | |
selection.select(('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