mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
DOCX Output: Add a n option to preserve the cover aspect ratio in the output document. Fixes #1715800 [Conversion to DOCX Results in Stretched Cover Page](https://bugs.launchpad.net/calibre/+bug/1715800)
This commit is contained in:
parent
f19fbaf61c
commit
ae098550e9
@ -33,6 +33,10 @@ class DOCXOutput(OutputFormatPlugin):
|
||||
help=_('Do not insert the book cover as an image at the start of the document.'
|
||||
' If you use this option, the book cover will be discarded.')),
|
||||
|
||||
OptionRecommendation(name='preserve_cover_aspect_ratio', recommended_value=False,
|
||||
help=_('Preserve the aspect ratio of the cover image instead of stretching'
|
||||
' it out to cover the entire page.')),
|
||||
|
||||
OptionRecommendation(name='docx_no_toc', recommended_value=False,
|
||||
help=_('Do not insert the table of contents as a page at the start of the document.')),
|
||||
|
||||
|
@ -457,7 +457,7 @@ class Convert(object):
|
||||
self.blocks.resolve_language()
|
||||
|
||||
if self.cover_img is not None:
|
||||
self.cover_img = self.images_manager.create_cover_markup(self.cover_img, *page_size(self.opts))
|
||||
self.cover_img = self.images_manager.create_cover_markup(self.cover_img, self.opts.preserve_cover_aspect_ratio, *page_size(self.opts))
|
||||
self.lists_manager.finalize(all_blocks)
|
||||
self.styles_manager.finalize(all_blocks)
|
||||
self.write()
|
||||
|
@ -184,9 +184,14 @@ class ImagesManager(object):
|
||||
finally:
|
||||
item.unload_data_from_memory(False)
|
||||
|
||||
def create_cover_markup(self, img, width, height):
|
||||
def create_cover_markup(self, img, preserve_aspect_ratio, width, height):
|
||||
self.count += 1
|
||||
makeelement, namespaces = self.document_relationships.namespace.makeelement, self.document_relationships.namespace.namespaces
|
||||
if preserve_aspect_ratio:
|
||||
if img.width >= img.height:
|
||||
height *= img.height / img.width
|
||||
else:
|
||||
width *= img.width / img.height
|
||||
|
||||
root = etree.Element('root', nsmap=namespaces)
|
||||
ans = makeelement(root, 'w:drawing', append=False)
|
||||
|
Loading…
x
Reference in New Issue
Block a user