From 1b39279dd10d7d0570a3ab054a141c70d24f2ea4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 1 Aug 2023 09:34:41 +0530 Subject: [PATCH] DOCX Input: Preserve underline style and color. Fixes #2028404 [Private bug](https://bugs.launchpad.net/calibre/+bug/2028404) --- src/calibre/ebooks/docx/char_styles.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/docx/char_styles.py b/src/calibre/ebooks/docx/char_styles.py index 025a080f11..a651b4349c 100644 --- a/src/calibre/ebooks/docx/char_styles.py +++ b/src/calibre/ebooks/docx/char_styles.py @@ -109,7 +109,18 @@ def read_underline(parent, dest, XPath, get): for col in XPath('./w:u[@w:val]')(parent): val = get(col, 'w:val') if val: - ans = val if val == 'none' else 'underline' + style = { + 'dotted': 'dotted', 'dash': 'dashed', 'dashDotDotHeavy': 'dotted', 'dashDotHeavy': 'dashed', 'dashedHeavy': 'dashed', + 'dashLong': 'dashed', 'dashLongHeavy': 'dashed', 'dotDash': 'dotted', 'dotDotDash': 'dotted', 'dottedHeavy': 'dotted', + 'double': 'double', 'none': 'none', 'single': 'solid', 'thick': 'solid', 'wave': 'wavy', 'wavyDouble': 'wavy', + 'wavyHeavy': 'wavy', 'words': 'solid'}.get(val, 'solid') + if style == 'none': + ans = 'none' + else: + ans = 'underline ' + style + color = get(col, 'w:color') + if color and color != 'auto': + ans += ' #' + color setattr(dest, 'text_decoration', ans)