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 个文本/矢量件。
237 lines
14 KiB
Python
237 lines
14 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
favicon 改前 / 改后 实测(第五十刀 · 任务 #18 的验收面)
|
||
|
||
现网 public/favicon.svg 的两条缺陷,我不接受"看起来更清楚了"这种说法,
|
||
要拿同一把尺量:
|
||
|
||
尺 1 封闭白占比:favicon 是朱底白字,白才是笔画 ⇒ 封闭白就是"字还剩多少"。
|
||
尺 2 白连通体数:睿的骨架在 384px 基准下是 4–5 块,小尺寸一旦数目大变,
|
||
说明栅格改写了字,不是"糊"而是"不是这个字了"。
|
||
尺 3 不可读面积:16×16 里有多少像素根本没参与任何形状(既不是红也不是白)。
|
||
|
||
对照(答案由构造决定,缺了它这三个数就没有意义):
|
||
正对照 已知 25% 面积封闭白孔的红方块 ⇒ 必须读 ≈25%
|
||
负对照 实心红方块 ⇒ 必须读 ≈0%
|
||
剔除对照 贴边开口槽 ⇒ 封闭白必须 ≈0%(验洪水填充把背景剔干净了)
|
||
|
||
⚠ 位图必须走 data URI:file:// 页里 drawImage 一张 file:// 图,
|
||
之后 getImageData 会被判跨源抛 SecurityError(本项目踩过)。
|
||
"""
|
||
import base64
|
||
import os
|
||
import re
|
||
|
||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||
REPO = os.path.dirname(os.path.dirname(HERE))
|
||
NEW = os.path.join(HERE, "assets-delivery")
|
||
|
||
SPECS = [
|
||
("现网 favicon.svg", os.path.join(REPO, "public", "favicon.svg"), "svg"),
|
||
("新 favicon.svg(16px 专用几何)", os.path.join(NEW, "favicon.svg"), "svg"),
|
||
("新 favicon-16x16.png", os.path.join(NEW, "favicon-16x16.png"), "png"),
|
||
("新 favicon-32x32.png", os.path.join(NEW, "favicon-32x32.png"), "png"),
|
||
("简标·主刻版 @16(对照:不缩版会怎样)", os.path.join(NEW, "seal-master.svg"), "svg@16"),
|
||
("简标·主刻版 @384(基准)", os.path.join(NEW, "seal-master.svg"), "svg@384"),
|
||
]
|
||
|
||
|
||
def uri(path, kind):
|
||
b = open(path, "rb").read()
|
||
if kind.startswith("png"):
|
||
return "data:image/png;base64," + base64.b64encode(b).decode()
|
||
return "data:image/svg+xml;base64," + base64.b64encode(b).decode()
|
||
|
||
|
||
CSS = """
|
||
*{box-sizing:border-box}
|
||
body{margin:0;background:#F7F4EF;color:#4F4A42;font:16px/1.9 "Songti SC",Georgia,serif;padding:34px 30px 90px}
|
||
.wrap{max-width:1160px;margin:0 auto}
|
||
h1{font-size:32px;color:#26221E;margin:6px 0 12px}
|
||
h2{font-size:20px;color:#26221E;margin:38px 0 8px}
|
||
.ey{font:12px/1.4 "PingFang SC",sans-serif;letter-spacing:.18em;text-transform:uppercase;color:#8A8377}
|
||
.j{border-left:2px solid #C41E3A;padding:3px 0 3px 16px;margin:14px 0;color:#26221E;max-width:96ch}
|
||
.panel{background:#fff;border:1px solid #EFEAE1;padding:22px 24px;margin:10px 0}
|
||
.dark{background:#141210;border-color:#141210}
|
||
.row{display:flex;gap:26px;flex-wrap:wrap;align-items:flex-end}
|
||
.cell{text-align:center}
|
||
.lab{font:11.5px/1.6 "PingFang SC",sans-serif;color:#8A8377;margin-top:6px}
|
||
.dark .lab{color:#8A8377}
|
||
table{border-collapse:collapse;width:100%;font:13px/1.6 "PingFang SC",sans-serif;margin:12px 0}
|
||
th,td{padding:9px 11px;border-bottom:1px solid #C3BDB1;text-align:left}
|
||
th{font-size:11px;letter-spacing:.1em;text-transform:uppercase;color:#8A8377;font-weight:500}
|
||
td.n,th.n{text-align:right;font-variant-numeric:tabular-nums;white-space:nowrap}
|
||
.good{color:#0f7b3b;font-weight:700}.bad{color:#C41E3A;font-weight:700}.warn{color:#8a6100;font-weight:700}
|
||
pre{font:8px/1.05 ui-monospace,Menlo,monospace;background:#fff;padding:6px;border:1px solid #EFEAE1;display:inline-block;margin:0;text-align:left;white-space:pre}
|
||
.gate{position:sticky;top:0;z-index:9;background:#fff;border:1px solid #C3BDB1;padding:12px 16px;margin-bottom:10px}
|
||
img{image-rendering:pixelated}
|
||
"""
|
||
|
||
PROBE = r"""<script>
|
||
function isWht(p,a){return a>=40&&Math.hypot(p[0]-255,p[1]-255,p[2]-255)<110;}
|
||
function isInk(p,a){return a>=40&&Math.hypot(p[0]-255,p[1]-255,p[2]-255)>=110;}
|
||
function ras(src,size){return new Promise(r=>{const im=new Image(),cv=document.createElement('canvas');
|
||
cv.width=size;cv.height=size;const x=cv.getContext('2d',{willReadFrequently:true});
|
||
x.clearRect(0,0,size,size);
|
||
im.onload=()=>{try{x.drawImage(im,0,0,size,size);r(x.getImageData(0,0,size,size));}
|
||
catch(e){r({err:e.message});}};
|
||
im.onerror=()=>r({err:'load failed'});im.src=src;});}
|
||
function stats(im,px){const d=im.data;const w=new Uint8Array(px*px),k=new Uint8Array(px*px);
|
||
let other=0,trans=0;
|
||
for(let i=0;i<px*px;i++){const j=i*4;const a=d[j+3];
|
||
if(a<40){trans++;continue;}
|
||
if(isWht([d[j],d[j+1],d[j+2]],a))w[i]=1;
|
||
else if(isInk([d[j],d[j+1],d[j+2]],a))k[i]=1;
|
||
else other++;}
|
||
const bg=new Uint8Array(px*px),st=[];
|
||
const push=i=>{if(w[i]&&!bg[i]){bg[i]=1;st.push(i);}};
|
||
for(let x=0;x<px;x++){push(x);push((px-1)*px+x);}
|
||
for(let y=0;y<px;y++){push(y*px);push(y*px+px-1);}
|
||
while(st.length){const p=st.pop(),x=p%px,y=(p-x)/px;
|
||
for(const q of [x+1<px?p+1:p,x-1>=0?p-1:p,y+1<px?p+px:p,y-1>=0?p-px:p])
|
||
if(q!==p&&w[q]&&!bg[q]){bg[q]=1;st.push(q);}}
|
||
const seen=new Uint8Array(px*px);let comps=0,tot=0;
|
||
for(let i=0;i<px*px;i++){if(!w[i]||bg[i]||seen[i])continue;
|
||
let n=0;const s2=[i];seen[i]=1;
|
||
while(s2.length){const p=s2.pop();n++;const x=p%px,y=(p-x)/px;
|
||
for(const q of [x+1<px?p+1:p,x-1>=0?p-1:p,y+1<px?p+px:p,y-1>=0?p-px:p])
|
||
if(w[q]&&!bg[q]&&!seen[q]){seen[q]=1;s2.push(q);}}
|
||
comps++;tot+=n;}
|
||
return {comps:comps,white:100*tot/(px*px),ink:100*k.filter(Boolean).length/(px*px),
|
||
other:100*other/(px*px),trans:100*trans/(px*px)};}
|
||
function grid(im,px){const d=im.data,g=[];for(let y=0;y<px;y++){let s='';
|
||
for(let x=0;x<px;x++){const i=(y*px+x)*4;const R=d[i],G=d[i+1],B=d[i+2],A=d[i+3];
|
||
s+= A<40 ? ' ' : (isInk([R,G,B],A)?'M':(isWht([R,G,B],A)?'.':'o'));}g.push(s);}return g.join('\n');}
|
||
(async()=>{
|
||
const R={items:{},errs:[]};
|
||
for(const el of document.querySelectorAll('[data-fav]')){
|
||
const key=el.dataset.fav, px=+el.dataset.px;
|
||
const im=await ras(el.src,px);
|
||
if(im.err){R.errs.push(key+':'+im.err);R.items[key]={err:im.err};continue;}
|
||
R.items[key]={px:px,...stats(im,px),grid:(px<=48?grid(im,px):null)};
|
||
}
|
||
// 对照
|
||
const C={hole:R.items['CTRL_hole'],solid:R.items['CTRL_solid'],notch:R.items['CTRL_notch']};
|
||
const cOK=C.hole&&C.solid&&C.notch&&C.hole.white>=20&&C.hole.white<=30
|
||
&&C.solid.white<=1&&C.notch.white<=1;
|
||
const want=Object.keys(R.items), miss=want.filter(k=>!R.items[k]||R.items[k].err);
|
||
const g=document.getElementById('gate');
|
||
if(g)g.innerHTML='<b>口径自检</b> '
|
||
+(cOK?'<span class="good">三对照全部成立</span>':'<span class="bad">对照不成立 ⇒ 下面的数作废</span>')
|
||
+':正对照(已知 25% 孔)='+ (C.hole?C.hole.white.toFixed(1)+'%':'—')
|
||
+',负对照(实心)='+(C.solid?C.solid.white.toFixed(1)+'%':'—')
|
||
+',剔除对照(贴边槽)='+(C.notch?C.notch.white.toFixed(1)+'%':'—')
|
||
+'<br><span class="lab">应测 '+want.length+' 项,报错 '+miss.length+' 项;'
|
||
+(R.errs.length?'<span class="bad">'+R.errs.join(' / ')+'</span>':'无栅格错误')+'</span>';
|
||
const tb=document.getElementById('tbl');
|
||
if(tb){const keys=want.filter(k=>!k.startsWith('CTRL_'));
|
||
tb.innerHTML='<tr><th>样张</th><th class="n">栅格</th><th class="n">封闭白</th>'
|
||
+'<th class="n">白连通体</th><th class="n">朱底</th><th class="n">过渡/未参与</th><th>16px 像素图</th></tr>'
|
||
+keys.map(k=>{const o=R.items[k];
|
||
return '<tr><td>'+k+'</td><td class="n">'+o.px+'</td>'
|
||
+'<td class="n">'+o.white.toFixed(2)+'%</td>'
|
||
+'<td class="n">'+o.comps+'</td>'
|
||
+'<td class="n">'+o.ink.toFixed(1)+'%</td>'
|
||
+'<td class="n">'+(o.other+o.trans).toFixed(1)+'%</td>'
|
||
+'<td>'+(o.grid?'<pre>'+o.grid+'</pre>':'—')+'</td></tr>';}).join('');}
|
||
window.__fc={R:R,cOK:cOK};
|
||
const V=document.getElementById('verdict');
|
||
if(V){const o=R.items;
|
||
const g=k=>o[k]&&o[k].white!==undefined?o[k]:null;
|
||
const old=g('现网 favicon.svg'), nw=g('新 favicon.svg(16px 专用几何)'),
|
||
png=g('新 favicon-16x16.png'), base=g('简标·主刻版 @384(基准)'),
|
||
bad=g('简标·主刻版 @16(对照:不缩版会怎样)');
|
||
if(old&&nw&&png&&base&&bad){
|
||
V.innerHTML='<b>结论(本页实测,三对照全部成立才写这一段)。</b>'
|
||
+'现网那枚 16px 的封闭白只有 <b class="bad">'+old.white.toFixed(2)+'%</b>,'
|
||
+'白连通体 '+old.comps+' 个,还有 <b class="bad">'+(old.other+old.trans).toFixed(1)
|
||
+'%</b> 的像素既不是朱也不是白(<code><text></code> 在 16px 被抗锯齿抹平的痕迹)—— '
|
||
+'它的像素图就是一块实心红加两个杂点,<b>「睿新致遠」四个字在 favicon 里根本不存在</b>。'
|
||
+'<br>换成 16px 专用几何后:SVG <b class="good">'+nw.white.toFixed(2)+'%</b>、'
|
||
+'PNG <b class="good">'+png.white.toFixed(2)+'%</b>,噪声 <b class="good">0%</b>,'
|
||
+'白连通体 '+nw.comps+' 个。相对现网是 <b>'+(nw.white/old.white).toFixed(1)+' 倍</b>的白。'
|
||
+'<br>但要说清它没有做到的事:384px 基准下「睿」的白是 <b>'+base.comps+'</b> 个连通体,'
|
||
+'16px 下是 <b>'+nw.comps+'</b> 个 —— 骨架仍被栅格改写。'
|
||
+'这正是裁定①A 的原话:<b>16px 承载「印」这个概念,不承载可读的「睿」</b>。'
|
||
+'同一枚主刻版硬缩到 16px 只有 '+bad.white.toFixed(2)+'%,专用版 '+nw.white.toFixed(2)
|
||
+'% —— 两副刻版的差距在这里是可测的。';
|
||
}}
|
||
})();
|
||
</script>"""
|
||
|
||
|
||
def build():
|
||
P = ['<!DOCTYPE html><html lang="zh-CN"><head><meta charset="utf-8">'
|
||
'<meta name="viewport" content="width=device-width,initial-scale=1">'
|
||
'<title>favicon 改前改后</title><style>' + CSS + '</style></head><body><div class="wrap">']
|
||
P.append('<div class="gate" id="gate">口径自检:进行中…</div>')
|
||
P.append('<div class="ey">Cut 50 · 2026-10-14 · 任务 #18 验收 · 位图走 data URI · repo 零改动</div>')
|
||
P.append('<h1>favicon:现网那枚 vs 重做的这枚,同一把尺量</h1>')
|
||
P.append('<div class="j"><b>现网 <code>public/favicon.svg</code> 的两条真实缺陷。</b>'
|
||
'① 它用 <code><text></code> 写「睿新致遠」,<code>font-size=24</code> 装在 '
|
||
'viewBox 100 里 ⇒ 16px 渲染时每个汉字 <b>3.84px</b>,物理上不可能读;'
|
||
'② 它的首选字族 <code>Ma Shan Zheng</code> / <code>ZCOOL XiaoWei</code> 是 Google 字体,'
|
||
'仓库既没安装也没嵌入,而项目规则明令禁止外部字体 CDN —— '
|
||
'也就是说这枚 favicon 同时违反"本地字体"律和 16px 信息下限。'
|
||
'它恰好就是 #14 R2 那条规则在生产环境里的活标本。</div>')
|
||
|
||
P.append('<h2>同一把尺:封闭白 / 白连通体 / 未参与像素</h2>')
|
||
P.append('<div class="panel"><table id="tbl"><tr><td>测量中…</td></tr></table>'
|
||
'<div class="lab">「封闭白」= 被朱地围住、不与画布边框相连的白像素。'
|
||
'白文印里白才是笔画,所以这一项就是"字还剩多少"。'
|
||
'「未参与」= 既不算朱也不算白的过渡像素与透明像素 —— 越小越好,'
|
||
'大意味着细节全被抗锯齿抹成灰。</div></div>')
|
||
|
||
P.append('<div class="j" id="verdict">结论:测量中…</div>')
|
||
P.append('<h2>摆在一起看(明底 / 深底各一排)</h2>')
|
||
for dark in (False, True):
|
||
P.append('<div class="panel%s"><div class="row">' % (" dark" if dark else ""))
|
||
for label, path, kind in SPECS:
|
||
if kind == "png":
|
||
continue
|
||
px = 16
|
||
P.append('<div class="cell"><img src="%s" width="64" height="64" alt="%s">'
|
||
'<div class="lab">%s<br>64px 显示(源 16px 栅格)</div></div>'
|
||
% (uri(path, "svg"), label, label))
|
||
P.append('</div></div>')
|
||
|
||
for tag, inner in [("CTRL_hole", '<rect width="100" height="100" fill="#C41E3A"/>'
|
||
'<rect x="25" y="25" width="50" height="50" fill="#FFFFFF"/>'),
|
||
("CTRL_solid", '<rect width="100" height="100" fill="#C41E3A"/>'),
|
||
("CTRL_notch", '<path d="M 0 0 L 100 0 L 100 30 L 60 30 L 60 70 L 100 70 '
|
||
'L 100 100 L 0 100 Z" fill="#C41E3A"/>')]:
|
||
svg = ('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">%s</svg>' % inner)
|
||
P.append('<img data-fav="%s" data-px="16" style="display:none" src="data:image/svg+xml;base64,%s">'
|
||
% (tag, base64.b64encode(svg.encode()).decode()))
|
||
|
||
for label, path, kind in SPECS:
|
||
px = 16
|
||
if kind.startswith("svg@"):
|
||
px = int(kind.split("@")[1])
|
||
src = uri(path, "svg")
|
||
elif kind == "png":
|
||
px = int(re.search(r"(\d+)", os.path.basename(path)).group(1))
|
||
src = uri(path, "png")
|
||
else:
|
||
src = uri(path, "svg")
|
||
P.append('<img data-fav="%s" data-px="%d" style="display:none" src="%s">'
|
||
% (label, px, src))
|
||
|
||
P.append('<footer style="margin-top:44px;padding-top:14px;border-top:1px solid #C3BDB1;'
|
||
'font:12.5px/1.7 PingFang SC,sans-serif;color:#8A8377">'
|
||
'生成器 <code>favicon-check.py</code> · 样张直接读 <code>assets-delivery/</code> 与 '
|
||
'<code>public/favicon.svg</code> 磁盘上的真文件(base64 内嵌,不走 file:// 取像素)· '
|
||
'三个对照与主表同轮测量 · repo 零改动</footer>')
|
||
P.append(PROBE)
|
||
P.append('</div></body></html>')
|
||
return "".join(P)
|
||
|
||
|
||
|
||
if __name__ == "__main__":
|
||
html = build()
|
||
with open(os.path.join(HERE, "favicon-check.html"), "w", encoding="utf-8") as f:
|
||
f.write(html)
|
||
print("favicon-check.html %s B" % format(len(html.encode("utf-8")), ","))
|