From 40361b77c91d9b64c469a42a75cb9e20b03fbf01 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 3 Aug 2017 18:01:12 +0530 Subject: [PATCH] DOCX Output: Convert images placed by themselves inside block tags as block images rather than inline images. Fixes #1707430 [Image Alignment EPUB to DOCX Conversion](https://bugs.launchpad.net/calibre/+bug/1707430) --- src/calibre/ebooks/docx/writer/images.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/docx/writer/images.py b/src/calibre/ebooks/docx/writer/images.py index bb69174ca5..c064d1b7c8 100644 --- a/src/calibre/ebooks/docx/writer/images.py +++ b/src/calibre/ebooks/docx/writer/images.py @@ -94,10 +94,16 @@ class ImagesManager(object): else: parent = html_img.getparent() if len(parent) == 1 and not (parent.text or '').strip() and not (html_img.tail or '').strip(): - # We have an inline image alone inside a block pstyle = stylizer.style(parent) - if pstyle['text-align'] in ('center', 'right') and 'block' in pstyle['display']: - floating = pstyle['text-align'] + if 'block' in pstyle['display']: + # We have an inline image alone inside a block + as_block = True + floating = pstyle['float'] + if floating not in {'left', 'right'}: + floating = None + if pstyle['text-align'] in ('center', 'right'): + floating = pstyle['text-align'] + floating = floating or 'left' fake_margins = floating is None self.count += 1 img = self.images[href]