Created
October 16, 2024 15:16
-
-
Save anthrotype/4facc66668c1dca9414180e4e276b922 to your computer and use it in GitHub Desktop.
Prune unused lookups from GPOS and GSUB tables
This file contains hidden or 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
"""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