From 5c6ec901da76a4af5c41b045ef2a74f46a1041b2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 2 Dec 2013 20:46:29 +0530 Subject: [PATCH] Preload embedded fonts so that the preview panel works off the bat --- src/calibre/gui2/tweak_book/boss.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index f1061f2cbe..f5ce95f5c3 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -18,7 +18,7 @@ from calibre import prints, prepare_string_for_xml from calibre.ptempfile import PersistentTemporaryDirectory from calibre.ebooks.oeb.base import urlnormalize from calibre.ebooks.oeb.polish.main import SUPPORTED, tweak_polish -from calibre.ebooks.oeb.polish.container import get_container as _gc, clone_container, guess_type +from calibre.ebooks.oeb.polish.container import get_container as _gc, clone_container, guess_type, OEB_FONTS from calibre.ebooks.oeb.polish.cover import mark_as_cover, mark_as_titlepage from calibre.ebooks.oeb.polish.pretty import fix_all_html, pretty_all from calibre.ebooks.oeb.polish.replace import rename_files, replace_file @@ -36,7 +36,16 @@ from calibre.gui2.tweak_book.preferences import Preferences def get_container(*args, **kwargs): kwargs['tweak_mode'] = True - return _gc(*args, **kwargs) + container = _gc(*args, **kwargs) + # We preload the embedded fonts from this book, so that the preview panel + # works + font_cache.remove_fonts() + for name, mt in container.mime_map.iteritems(): + if mt in OEB_FONTS and container.exists(name): + with container.open(name, 'rb') as f: + raw = f.read() + font_cache.add_font(raw) + return container class BusyCursor(object): @@ -167,7 +176,6 @@ class Boss(QObject): parse_worker.clear() container = job.result set_current_container(container) - font_cache.remove_fonts() self.current_metadata = self.gui.current_metadata = container.mi self.global_undo.open_book(container) self.gui.update_window_title()