Skip to content

Instantly share code, notes, and snippets.

@anthrotype
Created February 28, 2019 06:04
Show Gist options
  • Select an option

  • Save anthrotype/4ea0a460f91265a82e35750727543141 to your computer and use it in GitHub Desktop.

Select an option

Save anthrotype/4ea0a460f91265a82e35750727543141 to your computer and use it in GitHub Desktop.
List/count tuple variation regions in gvar table
import sys
import pprint
from collections import OrderedDict, Counter
import fontTools
from fontTools import ttLib
log = fontTools.log
def get_gvar_regions(vfont):
locs = Counter()
axisOrder = [a.axisTag for a in vfont["fvar"].axes]
gvar = vfont["gvar"]
for glyphname, variations in gvar.variations.items():
for tv in variations:
locs[
(
tuple(
tuple(i) for i in sorted(
tv.axes.items(), key=lambda i: axisOrder.index(i[0])
)
)
)
] += 1
return locs
def main():
fontfiles = sys.argv[1:]
if not fontfiles:
sys.exit("usage: list_vf_regions.py font.ttf [font2.ttf ...]")
fontTools.configLogger(level="INFO")
for fontfile in fontfiles:
vfont = ttLib.TTFont(fontfile)
if "gvar" not in vfont:
log.warning("%s is not a truetype variable font, skipped", fontfile)
regions = get_gvar_regions(vfont)
log.info(
"%s: %d\n%s",
fontfile,
len(regions),
pprint.pformat(dict(regions))
)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment