huangcm
2025-02-24 69ed55dec4b2116a19e4cca4393cbc014fce5fb2
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
31
32
33
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())