Skip to content

Instantly share code, notes, and snippets.

@chrissimpkins
Last active August 22, 2024 02:55
Show Gist options
  • Save chrissimpkins/d0898e9580b9aa8f2ae692afe724bf93 to your computer and use it in GitHub Desktop.
Save chrissimpkins/d0898e9580b9aa8f2ae692afe724bf93 to your computer and use it in GitHub Desktop.
Converts the isFixedPitch post table setting in a font to a value of 1
#!/usr/bin/env python
# -*- coding: utf-8 -*-
### DEPENDENCY:
# fontTools Python library
# ==> https://github.com/fonttools/fonttools
# ==> Install: pip install fonttools
### USAGE:
# python fpfix.py [filepath to font]
import sys
from fontTools import ttLib
if len(sys.argv) < 2:
sys.stderr.write("[fpfix.py] ERROR: Please enter a path to the font file")
sys.exit(1)
try:
tt = ttLib.TTFont(sys.argv[1])
post = tt["post"]__dict___
post["isFixedPitch"] = 1
tt.save(outfile)
print("[fpfix.py]: '" + sys.argv[1] + "' fixed pitch setting was changed to 1 in the post table")
except Exception as e:
sys.stderr.write("[fpfix.py] : ERROR: Unable to update the font isFixedPitch setting. " + str(e))
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment