From bb21e82f756debf9b27c4e8a7216abe4da57ff33 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 15 Oct 2020 09:12:56 +0530 Subject: [PATCH] DOCX Input: Add support for presentational markup used to rotate or flip images Note that it will only work if the output format supports CSS transforms, such as EPUB or AZW3 --- src/calibre/ebooks/docx/images.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/calibre/ebooks/docx/images.py b/src/calibre/ebooks/docx/images.py index 31ca932ed9..55130e1fbc 100644 --- a/src/calibre/ebooks/docx/images.py +++ b/src/calibre/ebooks/docx/images.py @@ -60,6 +60,26 @@ def get_image_properties(parent, XPath, get): title = docPr.get('title') or title if docPr.get('hidden', None) in {'true', 'on', '1'}: ans['display'] = 'none' + transforms = [] + for graphic in XPath('./a:graphic')(parent): + for xfrm in XPath('descendant::a:xfrm')(graphic): + rot = xfrm.get('rot') + if rot: + try: + rot = int(rot) / 60000 + except Exception: + rot = None + if rot: + transforms.append(f'rotate({rot:g}deg)') + fliph = xfrm.get('flipH') + if fliph in ('1', 'true'): + transforms.append('scaleX(-1)') + flipv = xfrm.get('flipV') + if flipv in ('1', 'true'): + transforms.append('scaleY(-1)') + + if transforms: + ans['transform'] = ' '.join(transforms) return ans, alt, title