From 694b457a1af1aa6003b2ff727e9fb225d495656e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 28 May 2015 09:53:47 +0530 Subject: [PATCH] DOCX Output: Detect the common idiom of placing centered images as inline images inside a containing centered block and render the resulting image as a floating centered image in the DOCX file. See #1455502 (EPUB to DOCX Conversation) --- src/calibre/ebooks/docx/writer/images.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/calibre/ebooks/docx/writer/images.py b/src/calibre/ebooks/docx/writer/images.py index 3aaf809297..1cac3a32ed 100644 --- a/src/calibre/ebooks/docx/writer/images.py +++ b/src/calibre/ebooks/docx/writer/images.py @@ -81,6 +81,13 @@ class ImagesManager(object): floating = 'center' if mr == 'auto' else 'right' if mr == 'auto': floating = 'center' if ml == 'auto' else 'right' + 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'): + floating = pstyle['text-align'] fake_margins = floating is None self.count += 1 img = self.images[href]