Skip to content

Instantly share code, notes, and snippets.

@tinylucid
Created November 30, 2022 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tinylucid/9a023d8c09f87ad4b17897a7cc3cc023 to your computer and use it in GitHub Desktop.
Save tinylucid/9a023d8c09f87ad4b17897a7cc3cc023 to your computer and use it in GitHub Desktop.
python script for fixing TTF font height
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