mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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)
This commit is contained in:
parent
8749611440
commit
a91133a7b0
@ -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:
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user