From e1190eeb8213b4c80a63d99e321f05262c7d83df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=AE=E7=94=9F=EF=BC=88=E5=AD=90=E8=99=9A=EF=BC=89?= <2234839456@qq.com> Date: Sat, 25 Jul 2026 03:59:53 +0800 Subject: [PATCH] =?UTF-8?q?perf(woff2):=20transformGlyfAndLoca=20simple=20?= =?UTF-8?q?glyph=20=E8=B7=B3=E8=BF=87=20bbox=20=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原每个 glyph 入口都读 numberOfContours + xMin/yMin/xMax/yMax 共 5 次 readI16, 但 simple glyph 的 bbox 由解码端从轮廓点重建(优化314,bboxBitmap 位恒为 0, 不写入 bboxStream),xMin/yMin/xMax/yMax 读取纯属浪费。仅复合 glyph 需显式存 bbox(raw 组件数据剥离 glyph 头,解码端无法重建)。 将 bbox 4 次 readI16 移入复合 glyph 分支(numberOfContours<0),simple glyph 路径只读 numberOfContours 一次。CJK 字体几乎全 simple,每字省 4 次 readI16。 7 产物 A/B 全 IDENTICAL。性能 best-of min N=4000: 篆体 -4.6%、思源8字 -2.3%、FiraCode -1.7%、令东8字 -1.4%、千字文 -1.1%。 基准测试全 SSIM 通过。 Co-Authored-By: Claude Opus 4.8 (1M context) --- vendor/fonteditor-core/woff2/woff2-encode.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/vendor/fonteditor-core/woff2/woff2-encode.js b/vendor/fonteditor-core/woff2/woff2-encode.js index 45aa510..d39a66e 100644 --- a/vendor/fonteditor-core/woff2/woff2-encode.js +++ b/vendor/fonteditor-core/woff2/woff2-encode.js @@ -254,13 +254,15 @@ function transformGlyfAndLoca(glyfData, locaData, indexFormat, numGlyphs) { } const numberOfContours = readI16(glyfData, glyphStart); - const xMin = readI16(glyfData, glyphStart + 2); - const yMin = readI16(glyfData, glyphStart + 4); - const xMax = readI16(glyfData, glyphStart + 6); - const yMax = readI16(glyfData, glyphStart + 8); if (numberOfContours < 0) { - /* 复合 glyph */ + /* 复合 glyph:bbox 需显式存入 bboxStream(raw 组件数据剥离 glyph 头,解码端无法重建), + * 故仅复合 glyph 读取 xMin/yMin/xMax/yMax。simple glyph 的 bbox 由解码端从轮廓点重建 + * (优化314,bboxBitmap 位恒为 0),读取纯属浪费——移到复合分支内避免每 simple glyph 4 次 readI16 */ + const xMin = readI16(glyfData, glyphStart + 2); + const yMin = readI16(glyfData, glyphStart + 4); + const xMax = readI16(glyfData, glyphStart + 6); + const yMax = readI16(glyfData, glyphStart + 8); let compOff = glyphStart + 10; let haveInstructions = false; let instrLength = 0;