From ed411b0cc9ddd6c760867204903fae3b07b44f76 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 12 Nov 2018 16:30:11 +1000 Subject: [PATCH] add hack for font name consistency issue https://anki.tenderapp.com/discussions/ankidesktop/30785-bug-font-not-applying-to-japanese-characters --- aqt/editor.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/aqt/editor.py b/aqt/editor.py index 1f20b79e9..86d1dcdc7 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -17,7 +17,7 @@ from aqt.qt import * from anki.utils import stripHTML, isWin, isMac, namedtmp, json, stripHTMLMedia, \ checksum import anki.sound -from anki.hooks import runHook, runFilter +from anki.hooks import runHook, runFilter, addHook from aqt.sound import getAudio from aqt.webview import AnkiWebView from aqt.utils import shortcut, showInfo, showWarning, getFile, \ @@ -331,7 +331,8 @@ class Editor: oncallback) def fonts(self): - return [(f['font'], f['size'], f['rtl']) + return [(runFilter("mungeEditingFontName", f['font']), + f['size'], f['rtl']) for f in self.note.model()['flds']] def saveNow(self, callback, keepFocus=False): @@ -983,3 +984,10 @@ class EditorWebView(AnkiWebView): a.triggered.connect(self.onPaste) runHook("EditorWebView.contextMenuEvent", self, m) m.popup(QCursor.pos()) + +# QFont returns "Kozuka Gothic Pro L" but WebEngine expects "Kozuka Gothic Pro" +# - there may be other cases like a trailing 'Bold' that need fixing, but will +# wait for further reports first. +def fontMungeHack(font): + return re.sub(" L$", "", font) +addHook("mungeEditingFontName", fontMungeHack)