From 447d1c547c28cfd3547700ce89894d537b1b3b9a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 22 Feb 2016 14:08:12 +0530 Subject: [PATCH] DOCX Input: Fix handling of toggle properties such as bold/italic/strikethrough/etc. when specified as document defaults. Fixes #1548187 [docx conversion to epub and mobi has strikethrough on converted document](https://bugs.launchpad.net/calibre/+bug/1548187) --- src/calibre/ebooks/docx/styles.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/calibre/ebooks/docx/styles.py b/src/calibre/ebooks/docx/styles.py index c34935e95d..9b3dc06958 100644 --- a/src/calibre/ebooks/docx/styles.py +++ b/src/calibre/ebooks/docx/styles.py @@ -189,12 +189,15 @@ class Styles(object): if val is not inherit: return val if attr in direct_formatting.toggle_properties: - val = False - for rs in parent_styles: - pval = getattr(rs, attr) - if pval is True: - val ^= True - return val + # The spec (section 17.7.3) does not make sense, so we follow the behavior + # of Word, which seems to only consider the document default if the + # property has not been defined in any styles. + vals = [int(getattr(rs, attr)) for rs in parent_styles if rs is not self.default_character_style and getattr(rs, attr) is not inherit] + if vals: + return sum(vals) % 2 == 1 + if self.default_character_style is not None: + return getattr(self.default_character_style, attr) is True + return False for rs in reversed(parent_styles): rval = getattr(rs, attr) if rval is not inherit: