Created
November 30, 2022 11:04
-
-
Save tinylucid/9a023d8c09f87ad4b17897a7cc3cc023 to your computer and use it in GitHub Desktop.
python script for fixing TTF font height
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
import os | |
import sys | |
from fontTools import ttLib | |
def run(argv): | |
if len(argv) != 2: | |
print("USAGE: %s <font-file>" % argv[0]) | |
sys.exit(1) | |
fontpath = argv[1] | |
tt = ttLib.TTFont(fontpath) | |
shift_down = 100 | |
extra_ascent = 100 | |
tt['hhea'].ascent += shift_down + extra_ascent | |
tt['hhea'].descent += shift_down | |
tt['hhea'].lineGap = 0 | |
tt.save(get_nolinegap_filepath(fontpath)) | |
def get_nolinegap_filepath(fontpath): | |
fontpath_list = os.path.split(fontpath) | |
font_dirname = fontpath_list[0] | |
font_basename = fontpath_list[1] | |
basepath_list = font_basename.split(".") | |
outfile_basename = basepath_list[0] + "-nolinegap." + basepath_list[1] | |
return os.path.join(font_dirname, outfile_basename) | |
if __name__ == '__main__': | |
run(sys.argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment