#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 交付资产的门禁 —— 第四十六刀收尾 为什么要有这个文件:这一轮查出「构造标准字用 fill-rule=evenodd ⇒ 每处笔画重叠被挖掉一块」, 而缺陷就躺在 348 个已生成的 .svg 里,靠肉眼看评审页发现不了(缺口只占画布 0.4%~1.3%)。 所以修完之后,必须留一个【机器读得懂"不许再这样"】的东西,而不是把结论写在注释里等人看。 判据三组,每组都配一个"答案由构造决定"的自证: A 现行字标资产里【不许出现 evenodd】; B 每个资产必须是可解析 XML、根标签是 、睿/NOVALON 的路径没被截断; C 尺寸策略:标着"专用版"的必须带固定宽高,可缩放版必须【不】带 —— 上一版这条判据被 stroke-width 与内层 误命中过(假警报), 又被开头那行 骗过(三个 OK 全是空判)。所以这里显式回显"切到了什么"。 退出码:0 = 全过;1 = 有红。不许打印红字却 exit 0。 """ import os import re import sys import xml.etree.ElementTree as ET HERE = os.path.dirname(os.path.abspath(__file__)) # 只有这些目录是"现行交付面"。其余 assets-* 是已作废的方向 # (环 / 圆印 / 液滴 / 模数批……),那里 evenodd 是对的(真有字碗),不许一刀扫过去。 # 只扫"现在真会交付的东西"。assets-final 是第十刀前后的 M2/M3/M4/N5 候选, # 那条方向早已作废,它的资产带着固定 width/height 是当时的写法,不是缺陷 —— # 拿现行尺寸策略去判它,只会造出 19 条假红,把真信号淹掉。 LIVE = ["assets-lockup", "assets-brand", "assets-jianbiao", "assets-wordmark", "assets-identity", "assets-novalon", "assets-delivery", "landing", ] SIZED = re.compile(r"-16\.svg$|-32\.svg$|favicon") def root_tag(text): """根标签 = 【第一个 '。 直接 split('>')[0] 会切到文件开头的 —— 注释也以 > 收尾, 那样 root 永远不含 width,判据恒真,是空判。""" i = text.find("", i) return text[i:j if j > 0 else None] def check(path): back = open(path, encoding="utf-8").read() fails = [] try: ET.fromstring(back[back.find(":素印/横条那几枚本来就是 rect 拼的, # 要求 path>=1 会把三枚正常资产判成"一个 path 都没有"。 nshape = sum(back.count("<" + t + " ") for t in ("path", "rect", "circle", "polygon", "ellipse")) if nshape < 1: fails.append("一个图形元素都没有(path/rect/circle/polygon/ellipse)") if nshape and not re.search(r'\sd="M|\sd="m|\swidth="|\sr="', back): fails.append("图形元素在,但没有任何几何数据") fixed = bool(re.search(r'\swidth="\d', root)) # 只看根标签,避开 stroke-width / rect want_fixed = bool(SIZED.search(os.path.basename(path))) if fixed != want_fixed: fails.append("尺寸策略不符:根标签固定宽高=%s,期望=%s" % (fixed, want_fixed)) if "evenodd" in back: fails.append("出现 fill-rule=evenodd —— 构造标准字必须走 nonzero") return fails, nshape, fixed def main(): files = [] missing = [] for d in LIVE: dd = os.path.join(HERE, d) n0 = len(files) if not os.path.isdir(dd): print("红 LIVE 目录不存在:%s" % d) missing.append(d) continue for fn in sorted(os.listdir(dd)): if fn.endswith(".svg"): files.append(os.path.join(dd, fn)) if len(files) == n0: print("红 LIVE 目录 %s 扫到 0 个 .svg ⇒ 覆盖面在缩小" % d) missing.append(d) # 覆盖面缩小必须判红。触发过一次真实事故:列表里写成 "a""b"(相邻字符串字面量 # 在 Python 里会拼接)⇒ 目录名变成 a b 连写、少扫 11 个文件,而退出码仍是 0。 if not files: print("FAIL 一个文件都没扫到 —— 这是空判,不是通过") return 1 bad = 0 for p in files: fails, nshape, fixed = check(p) rel = os.path.relpath(p, HERE) if fails: bad += 1 print("FAIL %-46s 墨形=%d 固定宽高=%s" % (rel, nshape, fixed)) for f in fails: print(" · %s" % f) else: print("ok %-46s 墨形=%d 固定宽高=%s" % (rel, nshape, fixed)) # 自证:判据本身必须能红。造一个已知含 evenodd 的样本喂给它,不红就是判据坏了。 tmp = os.path.join(HERE, "_selftest.svg") with open(tmp, "w", encoding="utf-8") as f: f.write('' '') self_fails, _n, _fx = check(tmp) os.remove(tmp) if not any("evenodd" in x for x in self_fails): print("FAIL 自证不通过:明知含 evenodd 的样本没被判红 ⇒ 上面所有 ok 都不作数") return 1 print("自证 含 evenodd 的样本被判红 ✓(%s)" % self_fails[-1]) print("\n扫 %d 个文件,红 %d 个%s" % ( len(files), bad, "" if not missing else " | 覆盖面缺失 %s" % ",".join(missing))) return 1 if (bad or missing) else 0 if __name__ == "__main__": sys.exit(main())