mirror of
https://github.com/2234839/web-font.git
synced 2026-09-04 23:02:27 +08:00
perf(woff2): transformGlyfAndLoca simple glyph 跳过 bbox 读取
原每个 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) <noreply@anthropic.com>
This commit is contained in:
parent
32afa17b5c
commit
e1190eeb82
12
vendor/fonteditor-core/woff2/woff2-encode.js
vendored
12
vendor/fonteditor-core/woff2/woff2-encode.js
vendored
@ -254,13 +254,15 @@ function transformGlyfAndLoca(glyfData, locaData, indexFormat, numGlyphs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const numberOfContours = readI16(glyfData, glyphStart);
|
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) {
|
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 compOff = glyphStart + 10;
|
||||||
let haveInstructions = false;
|
let haveInstructions = false;
|
||||||
let instrLength = 0;
|
let instrLength = 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user