From a91133a7b0de9e0874f1200f1e61f757ddafdff0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 3 Feb 2011 20:38:49 -0700 Subject: [PATCH] Workaround for bug in Qt on OS X that caused crashes when reading metedata from two or more EPUB files with HTML covers that used embedded fonts. Now the embedded fonts are ignored on OS X. Fixes #8643 (Calibre fails to read metadata when importing more than 1 epub book) --- src/calibre/ebooks/__init__.py | 6 +++--- src/calibre/ebooks/metadata/epub.py | 10 +++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/calibre/ebooks/__init__.py b/src/calibre/ebooks/__init__.py index da4d1178eb..4dc97f43ed 100644 --- a/src/calibre/ebooks/__init__.py +++ b/src/calibre/ebooks/__init__.py @@ -113,7 +113,7 @@ def render_html_svg_workaround(path_to_html, log, width=590, height=750): def render_html(path_to_html, width=590, height=750, as_xhtml=True): from PyQt4.QtWebKit import QWebPage - from PyQt4.Qt import QEventLoop, QPalette, Qt, SIGNAL, QUrl, QSize + from PyQt4.Qt import QEventLoop, QPalette, Qt, QUrl, QSize from calibre.gui2 import is_ok_to_use_qt if not is_ok_to_use_qt(): return None path_to_html = os.path.abspath(path_to_html) @@ -127,8 +127,7 @@ def render_html(path_to_html, width=590, height=750, as_xhtml=True): page.mainFrame().setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff) loop = QEventLoop() renderer = HTMLRenderer(page, loop) - page.connect(page, SIGNAL('loadFinished(bool)'), renderer, - Qt.QueuedConnection) + page.loadFinished.connect(renderer, type=Qt.QueuedConnection) if as_xhtml: page.mainFrame().setContent(open(path_to_html, 'rb').read(), 'application/xhtml+xml', QUrl.fromLocalFile(path_to_html)) @@ -136,6 +135,7 @@ def render_html(path_to_html, width=590, height=750, as_xhtml=True): page.mainFrame().load(QUrl.fromLocalFile(path_to_html)) loop.exec_() renderer.loop = renderer.page = None + page.loadFinished.disconnect() del page del loop if isinstance(renderer.exception, ParserError) and as_xhtml: diff --git a/src/calibre/ebooks/metadata/epub.py b/src/calibre/ebooks/metadata/epub.py index e1712f3668..f19b89eb88 100644 --- a/src/calibre/ebooks/metadata/epub.py +++ b/src/calibre/ebooks/metadata/epub.py @@ -14,7 +14,8 @@ from calibre.ebooks.BeautifulSoup import BeautifulStoneSoup from calibre.ebooks.metadata import MetaInformation from calibre.ebooks.metadata.opf2 import OPF from calibre.ptempfile import TemporaryDirectory, PersistentTemporaryFile -from calibre import CurrentDir +from calibre import CurrentDir, walk +from calibre.constants import isosx class EPubException(Exception): pass @@ -159,6 +160,13 @@ def get_cover(opf, opf_path, stream, reader=None): with TemporaryDirectory('_epub_meta') as tdir: with CurrentDir(tdir): zf.extractall() + if isosx: + # On OS X trying to render an HTML cover which uses embedded + # fonts more than once in the same process causes a crash in Qt + # so be safe and remove the fonts. + for f in walk('.'): + if os.path.splitext(f)[1].lower() in ('.ttf', '.otf'): + os.remove(f) opf_path = opf_path.replace('/', os.sep) cpage = os.path.join(tdir, os.path.dirname(opf_path), cpage) if not os.path.exists(cpage):