feat(内存占用): 复用SVG字体资源,减少多页阅读的传输量和内存开销
build.yaml / build (push) Successful in 41s

This commit is contained in:
xiaoqidun committed 2026-09-13 16:13:51 +08:00
1 parent 481b21c7ce
commit 78b34713cc
5 files changed
+165 -2

No files matched your search

+28
View File
@@ -53,6 +53,7 @@ const state = {
continuous: false,
renderAnnotations: true,
pageCache: new Map(),
svgFonts: new Map(),
selectedPages: new Set(),
pageInFlight: new Map(),
pageRenderQueue: [],
@@ -1509,6 +1510,10 @@ function renderPageFlow() {
}
function resetPageFlow() {
for (const font of state.svgFonts.values()) {
document.fonts.delete(font);
}
state.svgFonts.clear();
state.pageCache.clear();
state.selectedPages.clear();
state.visiblePages.clear();
@@ -1657,6 +1662,7 @@ async function processPageRenderQueue() {
continue;
}
const page = await callWASM("ofdgoRenderPage", task.index);
await loadSVGFonts(page.fonts, task.openSeq);
if (task.openSeq === state.openSeq) {
state.pageCache.set(task.index, page);
}
@@ -1672,6 +1678,28 @@ async function processPageRenderQueue() {
}
}
async function loadSVGFonts(fonts, openSeq) {
for (const font of fonts) {
if (openSeq !== state.openSeq) {
return;
}
if (state.svgFonts.has(font.name)) {
continue;
}
const data = await callWASM("ofdgoSVGFontData", font.name);
if (openSeq !== state.openSeq) {
return;
}
const face = new FontFace(font.name, data.bytes, { weight: String(font.weight), style: font.style });
await face.load();
if (openSeq !== state.openSeq) {
return;
}
document.fonts.add(face);
state.svgFonts.set(font.name, face);
}
}
function comparePageRenderTask(a, b) {
return a.priority - b.priority || Math.abs(a.index - state.pageIndex) - Math.abs(b.index - state.pageIndex);
}