From 423393107dcba2ec8c686b5e3bcd64c2d808b067 Mon Sep 17 00:00:00 2001 From: Abdo Date: Wed, 28 May 2025 06:36:40 +0300 Subject: [PATCH] Move fontMungeHack() --- qt/aqt/editor.py | 16 ---------------- ts/routes/editor/NoteEditor.svelte | 10 ++++++++-- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index dd8b2828e..b3b647a8b 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -574,12 +574,6 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too initiator=self ) - def fonts(self) -> list[tuple[str, int, bool]]: - return [ - (gui_hooks.editor_will_use_font_for_field(f["font"]), f["size"], f["rtl"]) - for f in self.note_type()["flds"] - ] - def call_after_note_saved( self, callback: Callable, keepFocus: bool = False ) -> None: @@ -1634,16 +1628,6 @@ class EditorWebView(AnkiWebView): return clipboard -# QFont returns "Kozuka Gothic Pro L" but WebEngine expects "Kozuka Gothic Pro Light" -# - there may be other cases like a trailing 'Bold' that need fixing, but will -# wait for further reports first. -def fontMungeHack(font: str) -> str: - return re.sub(" L$", " Light", font) - - -gui_hooks.editor_will_use_font_for_field.append(fontMungeHack) - - def set_cloze_button(editor: Editor) -> None: action = "show" if editor.note_type()["type"] == MODEL_CLOZE else "hide" editor.web.eval( diff --git a/ts/routes/editor/NoteEditor.svelte b/ts/routes/editor/NoteEditor.svelte index 821be1bc6..4d937f824 100644 --- a/ts/routes/editor/NoteEditor.svelte +++ b/ts/routes/editor/NoteEditor.svelte @@ -185,6 +185,13 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html const fields = clearableArray(); + // QFont returns "Kozuka Gothic Pro L" but WebEngine expects "Kozuka Gothic Pro Light" + // - there may be other cases like a trailing 'Bold' that need fixing, but will + // wait for further reports first. + function mungeFontName(fontName: string): string { + return fontName.replace(/ L$/g, " Light"); + } + export function setFonts(fs: [string, number, boolean][]): void { fonts = fs; } @@ -620,10 +627,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html setDescriptions( notetype.fields.map((field) => field.config?.description ?? ""), ); - // TODO: gui_hooks.editor_will_use_font_for_field setFonts( notetype.fields.map((field) => [ - field.config?.fontName ?? "", + mungeFontName(field.config?.fontName ?? ""), field.config?.fontSize ?? 16, field.config?.rtl ?? false, ]),