diff --git a/src/calibre/ebooks/oeb/polish/container.py b/src/calibre/ebooks/oeb/polish/container.py index 68ea7f20a6..d9360ab716 100644 --- a/src/calibre/ebooks/oeb/polish/container.py +++ b/src/calibre/ebooks/oeb/polish/container.py @@ -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 ' diff --git a/src/calibre/ebooks/oeb/polish/cover.py b/src/calibre/ebooks/oeb/polish/cover.py index c0d2d7f2bf..6423765d6e 100644 --- a/src/calibre/ebooks/oeb/polish/cover.py +++ b/src/calibre/ebooks/oeb/polish/cover.py @@ -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