Files
zhangxiang a57826f710 docs(brand): 品牌全案手册与落库证据入库(判据、门禁、负例都在场)
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 个文本/矢量件。
2026-10-16 19:23:28 +08:00

402 lines
20 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
交付资产集 + favicon 全套(第五十刀 · 任务 #18)
两件事,都有硬因由:
一、把散在 assets-lockup / assets-brand / assets-jianbiao 里的东西收成一个
真正能交接的目录 `assets-delivery/`:命名统一、每个文件头部带来源注释、
正色与反白成对,并按已裁定的规则配齐:
· 主锁定(上下,两端对齐)
· 名单独用(横排位 —— 裁定②:横排不带英文)
· 竖排锁定
· 简标两副刻版(≥48px 主刻版 / ≤24px 小刻版 —— 裁定①A)
· 头像两版(full 标准 / ring2 仪式版 —— 裁定③)
⚠ 全部必须是纯路径:不许有 <text>,不许引外部字体。
二、重做 favicon。现网 public/favicon.svg 有两个真实缺陷(本刀实测,不是推测):
① 用 <text> 写「睿新致遠」,font-size=24 在 viewBox 100 里 ⇒ 16px 渲染时
每字 3.84px,物理上不可读(正是 #14 R2 那条下限的活标本);
② font-family 首选 'Ma Shan Zheng' / 'ZCOOL XiaoWei' —— 两个 Google 字体,
仓库既没装也没嵌,且项目规则明令禁止外部字体 CDN。
产出:favicon.svg(纯路径,16px 专用几何)+ 16/32/180/512 PNG + 多尺寸 .ico。
栅格化用仓库已有的 sharp(实测可用),.ico 由本文件自己封
—— 现网那份 .ico 只封了 32 一档,这里封 16/32/48 三档。
三、自检不许省:写完必须回读。
每个文件跑 XML 解析、数图形元素、查有没有 <text>/http 引用/evenodd、
查根标签尺寸策略;.ico 封完再解回来数目录项。
并且配【反向自证】:明知违规的样本必须被判红,判不红就说明校验是空的。
"""
import importlib.util
import json
import os
import re
import struct
import subprocess
import sys
import xml.etree.ElementTree as ET
HERE = os.path.dirname(os.path.abspath(__file__))
OUT = os.path.join(HERE, "assets-delivery")
REPO = os.path.dirname(os.path.dirname(HERE))
def load(name, fn):
sp = importlib.util.spec_from_file_location(name, os.path.join(HERE, fn))
m = importlib.util.module_from_spec(sp)
sp.loader.exec_module(m)
return m
bd = load("bd", "brand.py")
jb = load("jb", "jianbiao.py")
nv, lk = bd.nv, bd.lk
INK, WHITE, RED = bd.INK, bd.WHITE, bd.RED
GEN = "pack-assets.py · 第五十刀 · 判据出处见 MANIFEST.md"
def head(title, rule):
return ('<?xml version="1.0" encoding="UTF-8"?>\n'
'<!-- 睿新致遠 NOVALON · %s\n'
' 规则/判据:%s\n'
' 生成:%s\n'
' 纯路径,无 <text>,无外部字体。 -->\n' % (title, rule, GEN))
def strip_size(svg):
return re.sub(r' (width|height)="[\d.]+"', '', svg, count=2)
def set_size(svg, px):
s = strip_size(svg)
return s.replace('<svg ', '<svg width="%d" height="%d" ' % (px, px), 1)
# ------------------------------------------------------------------ SVG 集
def name_only(px=None, col=INK):
"""名单独用(横排位)。裁定②:横排不带英文。"""
body, nl, nr, nh = lk.name_row(16.0, 52.0, bd.NAME_H, col)
W, H = nr + 16.0, 96.0
s = ('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 %g %g" '
'width="%g" height="%g">%s</svg>' % (W, H, W, H, body))
return s if px is None else set_size(s, px)
def build_set():
os.makedirs(OUT, exist_ok=True)
# 先清空:上一版跑剩的文件留在交付目录里,会被当成这一版的产物交出去。
# (真的出现过:JOBS 改了输出名之后,旧 favicon-native-16.png 和新的
# favicon-native-32.png 并存在同一个目录里。)
for f in sorted(os.listdir(OUT)):
if f.endswith((".svg", ".png", ".ico")):
os.remove(os.path.join(OUT, f))
files = {}
# P5=S4(2026-10-16 甲方「均采用推荐方案」):号里的 A 上正朱砂并把笔宽乘 1.146。
# 只给**墨版**加彩;反白版整体走单色白 —— 实测 `#E13C58` 对白字轻 80.6%、
# 纸底朱砂直接搬上来轻 87.6%,深底加彩在光学上是虚的,裁定不做。
ACCENT = ("A", "#C41E3A", 1.146)
st, stm = bd.lockup_stack(560, accent=ACCENT)
# 反白版也逐字母发射:让两张锁定的 path 结构一一对应,交叉核验的「反白只换色」判据
# 才有得比;A 在反白版里**不加彩也不加粗**(深底没有色彩缺口可补,实测加彩轻 80.6%)。
rv, rvm = bd.lockup_stack(560, WHITE, WHITE, per_letter=True)
cl, cm = bd.lockup_column(250, accent=ACCENT)
files["lockup-primary.svg"] = (head("主锁定(上下·两端对齐)",
"号 cap = 名高×0.535;锁定字距 33.62;左右差实测 0.00;画布宽高均由墨算;A 用正朱砂且笔宽×1.146(P5=S4,唯一笔宽例外)"),
strip_size(st))
files["lockup-primary-reversed.svg"] = (head("主锁定·反白", "用于深底/朱砂底"), strip_size(rv))
files["name-alone.svg"] = (head("名单独用(横排位)",
"裁定②:横排不带英文;导航栏等窄长条用这一枚"), strip_size(name_only()))
files["name-alone-reversed.svg"] = (head("名单独用·反白", "裁定②"),
strip_size(name_only(col=WHITE)))
files["lockup-vertical.svg"] = (head("竖排锁定", "匾额/书签/竖幅;竖列居中在名上方"),
strip_size(cl))
files["seal-master.svg"] = (head("简标·主刻版(≥48px)",
"白文睿 字面 0.78;实测信息下限 48px(16px 保留率仅 61.9%%、连通体 4→10)"),
strip_size(jb.seal_wen(100)))
files["seal-16.svg"] = (head("简标·小刻版(≤24px,16px 档)",
"字面 0.92 + 减地 0.5 设备像素;减地按设备像素定义 ⇒ 这一版绑死 16px,放大即废"),
set_size(jb.seal_wen(16, face=0.92, dg=0.5), 16))
files["avatar-standard.svg"] = (head("头像·标准版 full(字面 0.80)",
"裁定③:40px 保留率 93.1%% 最优;圆内不裁切上限 face≤0.866(真迹最远极径 0.5773×max)"),
strip_size(jb.avatar(512, "full")))
files["avatar-ceremonial.svg"] = (head("头像·仪式版 ring2(粗白环 4.5% + 字面 0.68)",
"裁定③:只用在环能活的大载体;细环版已否(40px 碎成 38 块)"),
strip_size(jb.avatar(512, "ring2")))
# favicon:16px 专用几何(小刻版),纯路径
files["favicon.svg"] = (head("favicon(16px 专用几何)",
"替换现网 favicon.svg —— 现网用 <text> 写 16px 不可读的汉字并首选 Google 字体"),
set_size(jb.seal_wen(16, face=0.92, dg=0.5), 16))
# 大尺寸栅格化用的母版(主刻版,字面 0.78)
files["favicon-source-large.svg"] = (head("32/180/512 PNG 的栅格源(主刻版)",
"≥32px 时「睿」已可读,用主刻版而不是 16px 专用几何"),
set_size(jb.seal_wen(512), 512))
for name, (h, body) in files.items():
with open(os.path.join(OUT, name), "w", encoding="utf-8") as f:
f.write(h + body + "\n")
return files
# ------------------------------------------------------------------ PNG / ICO
NODE_RASTER = """
const sharp=require('sharp'), fs=require('fs'), path=require('path');
const D=process.argv[2];
/* 16 这一档必须用 16px 专用几何(favicon.svg)当源,不能用主刻版源。
上一版这里写成 favicon-source-large.svg → 16,实测封闭白只有 9.77%,
而同一尺寸的 favicon.svg 是 15.63% —— 差 60%。这正是要靠"两副刻版"的原因,
结果栅格化时把专用版绕过了,等于只交付了一副。 */
const JOBS=[['favicon.svg',16,'favicon-16x16.png'],
['favicon-source-large.svg',32,'favicon-32x32.png'],
['favicon-source-large.svg',48,'favicon-48x48.png'],
['favicon-source-large.svg',180,'apple-touch-icon.png'],
['favicon-source-large.svg',512,'icon-512x512.png'],
['favicon.svg',32,'favicon-native-32.png']];
(async()=>{
for(const [src,px,out] of JOBS){
const b=fs.readFileSync(path.join(D,src));
await sharp(b,{density:300}).resize(px,px,{fit:'contain',background:{r:0,g:0,b:0,alpha:0}})
.png().toFile(path.join(D,out));
console.log(out, px+'px', fs.statSync(path.join(D,out)).size+'B');
}
})().catch(e=>{console.error('RASTER FAIL',e.message);process.exit(1);});
"""
def raster():
script = os.path.join(HERE, "_raster.cjs")
with open(script, "w", encoding="utf-8") as f:
f.write(NODE_RASTER)
p = subprocess.run(["node", script, OUT], cwd=REPO, capture_output=True, text=True)
os.remove(script)
if p.returncode != 0:
raise RuntimeError("sharp 栅格化失败:" + (p.stderr or p.stdout)[:400])
return p.stdout.strip()
def build_ico(pngs):
"""多尺寸 .ico:16/32/48。现网那份只封了 32 一档。"""
entries, blobs = [], []
off = 6 + 16 * len(pngs)
for name in pngs:
b = pngs[name]
m = re.search(r"(\d+)x(\d+)", name)
w = int(m.group(1))
# 字段序:width, height, colorCount, reserved, planes, bpp, size, offset。
# 上一版把 0 写进 height、把 w 写进 colorCount ⇒ 目录声称 16x256 且色彩数=16,
# 而内嵌 PNG 的 IHDR 是 16x16 —— 两个来源自相矛盾。height 必须等于 width,
# colorCount 对 32bpp 真彩应为 0(不是尺寸)。
entries.append(struct.pack("<BBBBHHII",
w % 256, w % 256, 0, 0, 1, 32, len(b), off))
off += len(b)
blobs.append(b)
return struct.pack("<HHH", 0, 1, len(pngs)) + b"".join(entries) + b"".join(blobs)
# ------------------------------------------------------------------ 校验
def check_file(path):
back = open(path, encoding="utf-8").read()
fails = []
svg_at = back.find("<svg")
if svg_at < 0:
return ["没有 <svg 根"], 0
try:
ET.fromstring(back[svg_at:])
except Exception as e: # noqa: BLE001
fails.append("XML 解析失败:%s" % e)
root = back[svg_at:back.find(">", svg_at)]
# 判据先剥注释、并放行 xmlns 命名空间 —— 否则两处都是我自己造的假红:
# ① 文件头的来源注释里写着「纯路径,无 <text>」,被字符串匹配当成真元素;
# ② 每个合法 SVG 都必须带 xmlns="http://www.w3.org/2000/svg",
# 拿 "http://" 一刀切会把命名空间判成"外部字体引用"。
code = re.sub(r"<!--.*?-->", "", back[svg_at:], flags=re.S)
if "<text" in code:
fails.append("含 <text> —— 交付资产必须纯路径")
# 命名空间 URI(xmlns / xlink)本身就是 http(s) URI,不是"外部资源引用"。
# 上一版用 endswith("w3.org/2000") 放行 —— 真实命名空间结尾是 /svg,
# 条件永不成立,于是 11 个合法文件被假红。判据过火和判据失灵一样贵。
urls = [u for u in re.findall(r'''https?://[^\s"']+''', code)
if "www.w3.org" not in u]
if urls:
fails.append("含外部 URL:%s" % " ".join(sorted(set(urls))[:3]))
if "evenodd" in code:
fails.append("含 fill-rule=evenodd")
nshape = sum(back.count("<" + t + " ") for t in ("path", "rect", "circle", "polygon"))
if nshape < 1:
fails.append("没有图形元素")
if not back.startswith("<?xml"):
fails.append("缺 XML 声明/来源注释头")
return fails, nshape
def check_png(path):
"""不跳过 PNG:解析签名 + IHDR 宽高,与文件名里那一档对账。
这能抓住"16 的文件其实是 512"、"resize 没生效"、"写坏了"三类。"""
b = open(path, "rb").read()
fails = []
if b[:8] != b"\x89PNG\r\n\x1a\n":
return ["PNG 签名不对"], None
if b[12:16] != b"IHDR":
return ["缺 IHDR"], None
w, h = struct.unpack(">II", b[16:24])
m = re.search(r"(\d+)", os.path.basename(path))
want = int(m.group(1)) if m else None
if want and (w != want or h != want):
fails.append("实际 %dx%d,文件名说 %d" % (w, h, want))
return fails, (w, h)
def check_ico(path):
b = open(path, "rb").read()
reserved, kind, n = struct.unpack("<HHH", b[:6])
if reserved != 0 or kind != 1:
return ["ICO 头不对:reserved=%d type=%d" % (reserved, kind)], 0
sizes, fails = [], []
for i in range(n):
e = b[6 + 16 * i: 6 + 16 * (i + 1)]
w, h, cc, res, planes, bpp, size, off = struct.unpack("<BBBBHHII", e)
W = w or 256
H = h or 256
# 真值来自内嵌 PNG 自己的 IHDR —— 目录与图像不一致就是坏文件
ihdr = None
if b[off:off + 8] == b"\x89PNG\r\n\x1a\n":
ihdr = struct.unpack(">II", b[off + 16:off + 24])
sizes.append((W, bpp, planes, off + size <= len(b)))
if res != 0:
fails.append("%dpx 项 reserved=%d(应为 0)" % (W, res))
if cc != 0:
fails.append("%dpx 项 colorCount=%d(32bpp 真彩应为 0,不是尺寸)" % (W, cc))
if ihdr is None:
fails.append("%dpx 项偏移处不是 PNG" % W)
else:
if (W, H) != ihdr:
fails.append("目录 %dx%d 与 PNG IHDR %dx%d 不一致" % (W, H, ihdr[0], ihdr[1]))
if off + size > len(b):
fails.append("%dpx 项数据越界" % W)
if n != 3:
fails.append("目录项 %d 个,期望 3(16/32/48)" % n)
for w, bpp, planes, inbounds in sizes:
if bpp != 32 or planes != 1:
fails.append("%dpx 项 bpp=%d planes=%d" % (w, bpp, planes))
return fails, [s[0] for s in sizes]
def selftest():
"""校验器自己的【双边】对照。只有负对照的校验器会一路报红还自我感觉良好 ——
这一刀就是:放行命名空间的条件写错,11 个合法文件被假红,而负对照照样"通过"。
脏样本:必须抓到 <text>、evenodd、真·外部 URL 三条;
干净样本:纯路径 + 带 xmlns + 注释里出现 <text> 与 URL ⇒ 必须零红。"""
dirty = os.path.join(OUT, "_selftest-dirty.svg")
with open(dirty, "w", encoding="utf-8") as f:
f.write('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10">'
'<text x="1" y="1" font-family="Ma Shan Zheng">睿</text>'
'<path d="M 0 0 L 8 0 L 8 8 Z" fill-rule="evenodd"/>'
'<circle cx="1" cy="1" r="1" fill="url(https://x.example/a.png)"/></svg>')
df, _n = check_file(dirty)
os.remove(dirty)
want = ["<text>", "evenodd", "外部 URL"]
hit = [w for w in want if any(w in x for x in df)]
clean = os.path.join(OUT, "_selftest-clean.svg")
with open(clean, "w", encoding="utf-8") as f:
f.write('<?xml version="1.0" encoding="UTF-8"?>\n'
'<!-- 注释里出现 <text> 和 https://fonts.googleapis.com 都不该被判红 -->\n'
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10">'
'<path d="M 0 0 L 8 0 L 8 8 Z" fill="#C41E3A"/></svg>')
cf, _cn = check_file(clean)
os.remove(clean)
return len(hit) == len(want) and not cf, df, cf
def manifest(png_out, ico_sizes):
rows = [
("lockup-primary.svg", "主锁定(上下)", "号 cap=名高×0.535;字距 33.62;左右差实测 0.00", "brand.py lockup_stack()"),
("lockup-primary-reversed.svg", "主锁定·反白", "深底/朱砂底用", "同上"),
("name-alone.svg", "名单独用(横排位)", "裁定②:横排不带英文", "lockup.name_row()"),
("name-alone-reversed.svg", "名单独用·反白", "裁定②", "同上"),
("lockup-vertical.svg", "竖排锁定", "竖列居中在名上方", "brand.py lockup_column()"),
("seal-master.svg", "简标·主刻版 ≥48px", "白文睿 0.78;48px 为实测信息下限", "jianbiao.py seal_wen()"),
("seal-16.svg", "简标·小刻版 ≤24px", "0.92 + 减地 0.5 设备像素;绑死 16px", "同上"),
("avatar-standard.svg", "头像·标准 full", "40px 保留率 93.1% 最优;face≤0.866 由真迹极径算出", "jianbiao.py avatar()"),
("avatar-ceremonial.svg", "头像·仪式版 ring2", "粗环 4.5% + 字面 0.68;仅大载体", "同上"),
("favicon.svg", "favicon(16px 专用几何)", "替换现网那份 <text>+Google 字体的", "同上"),
("favicon-16x16/32/48.png", "PNG 三档", "sharp 栅格,主刻版源", "_raster.cjs"),
("apple-touch-icon.png", "180px", "iOS", "同上"),
("icon-512x512.png", "512px", "PWA/Android", "同上"),
("favicon.ico", "多尺寸 16/32/48", "现网那份只有 32 一档", "本文件 struct 封装"),
]
txt = ["# 睿新致遠 / NOVALON · 交付资产清单", "",
"生成:`pack-assets.py`(第五十刀)。方向已裁定:**方案一 纯字标,无图形符号**。",
"", "| 文件 | 用途 | 关键判据(实测) | 来源 |", "|---|---|---|---|"]
for a, b, c, d in rows:
txt.append("| `%s` | %s | %s | `%s` |" % (a, b, c, d))
txt += ["", "## 三条必须随文件一起交接的裁定", "",
"1. **16px 承载『印』不承载『睿』**(裁定①A)。白文睿实测信息下限 48px;"
"16px 下五种刻法的封闭白保留率 61.9–73.6%,且白连通体从 4 个碎成 10–11 个 —— "
"栅格改写了字的骨架,不是糊,是「不是这个字了」。",
"2. **横排不带英文**(裁定②)。号压名的墨底会让号整体偏低 9.82 单位(名高 18.9%);"
"即便按墨中心对墨中心做到 0.00,那个位置也不需要两个读法。",
"3. **头像为标准/仪式两版**(裁定③)。细白环版已否 —— 2.8% 粗的环在 40px 只有 1.1px,"
"实测碎成 38 块。", "",
"## 现网 favicon 的两个真实缺陷(本刀实测)", "",
"① `public/favicon.svg` 用 `<text>` 写「睿新致遠」,`font-size=24` 在 viewBox 100 内 ⇒ "
"16px 渲染时每个汉字 3.84px,物理不可读。"
"② 其 `font-family` 首选 `Ma Shan Zheng` / `ZCOOL XiaoWei` —— 两个 Google 字体,"
"仓库既未安装也未嵌入,且项目规则禁止外部字体 CDN。"
"⇒ 本目录的 `favicon.svg` 是纯路径、16px 专用几何,PNG/ICO 由 sharp 栅格化产出。",
"", "## 栅格化与封装输出", "", "```", png_out, "", "favicon.ico 目录项:%s" % ico_sizes, "```", ""]
with open(os.path.join(OUT, "MANIFEST.md"), "w", encoding="utf-8") as f:
f.write("\n".join(txt))
def main():
build_set()
png_out = raster()
pngs = {}
for n in ("favicon-16x16.png", "favicon-32x32.png", "favicon-48x48.png"):
with open(os.path.join(OUT, n), "rb") as f:
pngs[n] = f.read()
ico = build_ico(pngs)
with open(os.path.join(OUT, "favicon.ico"), "wb") as f:
f.write(ico)
ifails, isizes = check_ico(os.path.join(OUT, "favicon.ico"))
bad = 0
names = sorted(x for x in os.listdir(OUT) if x.endswith((".svg", ".png", ".ico")))
for n in names:
size = os.path.getsize(os.path.join(OUT, n))
if n.endswith(".ico"):
continue
if n.endswith(".png"):
fails, dim = check_png(os.path.join(OUT, n))
else:
fails, dim = check_file(os.path.join(OUT, n))
if fails:
bad += 1
print("FAIL %-32s %6dB %s" % (n, size, ";".join(fails)))
else:
print("ok %-32s %6dB %s" % (n, size, dim))
if ifails:
bad += 1
print("FAIL favicon.ico %s" % ";".join(ifails))
else:
print("ok %-32s %6dB 目录项=%s px" % ("favicon.ico", len(ico), isizes))
ok_st, df, cf = selftest()
nhit = len([w for w in ("<text>", "evenodd", "外部 URL")
if any(w in x for x in df)])
print("自证 脏样本抓到 %d/3:%s | 干净样本零红:%s"
% (nhit, "✓" if nhit == 3 else "✗ %s" % df,
"✓" if not cf else "✗ 判据过火:%s" % cf))
if not ok_st:
bad += 1
manifest(png_out, isizes)
print("\n%d 个文件,红 %d 个" % (len(names), bad))
return 1 if bad else 0
if __name__ == "__main__":
sys.exit(main())