diff --git a/assets/webui/ofdgo.js b/assets/webui/ofdgo.js index fc731f0..762ad58 100644 --- a/assets/webui/ofdgo.js +++ b/assets/webui/ofdgo.js @@ -4423,11 +4423,13 @@ function updateTextFonts(item, refresh = false) { if (document.activeElement === el.textFont && fontPicker.open) return; state.textFontID = key; state.textFonts = editorFonts(null); - for (const [font, face] of rich.faces) { + for (const font of rich.faces.keys()) { const choice = rich.choices?.get(font); - state.textFonts.unshift(choice || { id: `embedded:${font}`, name: font === rich.editing.item.font ? rich.editing.item.fontName || font : face.family, embedded: !rich.imports.has(font), richKey: font }); + state.textFonts.unshift({ ...(choice || { id: `embedded:${font}`, + name: state.doc?.fonts?.find(value => value.id === font)?.fontName || (font === rich.editing.item.font ? rich.editing.item.fontName : "") || font, + embedded: !rich.imports.has(font) }), richKey: font }); } - fontPicker.setFonts(state.textFonts, id === undefined ? null : state.textFonts.find(font => font.richKey === id || rich.choices?.get(id) === font)); + fontPicker.setFonts(state.textFonts, id === undefined ? null : state.textFonts.find(font => font.richKey === id)); el.textFont.placeholder = id === undefined ? "混合" : ""; } return; @@ -4479,7 +4481,7 @@ async function changeTextFont() { await face.load(); if (!isForegroundDocument(tab) || openSeq !== state.openSeq || canvasEditor.input !== editing) return; editing.fontChoice = font; - if (item.draft) state.textDefaults.fontChoice = font; + if (item.draft && !font.richKey) state.textDefaults.fontChoice = font; if (editing.rich) { const key = font.richKey || (font.embedded ? font.id.slice(9) : `temp-font-${crypto.randomUUID()}`); editing.rich.choices ||= new Map(); diff --git a/assets/webui/ofdgo_edit.js b/assets/webui/ofdgo_edit.js index b054220..f4ee9cb 100644 --- a/assets/webui/ofdgo_edit.js +++ b/assets/webui/ofdgo_edit.js @@ -413,7 +413,9 @@ export class RichTextSession { } setFont(face, data, key) { key ||= `temp-font-${crypto.randomUUID()}`; + const previous = this.faces.get(key); this.faces.set(key, face); + if (previous && ![...this.faces.values()].includes(previous)) document.fonts.delete(previous); if (data) this.imports.set(key, data); document.fonts.add(face); this.apply({ font: key }); diff --git a/assets/webui/ofdgo_font.js b/assets/webui/ofdgo_font.js index f3cc1ff..9380b01 100644 --- a/assets/webui/ofdgo_font.js +++ b/assets/webui/ofdgo_font.js @@ -31,7 +31,7 @@ export class FontPicker { const name = (font.fullName || font.name).normalize("NFKC").toLocaleLowerCase(); this.names.set(name, (this.names.get(name) || 0) + 1); } - const key = font => font?.id || font?.postscriptName; + const key = font => font?.richKey || font?.id || font?.postscriptName; this.value = !fonts.length ? "" : selected === null ? "-1" : String(Math.max(0, fonts.findIndex(font => key(font) === key(selected)))); this.restore(); }