DOCX Input: When a style only specifies a complex script font, use it instead of the normal font

This commit is contained in:
Kovid Goyal 2017-05-16 13:24:22 +05:30
parent 3dd277481d
commit 71acdf085f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -106,15 +106,6 @@ def read_letter_spacing(parent, dest, XPath, get):
setattr(dest, 'letter_spacing', ans) setattr(dest, 'letter_spacing', ans)
def read_sz(parent, dest, XPath, get):
ans = inherit
for col in XPath('./w:sz[@w:val]')(parent):
val = simple_float(get(col, 'w:val'), 0.5)
if val is not None:
ans = val
setattr(dest, 'font_size', ans)
def read_underline(parent, dest, XPath, get): def read_underline(parent, dest, XPath, get):
ans = inherit ans = inherit
for col in XPath('./w:u[@w:val]')(parent): for col in XPath('./w:u[@w:val]')(parent):
@ -144,17 +135,30 @@ def read_position(parent, dest, XPath, get):
setattr(dest, 'position', ans) setattr(dest, 'position', ans)
def read_font_family(parent, dest, XPath, get): def read_font(parent, dest, XPath, get):
ans = inherit ff = inherit
used_cs = False
for col in XPath('./w:rFonts')(parent): for col in XPath('./w:rFonts')(parent):
val = get(col, 'w:asciiTheme') val = get(col, 'w:asciiTheme')
if val: if val:
val = '|%s|' % val val = '|%s|' % val
else: else:
val = get(col, 'w:ascii') val = get(col, 'w:ascii')
if not val:
val = get(col, 'w:cs')
used_cs = bool(val)
if val: if val:
ans = val ff = val
setattr(dest, 'font_family', ans) 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
setattr(dest, 'font_size', inherit)
# }}} # }}}
@ -185,7 +189,8 @@ class RunStyle(object):
): ):
setattr(self, p, binary_property(rPr, p, namespace.XPath, namespace.get)) 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', 'position', 'lang', 'font_family'): read_font(rPr, self, namespace.XPath, namespace.get)
for x in ('text_border', 'color', 'highlight', 'shd', 'letter_spacing', 'underline', 'vert_align', 'position', 'lang'):
f = globals()['read_%s' % x] f = globals()['read_%s' % x]
f(rPr, self, namespace.XPath, namespace.get) f(rPr, self, namespace.XPath, namespace.get)
@ -274,4 +279,3 @@ class RunStyle(object):
def same_border(self, other): def same_border(self, other):
return self.get_border_css({}) == other.get_border_css({}) return self.get_border_css({}) == other.get_border_css({})