File: gen_test_data.py

package info (click to toggle)
axisregistry 0.3.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,024 kB
  • sloc: python: 955; makefile: 4
file content (30 lines) | stat: -rw-r--r-- 757 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""
Regenerate ttx dumps. Run this is the axis registry files in
Lib/axisregistry/data/*.textproto have been updated.
"""
from fontTools.ttLib import TTFont
from fontTools.misc.testTools import getXML, parseXML
from glob import glob
import os


def dump(table, ttFont=None):
    return "\n".join(getXML(table.toXML, ttFont))


CWD = os.path.dirname(__file__)
DATA_DIR = os.path.join(CWD, "data")
font_fps = glob(os.path.join(DATA_DIR, "*.ttf"))

# Dump STATs
for fp in font_fps:
    font = TTFont(fp)
    try:
        stat = dump(font["STAT"], font)
        stat_fp = os.path.join(
            DATA_DIR, font.reader.file.name.replace(".ttf", "_STAT.ttx")
        )
        with open(stat_fp, "w") as doc:
            doc.write(stat)
    except:
        all