Edit book/Book polishing: When adding a cover to an EPUB 3.0 file set the svg property if an SVG cover wrapper is used

This commit is contained in:
Kovid Goyal 2017-04-12 11:46:32 +05:30
parent 3feca0981a
commit 842ac7b254
2 changed files with 23 additions and 0 deletions

View File

@ -702,6 +702,23 @@ class Container(ContainerBase): # {{{
self.dirty(self.opf_name)
return removed_names, added_names
def add_properties(self, name, *properties):
''' Add the specified properties to the manifest item identified by name. '''
properties = frozenset(properties)
if not properties:
return True
for p in properties:
if p.startswith('calibre:'):
ensure_prefix(self.opf, None, 'calibre', CALIBRE_PREFIX)
break
for item in self.opf_xpath('//opf:manifest/opf:item'):
iname = self.href_to_name(item.get('href'), self.opf_name)
if name == iname:
props = frozenset((item.get('properties') or '').split()) | properties
item.set('properties', ' '.join(props))
return True
return False
@property
def guide_type_map(self):
' Mapping of guide type to canonical name '

View File

@ -115,6 +115,7 @@ def is_raster_image(media_type):
return media_type and media_type.lower() in {
'image/png', 'image/jpeg', 'image/jpg', 'image/gif'}
COVER_TYPES = {
'coverimagestandard', 'other.ms-coverimage-standard',
'other.ms-titleimage-standard', 'other.ms-titleimage',
@ -345,11 +346,14 @@ def create_epub_cover(container, cover_path, existing_image, options=None):
if no_svg:
style = 'style="height: 100%%"'
templ = CoverManager.NONSVG_TEMPLATE.replace('__style__', style)
has_svg = False
else:
if callable(cover_path):
templ = (options or {}).get('template', CoverManager.SVG_TEMPLATE)
has_svg = 'xlink:href' in templ
else:
width, height = 600, 800
has_svg = True
try:
if existing_image:
width, height = identify(container.raw_data(existing_image, decode=False))[1:]
@ -400,6 +404,8 @@ def create_epub_cover(container, cover_path, existing_image, options=None):
else:
container.apply_unique_properties(raster_cover, 'cover-image')
container.apply_unique_properties(titlepage, 'calibre:title-page')
if has_svg:
container.add_properties(titlepage, 'svg')
return raster_cover, titlepage