mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Simpler markup for covers that works in HTML 5 rendering mode
This commit is contained in:
parent
fb25c0aaae
commit
b4f793507a
@ -294,7 +294,7 @@ def create_epub_cover(container, cover_path, existing_image, options=None):
|
||||
templ = CoverManager.NONSVG_TEMPLATE.replace('__style__', style)
|
||||
else:
|
||||
if callable(cover_path):
|
||||
templ = CoverManager.SVG_TEMPLATE
|
||||
templ = (options or {}).get('template', CoverManager.SVG_TEMPLATE)
|
||||
else:
|
||||
width, height = 600, 800
|
||||
try:
|
||||
|
@ -16,6 +16,7 @@ from urllib import quote
|
||||
from cssutils import replaceUrls
|
||||
from cssutils.css import CSSRule
|
||||
|
||||
from calibre import prepare_string_for_xml
|
||||
from calibre.ebooks import parse_css_length
|
||||
from calibre.ebooks.oeb.base import (
|
||||
OEB_DOCS, OEB_STYLES, rewrite_links, XPath, urlunquote, XLINK, XHTML_NS, OPF, XHTML, EPUB_NS)
|
||||
@ -134,12 +135,18 @@ class Container(ContainerBase):
|
||||
f.write(json.dumps(self.book_render_data, ensure_ascii=False).encode('utf-8'))
|
||||
|
||||
def create_cover_page(self, input_fmt):
|
||||
templ = '''
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||
<head><style>
|
||||
html, body, img { height: 100%%; display: block; margin: 0; padding: 0; border-width: 0; }
|
||||
img { width: auto; margin-left:auto; margin-right: auto; }
|
||||
</style></head><body><img src="%s"/></body></html>
|
||||
'''
|
||||
if input_fmt == 'epub':
|
||||
def cover_path(action, data):
|
||||
if action == 'write_image':
|
||||
data.write(BLANK_JPEG)
|
||||
return set_epub_cover(self, cover_path, (lambda *a: None))
|
||||
from calibre.ebooks.oeb.transforms.cover import CoverManager
|
||||
return set_epub_cover(self, cover_path, (lambda *a: None), options={'template':templ})
|
||||
raster_cover_name = find_cover_image(self, strict=True)
|
||||
if raster_cover_name is None:
|
||||
item = self.generate_item(name='cover.jpeg', id_prefix='cover')
|
||||
@ -148,8 +155,7 @@ class Container(ContainerBase):
|
||||
dest.write(BLANK_JPEG)
|
||||
item = self.generate_item(name='titlepage.html', id_prefix='titlepage')
|
||||
titlepage_name = self.href_to_name(item.get('href'), self.opf_name)
|
||||
templ = CoverManager.SVG_TEMPLATE
|
||||
raw = templ % self.name_to_href(raster_cover_name, titlepage_name)
|
||||
raw = templ % prepare_string_for_xml(self.name_to_href(raster_cover_name, titlepage_name), True)
|
||||
with self.open(titlepage_name, 'wb') as f:
|
||||
f.write(raw.encode('utf-8'))
|
||||
spine = self.opf_xpath('//opf:spine')[0]
|
||||
|
@ -39,14 +39,9 @@ def load_resources(db, book, root_name, previous_resources, proceed):
|
||||
db.get_file(book, name, got_one)
|
||||
|
||||
def got_one(data, name, mimetype):
|
||||
if name is book.manifest.title_page_name:
|
||||
w = book.manifest.cover_width or 600
|
||||
h = book.manifest.cover_height or 800
|
||||
ar = 'xMidYMid meet' # or 'none'
|
||||
data = data.replace('__ar__', ar)
|
||||
data = data.replace('__viewbox__', '0 0 ' + w + ' ' + h)
|
||||
data = data.replace('__width__', w + '')
|
||||
data = data.replace('__height__', h + '')
|
||||
if False and name is book.manifest.title_page_name:
|
||||
# Enable to have cover image not preserve aspect ratio
|
||||
data = data.replace('width: auto', 'width: 100%')
|
||||
ans[name] = v'[data, mimetype]'
|
||||
if type(data) is 'string':
|
||||
find_virtualized_resources(data)
|
||||
|
Loading…
x
Reference in New Issue
Block a user