Skip to content

Instantly share code, notes, and snippets.

@koutsenko
Last active May 13, 2020 21:05
Show Gist options
  • Save koutsenko/047fc1062f6c12e506e847edb5b0a10b to your computer and use it in GitHub Desktop.
Save koutsenko/047fc1062f6c12e506e847edb5b0a10b to your computer and use it in GitHub Desktop.
font normalizer
# how to run:
# fontforge -lang=py -script ./normalize.py
import fontforge
from pathlib import Path
paths = list(Path(".").rglob("*.woff"))
# Constants
ascent = 800
descent = 200
xheight = 450
capheight = 700
for path in paths:
file = str(path.resolve())
print(file)
font = fontforge.open(file)
# General
font.ascent = ascent
font.descent = descent
font.em = 1024
# OS/2 -> Metrics
font.os2_winascent = ascent
font.os2_winascent_add = False
font.os2_windescent = descent
font.os2_windescent_add = False
font.os2_use_typo_metrics = False
font.os2_typoascent = ascent
font.os2_typoascent_add = False
font.os2_typodescent = -descent
font.os2_typodescent_add = False
font.os2_typolinegap = 0
font.hhea_ascent = ascent
font.hhea_ascent_add = False
font.hhea_descent = -descent
font.hhea_descent_add = False
font.hhea_linegap = 0
font.os2_capheight = capheight
font.os2_xheight = xheight
font.generate(file)
font.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment