"""统计样本用到的字体(东亚字体),决定字体替换表要覆盖哪些。""" import collections, re, sys, zipfile, pathlib sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent.parent)) from common import IDS, sample_file, sniff tot = collections.Counter() for sid in IDS: f = sample_file(sid) if sniff(f) != "docx": continue with zipfile.ZipFile(f) as z: xml = z.read("word/document.xml").decode("utf-8", "replace") sty = z.read("word/styles.xml").decode("utf-8", "replace") if "word/styles.xml" in z.namelist() else "" c = collections.Counter(re.findall(r'w:eastAsia="([^"]+)"', xml + sty)) c.update(re.findall(r'w:ascii="([^"]+)"', xml + sty)) tot.update(c) print(sid, c.most_common(6)) print("TOTAL", tot.most_common(15))