Skip to content

Instantly share code, notes, and snippets.

@simoncozens
Created March 13, 2023 07:28
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 simoncozens/eb1a1ef3e913bf45ddade6a173bf0f86 to your computer and use it in GitHub Desktop.
Save simoncozens/eb1a1ef3e913bf45ddade6a173bf0f86 to your computer and use it in GitHub Desktop.
from fontTools.ttLib import TTFont
from fontTools.ttLib.tables.otBase import OTTableWriter
import sys
from fontTools.feaLib.lookupDebugInfo import LOOKUP_DEBUG_INFO_KEY
font = TTFont(sys.argv[1])
def locate(table, ix):
if "Debg" not in font:
return str(ix)
debg = font["Debg"].data[LOOKUP_DEBUG_INFO_KEY][table].get(str(ix))
if debg:
return f"{ix} = {debg[0]} ({debg[1]})"
return str(ix)
for table in ["GSUB", "GPOS"]:
print(f"{table} table")
print("==========\n")
lookups = font.get(table).table.LookupList.Lookup
sizes = []
for ix, lookup in enumerate(lookups):
writer = OTTableWriter()
lookup.compile(writer, font)
sizes.append((locate(table, ix), len(writer.getAllData())))
for location, size in (list(sorted(sizes, key=lambda a:-a[1])))[0:10]:
print(location, "\t", size)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment