BRAND-MANUAL.md 收敛识别方案裁定与实测判据;TOKEN-MIGRATION.md 记 P1/P3/P4 迁移面与孪生缺陷; TEST-PATCH.md 记 P7 的 1→0 实测。随包入库的是结论赖以成立的仪器与证据:check-assets、check-manual、 verify-assets-cross、check-wordmark-copies、check-docsync、check-probes(四段闸,每段带能失败的负例)、 check-baseline-shift.cjs(平移感知基线判据,四合成样本两绿两红自测通过;它取代被证伪的 「diff 包围盒不许越页眉带」)与 measured/baseline-shift-p1.json(第一批 104 张逐张分类,带 _src 出处戳)。 大体积工作件不入库:样机 HTML 与栅格截图 100+MB、字体母版 45MB 留在盘上,入库 690 个文本/矢量件。
124 lines
5.7 KiB
Python
124 lines
5.7 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
交付资产的门禁 —— 第四十六刀收尾
|
||
|
||
为什么要有这个文件:这一轮查出「构造标准字用 fill-rule=evenodd ⇒ 每处笔画重叠被挖掉一块」,
|
||
而缺陷就躺在 348 个已生成的 .svg 里,靠肉眼看评审页发现不了(缺口只占画布 0.4%~1.3%)。
|
||
所以修完之后,必须留一个【机器读得懂"不许再这样"】的东西,而不是把结论写在注释里等人看。
|
||
|
||
判据三组,每组都配一个"答案由构造决定"的自证:
|
||
A 现行字标资产里【不许出现 evenodd】;
|
||
B 每个资产必须是可解析 XML、根标签是 <svg>、睿/NOVALON 的路径没被截断;
|
||
C 尺寸策略:标着"专用版"的必须带固定宽高,可缩放版必须【不】带
|
||
—— 上一版这条判据被 stroke-width 与内层 <rect 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):
|
||
"""根标签 = 【第一个 <svg 之后】到它的 '>'。
|
||
直接 split('>')[0] 会切到文件开头的 <!-- 注释 --> —— 注释也以 > 收尾,
|
||
那样 root 永远不含 width,判据恒真,是空判。"""
|
||
i = text.find("<svg")
|
||
if i < 0:
|
||
return ""
|
||
j = 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("<svg"):])
|
||
except Exception as e: # noqa: BLE001
|
||
fails.append("XML 解析失败:%s" % e)
|
||
root = root_tag(back)
|
||
if not root.startswith("<svg"):
|
||
fails.append("没取到根标签(取到的是 %r)" % root[:24])
|
||
# 有墨形的判据不能只认 <path>:素印/横条那几枚本来就是 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('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10">'
|
||
'<path d="M 0 0 L 8 0 L 8 8 L 0 8 Z" fill="#000" fill-rule="evenodd"/></svg>')
|
||
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())
|