fonttools/Snippets/dump_woff_metadata.py
Cosimo Lupo 0782513d4d Snippets: add 'merge_woff_metadata.py' and 'dump_woff_metatada.py' scripts
This is just to exemplify how one could use the `TTFont.flavorData` attribute to get/set the WOFF metadata.
See discussion at https://github.com/behdad/fonttools/issues/630
2016-07-04 15:51:51 +01:00

34 lines
751 B
Python

from __future__ import print_function
import sys
from fontTools.ttx import makeOutputFileName
from fontTools.ttLib import TTFont
def main(args=None):
if args is None:
args = sys.argv[1:]
if len(args) < 1:
print("usage: dump_woff_metadata.py "
"INPUT.woff [OUTPUT.xml]", file=sys.stderr)
return 1
infile = args[0]
if len(args) > 1:
outfile = args[1]
else:
outfile = makeOutputFileName(infile, None, ".xml")
font = TTFont(infile)
if not font.flavorData or not font.flavorData.metaData:
print("No WOFF metadata")
return 1
with open(outfile, "wb") as f:
f.write(font.flavorData.metaData)
if __name__ == "__main__":
sys.exit(main())