From e5d7f577c7f751c3d4f96c2d79863cd3def6fefa Mon Sep 17 00:00:00 2001 From: xiaoqidun Date: Wed, 28 Oct 2026 21:59:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=AD=97=E4=BD=93=E5=A4=84=E7=90=86):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AD=97=E4=BD=93=E7=BB=AD=E5=BB=BA=E3=80=81?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E4=B8=8E=E5=A4=8D=E5=88=B6=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/webui/ofdgo.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/assets/webui/ofdgo.js b/assets/webui/ofdgo.js index 3b45359..4ae6794 100644 --- a/assets/webui/ofdgo.js +++ b/assets/webui/ofdgo.js @@ -4443,9 +4443,10 @@ async function beginCanvasText(index, box, surface, page) { const item = { ...state.textDefaults, ...box, wrap: Boolean(box.wrap), index, page, surface, node, text: "", draft: true, fontData: data }; const model = { ...richTextModel(item), autoWidth: !box.wrap }; - const key = `temp-font-${crypto.randomUUID()}`; + const key = font.embedded ? font.id.slice(9) : `temp-font-${crypto.randomUUID()}`; + const embedded = font.embedded && state.doc?.fonts?.some(font => font.id === key && font.embedded); model.runs[0].format.font = key; - canvasEditor.editText(item, face, null, { model, faces: new Map([[key, face]]), fonts: [{ key, data }] }); + canvasEditor.editText(item, face, null, { model, faces: new Map([[key, face]]), fonts: embedded ? [] : [{ key, data }], resources: new Map([[key, data]]) }); } catch (err) { if (isForegroundDocument(tab) && openSeq === state.openSeq) showError(err, false); } finally { @@ -4608,8 +4609,12 @@ async function prepareTextFaces(tab, runs, font, key, value, rich) { const candidates = [...choices.values()]; for (const choice of candidates) { if (choice.menuFamily || ![...originals.values()].some(font => textFontIdentity(font || {}) === textFontIdentity(choice)) && (!font || textFontIdentity(choice) !== textFontIdentity(font))) continue; - const [metadata] = await callWASM("ofdgoFontFaces", await read(choice)); - if (metadata) Object.assign(choice, metadata, { index: choice.index }); + try { + const [metadata] = await callWASM("ofdgoFontFaces", await read(choice)); + if (metadata) Object.assign(choice, metadata, { index: choice.index }); + } catch (error) { + if (!current() || !font || textFontIdentity(choice) === textFontIdentity(font)) throw error; + } } const groups = await groupTextFonts(candidates, tab), changes = new Map(), prepared = new Map(); for (const run of runs) { @@ -4675,7 +4680,9 @@ async function changeTextFace(font, key, value) { tab.editTask = busy; setBusy(true, "", 0, "", tab); try { - const fonts = fontManager.editorFonts().filter(font => font.familyKey === source.familyKey && textFontSource(font) === textFontSource(source)), groups = await groupTextFonts(fonts, tab); + const available = source.embedded ? (state.doc?.fonts || []).filter(font => font.embedded || font.status === "matched").map(font => documentFontChoice(font.id)) : fontManager.editorFonts(); + const fonts = [source, ...available.filter(font => textFontIdentity(font) !== textFontIdentity(source))].filter(font => font.familyKey === source.familyKey && textFontSource(font) === textFontSource(source)); + const groups = await groupTextFonts(fonts, tab); if (!current()) return; const index = fonts.findIndex(choice => textFontIdentity(choice) === textFontIdentity(source)); const faces = (groups.find(group => group.includes(index)) || []).map(index => fonts[index]); @@ -4726,6 +4733,7 @@ async function changeTextFace(font, key, value) { rich.faces.set(entry.key, entry.face); if (previous && ![...rich.faces.values()].includes(previous)) document.fonts.delete(previous); if (!entry.choice.embedded) rich.imports.set(entry.key, entry.data); + else rich.resources.set(entry.key, entry.data); rich.choices.set(entry.key, entry.choice); document.fonts.add(entry.face); }