1import sys 2from fontTools.ttx import makeOutputFileName 3from fontTools.ttLib import TTFont 4 5 6def main(args=None): 7 if args is None: 8 args = sys.argv[1:] 9 10 if len(args) < 1: 11 print("usage: dump_woff_metadata.py " 12 "INPUT.woff [OUTPUT.xml]", file=sys.stderr) 13 return 1 14 15 infile = args[0] 16 if len(args) > 1: 17 outfile = args[1] 18 else: 19 outfile = makeOutputFileName(infile, None, ".xml") 20 21 font = TTFont(infile) 22 23 if not font.flavorData or not font.flavorData.metaData: 24 print("No WOFF metadata") 25 return 1 26 27 with open(outfile, "wb") as f: 28 f.write(font.flavorData.metaData) 29 30 31if __name__ == "__main__": 32 sys.exit(main()) 33