mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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:
parent
3feca0981a
commit
842ac7b254
@ -702,6 +702,23 @@ class Container(ContainerBase): # {{{
|
|||||||
self.dirty(self.opf_name)
|
self.dirty(self.opf_name)
|
||||||
return removed_names, added_names
|
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
|
@property
|
||||||
def guide_type_map(self):
|
def guide_type_map(self):
|
||||||
' Mapping of guide type to canonical name '
|
' Mapping of guide type to canonical name '
|
||||||
|
@ -115,6 +115,7 @@ def is_raster_image(media_type):
|
|||||||
return media_type and media_type.lower() in {
|
return media_type and media_type.lower() in {
|
||||||
'image/png', 'image/jpeg', 'image/jpg', 'image/gif'}
|
'image/png', 'image/jpeg', 'image/jpg', 'image/gif'}
|
||||||
|
|
||||||
|
|
||||||
COVER_TYPES = {
|
COVER_TYPES = {
|
||||||
'coverimagestandard', 'other.ms-coverimage-standard',
|
'coverimagestandard', 'other.ms-coverimage-standard',
|
||||||
'other.ms-titleimage-standard', 'other.ms-titleimage',
|
'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:
|
if no_svg:
|
||||||
style = 'style="height: 100%%"'
|
style = 'style="height: 100%%"'
|
||||||
templ = CoverManager.NONSVG_TEMPLATE.replace('__style__', style)
|
templ = CoverManager.NONSVG_TEMPLATE.replace('__style__', style)
|
||||||
|
has_svg = False
|
||||||
else:
|
else:
|
||||||
if callable(cover_path):
|
if callable(cover_path):
|
||||||
templ = (options or {}).get('template', CoverManager.SVG_TEMPLATE)
|
templ = (options or {}).get('template', CoverManager.SVG_TEMPLATE)
|
||||||
|
has_svg = 'xlink:href' in templ
|
||||||
else:
|
else:
|
||||||
width, height = 600, 800
|
width, height = 600, 800
|
||||||
|
has_svg = True
|
||||||
try:
|
try:
|
||||||
if existing_image:
|
if existing_image:
|
||||||
width, height = identify(container.raw_data(existing_image, decode=False))[1:]
|
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:
|
else:
|
||||||
container.apply_unique_properties(raster_cover, 'cover-image')
|
container.apply_unique_properties(raster_cover, 'cover-image')
|
||||||
container.apply_unique_properties(titlepage, 'calibre:title-page')
|
container.apply_unique_properties(titlepage, 'calibre:title-page')
|
||||||
|
if has_svg:
|
||||||
|
container.add_properties(titlepage, 'svg')
|
||||||
|
|
||||||
return raster_cover, titlepage
|
return raster_cover, titlepage
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user