From 5cd412a7d5d7120481a002e7d438ed72cabf5a37 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 15 Dec 2010 18:34:03 -0700 Subject: [PATCH] EPUB metadata: When rendering the first page as cover, render it as XHTML. This means that if the EPUB is not valid XHTML the cover wont be rendered correctly. Necessary for rendering of SVG elements in the page when it does not have an .xhtml extension. Fixes #7909 (Issue with HarperCollins EPUB Covers) --- src/calibre/ebooks/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/__init__.py b/src/calibre/ebooks/__init__.py index 9bdf937dd1..b4619551b7 100644 --- a/src/calibre/ebooks/__init__.py +++ b/src/calibre/ebooks/__init__.py @@ -122,7 +122,11 @@ def render_html(path_to_html, width=590, height=750): renderer = HTMLRenderer(page, loop) page.connect(page, SIGNAL('loadFinished(bool)'), renderer, Qt.QueuedConnection) - page.mainFrame().load(QUrl.fromLocalFile(path_to_html)) + # Can't use load as if the extension of path is not xhtml + # then it won't render SVG correctly, so set mimetype + # explicitly + page.mainFrame().setContent(open(path_to_html, 'rb').read(), + 'application/xhtml+xml', QUrl.fromLocalFile(path_to_html)) loop.exec_() renderer.loop = renderer.page = None del page