Skip to content

Instantly share code, notes, and snippets.

@anthrotype
Created October 16, 2024 15:16
Show Gist options
  • Save anthrotype/4facc66668c1dca9414180e4e276b922 to your computer and use it in GitHub Desktop.
Save anthrotype/4facc66668c1dca9414180e4e276b922 to your computer and use it in GitHub Desktop.
Prune unused lookups from GPOS and GSUB tables
"""Use FontTools subsetter's prune_lookup method to remove all unreferenced lookups from GPOS and GSUB tables."""
import sys
from fontTools.misc.cliTools import makeOutputFileName
from fontTools.ttLib import TTFont
# importing this dynamically adds a prune_lookups method to GPOS/GSUB classes
from fontTools import subset
input_file = sys.argv[1]
font = TTFont(input_file)
for table_tag in ("GPOS", "GSUB"):
if table_tag not in font:
continue
font[table_tag].prune_lookups(remap=True)
# save the modified font to <input_file>#1.ttf, #2, etc. to avoid overwriting original
font.save(makeOutputFileName(input_file))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment