fix(问题修复): 修复字体框闪动及换字体报错
build.yaml / build (push) Successful in 45s

This commit is contained in:
xiaoqidun committed 2026-10-31 23:49:19 +08:00
1 parent 1d40268c9f
commit f6f45a2657
3 files changed
+27 -15

No files matched your search

+4 -2
View File
@@ -4927,7 +4927,8 @@ function updateTextFonts(item, refresh = false, preserve = false) {
embedded: !rich.imports.has(font) }), richKey: font }); embedded: !rich.imports.has(font) }), richKey: font });
} }
fontPicker.setFonts(state.textFonts, id === undefined ? null : state.textFonts.find(font => font.richKey === id), preserve); fontPicker.setFonts(state.textFonts, id === undefined ? null : state.textFonts.find(font => font.richKey === id), preserve);
el.textFont.placeholder = id === undefined ? "混合" : ""; const placeholder = id === undefined ? "混合" : "";
if (el.textFont.placeholder !== placeholder) el.textFont.placeholder = placeholder;
} }
return; return;
} }
@@ -4944,7 +4945,8 @@ function updateTextFonts(item, refresh = false, preserve = false) {
} }
const mixed = (item?.items || item?.richText) && !id; const mixed = (item?.items || item?.richText) && !id;
fontPicker.setFonts(state.textFonts, mixed ? null : selected || (state.textDefaults.fontChoice === null ? null : state.textFonts[0]), preserve); fontPicker.setFonts(state.textFonts, mixed ? null : selected || (state.textDefaults.fontChoice === null ? null : state.textFonts[0]), preserve);
el.textFont.placeholder = mixed ? "混合" : ""; const placeholder = mixed ? "混合" : "";
if (el.textFont.placeholder !== placeholder) el.textFont.placeholder = placeholder;
if (!id && !item?.items && !item?.richText) state.textDefaults.fontChoice = state.textFonts[Number(fontPicker.value)] || (state.textDefaults.fontChoice === null ? null : undefined); if (!id && !item?.items && !item?.richText) state.textDefaults.fontChoice = state.textFonts[Number(fontPicker.value)] || (state.textDefaults.fontChoice === null ? null : undefined);
} }
} }
+9 -6
View File
@@ -57,8 +57,9 @@ export class FontPicker {
} }
setDisabled(disabled) { setDisabled(disabled) {
this.input.disabled = this.toggle.disabled = disabled; if (this.input.disabled !== disabled) this.input.disabled = disabled;
if (disabled) this.close(); if (this.toggle.disabled !== disabled) this.toggle.disabled = disabled;
if (disabled && this.open) this.close();
} }
restore() { restore() {
@@ -68,8 +69,9 @@ export class FontPicker {
this.input.value = value; this.input.value = value;
if (document.activeElement === this.input) this.input.select(); if (document.activeElement === this.input) this.input.select();
} }
this.input.scrollLeft = 0; if (this.input.scrollLeft) this.input.scrollLeft = 0;
this.input.title = font ? [this.input.value, this.sourceLabel(font)].filter(Boolean).join(" · ") : ""; const title = font ? [this.input.value, this.sourceLabel(font)].filter(Boolean).join(" · ") : "";
if (this.input.title !== title) this.input.title = title;
} }
sourceLabel(font) { sourceLabel(font) {
@@ -307,11 +309,12 @@ export class FontManager {
async queryLocal() { async queryLocal() {
try { try {
const available = this.host ? await this.host.fonts() : await window.queryLocalFonts(); const available = this.host ? await this.host.fonts() : await window.queryLocalFonts();
this.catalog = available; this.catalog = this.host ? available : available.map(font => ({ family: font.family, fullName: font.fullName,
postscriptName: font.postscriptName, style: font.style, blob: () => font.blob() }));
this.catalogLoaded = true; this.catalogLoaded = true;
this.permission = "granted"; this.permission = "granted";
this.onPermissionChange(); this.onPermissionChange();
return available; return this.catalog;
} catch (err) { } catch (err) {
if (err && err.name === "NotAllowedError") { if (err && err.name === "NotAllowedError") {
this.permission = "denied"; this.permission = "denied";
+14 -7
View File
@@ -758,13 +758,7 @@ func (s *Session) Details() DocumentDetails {
} }
info.SignatureCount = len(info.Signatures) info.SignatureCount = len(info.Signatures)
if fonts, err := s.Renderer.DeclaredFontInfos(); err == nil { if fonts, err := s.Renderer.DeclaredFontInfos(); err == nil {
for index := range fonts { s.localizeFontInfos(fonts)
if fonts[index].Embedded {
if face, err := s.Reader.FontFace(fonts[index].ID, 3, 0x0804); err == nil {
fonts[index].MatchedFace = face
}
}
}
info.Fonts = fonts info.Fonts = fonts
info.FontCount = len(fonts) info.FontCount = len(fonts)
} }
@@ -1017,11 +1011,24 @@ func (s *Session) scanFontInfo() bool {
return false return false
} }
s.fontInfos, _ = s.fontScan.Infos() s.fontInfos, _ = s.fontScan.Infos()
s.localizeFontInfos(s.fontInfos)
s.fontsRead = true s.fontsRead = true
s.fontScan = nil s.fontScan = nil
return true return true
} }
// localizeFontInfos 统一内嵌字体在概要和完整统计中的中文名称
// 入参: fonts 当前文档的字体诊断信息
func (s *Session) localizeFontInfos(fonts []FontInfo) {
for index := range fonts {
if fonts[index].Embedded {
if face, err := s.Reader.FontFace(fonts[index].ID, 3, 0x0804); err == nil {
fonts[index].MatchedFace = face
}
}
}
}
// scanFontInfoBatch 为大文档批量统计字体,限制每次处理的页数与耗时 // scanFontInfoBatch 为大文档批量统计字体,限制每次处理的页数与耗时
// 返回: bool 是否完成 // 返回: bool 是否完成
func (s *Session) scanFontInfoBatch() bool { func (s *Session) scanFontInfoBatch() bool {