gen_test_data.py 757 B

123456789101112131415161718192021222324252627282930
  1. """
  2. Regenerate ttx dumps. Run this is the axis registry files in
  3. Lib/axisregistry/data/*.textproto have been updated.
  4. """
  5. from fontTools.ttLib import TTFont
  6. from fontTools.misc.testTools import getXML, parseXML
  7. from glob import glob
  8. import os
  9. def dump(table, ttFont=None):
  10. return "\n".join(getXML(table.toXML, ttFont))
  11. CWD = os.path.dirname(__file__)
  12. DATA_DIR = os.path.join(CWD, "data")
  13. font_fps = glob(os.path.join(DATA_DIR, "*.ttf"))
  14. # Dump STATs
  15. for fp in font_fps:
  16. font = TTFont(fp)
  17. try:
  18. stat = dump(font["STAT"], font)
  19. stat_fp = os.path.join(
  20. DATA_DIR, font.reader.file.name.replace(".ttf", "_STAT.ttx")
  21. )
  22. with open(stat_fp, "w") as doc:
  23. doc.write(stat)
  24. except:
  25. all