From 2cd0c92224597c08073caddc409910f8362229e7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 3 Aug 2015 09:11:20 +0530 Subject: [PATCH] DOCX Input: Add support for text whose vertical position is adjusted by offsets from the baseline --- src/calibre/ebooks/docx/char_styles.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/docx/char_styles.py b/src/calibre/ebooks/docx/char_styles.py index fd1deffc5c..f08e4ceb24 100644 --- a/src/calibre/ebooks/docx/char_styles.py +++ b/src/calibre/ebooks/docx/char_styles.py @@ -122,6 +122,16 @@ def read_vert_align(parent, dest, XPath, get): ans = val setattr(dest, 'vert_align', ans) +def read_position(parent, dest, XPath, get): + ans = inherit + for col in XPath('./w:position[@w:val]')(parent): + val = get(col, 'w:val') + try: + ans = float(val)/2.0 + except Exception: + pass + setattr(dest, 'position', ans) + def read_font_family(parent, dest, XPath, get): ans = inherit for col in XPath('./w:rFonts')(parent): @@ -142,7 +152,7 @@ class RunStyle(object): 'rtl', 'shadow', 'smallCaps', 'strike', 'vanish', 'webHidden', 'border_color', 'border_style', 'border_width', 'padding', 'color', 'highlight', 'background_color', - 'letter_spacing', 'font_size', 'text_decoration', 'vert_align', 'lang', 'font_family', + 'letter_spacing', 'font_size', 'text_decoration', 'vert_align', 'lang', 'font_family', 'position', } toggle_properties = { @@ -162,7 +172,7 @@ class RunStyle(object): ): setattr(self, p, binary_property(rPr, p, namespace.XPath, namespace.get)) - for x in ('text_border', 'color', 'highlight', 'shd', 'letter_spacing', 'sz', 'underline', 'vert_align', 'lang', 'font_family'): + for x in ('text_border', 'color', 'highlight', 'shd', 'letter_spacing', 'sz', 'underline', 'vert_align', 'position', 'lang', 'font_family'): f = globals()['read_%s' % x] f(rPr, self, namespace.XPath, namespace.get) @@ -235,6 +245,9 @@ class RunStyle(object): if val is not inherit: c[x.replace('_', '-')] = '%.3gpt' % val + if self.position is not inherit: + c['vertical-align'] = '%.3gpt' % val + if self.highlight is not inherit and self.highlight != 'transparent': c['background-color'] = self.highlight