25
25
BOOK_EXTENSIONS = ['lrf', 'rar', 'zip', 'rtf', 'lit', 'txt', 'htm', 'xhtm',
26
'html', 'xhtml', 'pdf', 'prc', 'mobi', 'azw',
26
'html', 'xhtml', 'pdf', 'pdb', 'prc', 'mobi', 'azw', 'doc',
27
27
'epub', 'fb2', 'djvu', 'lrx', 'cbr', 'cbz', 'oebzip',
28
'rb', 'imp', 'odt', 'chm', 'tpz', 'azw1']
30
30
class HTMLRenderer(object):
60
def extract_cover_from_embedded_svg(html, base, log):
61
from lxml import etree
62
from calibre.ebooks.oeb.base import XPath, SVG, XLINK
63
root = etree.fromstring(html)
65
svg = XPath('//svg:svg')(root)
66
if len(svg) == 1 and len(svg[0]) == 1 and svg[0][0].tag == SVG('image'):
68
href = image.get(XLINK('href'), None)
69
path = os.path.join(base, *href.split('/'))
70
if href and os.access(path, os.R_OK):
71
return open(path, 'rb').read()
73
def render_html_svg_workaround(path_to_html, log, width=590, height=750):
74
from calibre.ebooks.oeb.base import SVG_NS
75
raw = open(path_to_html, 'rb').read()
79
data = extract_cover_from_embedded_svg(raw,
80
os.path.dirname(path_to_html), log)
84
renderer = render_html(path_to_html, width, height)
85
data = getattr(renderer, 'data', None)
60
89
def render_html(path_to_html, width=590, height=750):
61
90
from PyQt4.QtWebKit import QWebPage
62
91
from PyQt4.Qt import QEventLoop, QPalette, Qt, SIGNAL, QUrl, QSize
92
from calibre.gui2 import is_ok_to_use_qt
93
if not is_ok_to_use_qt(): return None
63
94
path_to_html = os.path.abspath(path_to_html)
64
95
with CurrentDir(os.path.dirname(path_to_html)):