DOCX Input: Ignore complex script font styles. Fixes conversion of documents that specify only complex script styles and no simple script styles. Fixes #1766650 [Private bug](https://bugs.launchpad.net/calibre/+bug/1766650)

This commit is contained in:
Kovid Goyal 2018-04-25 14:11:10 +05:30
parent 5346902c6f
commit 5e72273aa9
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 31 additions and 13 deletions

View File

@ -11,6 +11,8 @@ from collections import OrderedDict
class Inherit:
pass
inherit = Inherit()
@ -332,6 +334,7 @@ class ParagraphStyle(object):
# Misc.
'text_indent', 'text_align', 'line_height', 'background_color',
'numbering', 'font_family', 'font_size', 'color', 'frame',
'cs_font_size', 'cs_font_family',
)
def __init__(self, namespace, pPr=None):
@ -356,7 +359,7 @@ class ParagraphStyle(object):
for s in namespace.XPath('./w:pStyle[@w:val]')(pPr):
self.linked_style = namespace.get(s, 'w:val')
self.font_family = self.font_size = self.color = inherit
self.font_family = self.font_size = self.color = self.cs_font_size = self.cs_font_family = inherit
self._css = None
self._border_key = None

View File

@ -137,28 +137,41 @@ def read_position(parent, dest, XPath, get):
def read_font(parent, dest, XPath, get):
ff = inherit
used_cs = False
for col in XPath('./w:rFonts')(parent):
val = get(col, 'w:asciiTheme')
if val:
val = '|%s|' % val
else:
val = get(col, 'w:ascii')
if not val:
val = get(col, 'w:cs')
used_cs = bool(val)
if val:
ff = val
setattr(dest, 'font_family', ff)
sizes = ('szCs', 'sz') if used_cs else ('sz', 'szCs')
for q in sizes:
for col in XPath('./w:%s[@w:val]' % q)(parent):
val = simple_float(get(col, 'w:val'), 0.5)
if val is not None:
setattr(dest, 'font_size', val)
return
for col in XPath('./w:sz[@w:val]')(parent):
val = simple_float(get(col, 'w:val'), 0.5)
if val is not None:
setattr(dest, 'font_size', val)
return
setattr(dest, 'font_size', inherit)
def read_font_cs(parent, dest, XPath, get):
ff = inherit
for col in XPath('./w:rFonts')(parent):
val = get(col, 'w:csTheme')
if val:
val = '|%s|' % val
else:
val = get(col, 'w:cs')
if val:
ff = val
setattr(dest, 'cs_font_family', ff)
for col in XPath('./w:szCS[@w:val]')(parent):
val = simple_float(get(col, 'w:val'), 0.5)
if val is not None:
setattr(dest, 'font_size', val)
return
setattr(dest, 'cs_font_size', inherit)
# }}}
@ -170,6 +183,7 @@ class RunStyle(object):
'border_color', 'border_style', 'border_width', 'padding', 'color', 'highlight', 'background_color',
'letter_spacing', 'font_size', 'text_decoration', 'vert_align', 'lang', 'font_family', 'position',
'cs_font_size', 'cs_font_family'
}
toggle_properties = {
@ -191,6 +205,7 @@ class RunStyle(object):
setattr(self, p, binary_property(rPr, p, X, g))
read_font(rPr, self, X, g)
read_font_cs(rPr, self, X, g)
read_text_border(rPr, self, X, g)
read_color(rPr, self, X, g)
read_highlight(rPr, self, X, g)

View File

@ -339,7 +339,7 @@ class Styles(object):
has_links = '1' in {r.get('is-link', None) for r in runs}
char_styles = [self.resolve_run(r) for r in runs]
block_style = self.resolve_paragraph(p)
for prop in ('font_family', 'font_size', 'color'):
for prop in ('font_family', 'font_size', 'cs_font_family', 'cs_font_size', 'color'):
if has_links and prop == 'color':
# We cannot promote color as browser rendering engines will
# override the link color setting it to blue, unless the