mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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:
parent
5346902c6f
commit
5e72273aa9
@ -11,6 +11,8 @@ from collections import OrderedDict
|
|||||||
|
|
||||||
class Inherit:
|
class Inherit:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
inherit = Inherit()
|
inherit = Inherit()
|
||||||
|
|
||||||
|
|
||||||
@ -332,6 +334,7 @@ class ParagraphStyle(object):
|
|||||||
# Misc.
|
# Misc.
|
||||||
'text_indent', 'text_align', 'line_height', 'background_color',
|
'text_indent', 'text_align', 'line_height', 'background_color',
|
||||||
'numbering', 'font_family', 'font_size', 'color', 'frame',
|
'numbering', 'font_family', 'font_size', 'color', 'frame',
|
||||||
|
'cs_font_size', 'cs_font_family',
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, namespace, pPr=None):
|
def __init__(self, namespace, pPr=None):
|
||||||
@ -356,7 +359,7 @@ class ParagraphStyle(object):
|
|||||||
for s in namespace.XPath('./w:pStyle[@w:val]')(pPr):
|
for s in namespace.XPath('./w:pStyle[@w:val]')(pPr):
|
||||||
self.linked_style = namespace.get(s, 'w:val')
|
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._css = None
|
||||||
self._border_key = None
|
self._border_key = None
|
||||||
|
@ -137,28 +137,41 @@ def read_position(parent, dest, XPath, get):
|
|||||||
|
|
||||||
def read_font(parent, dest, XPath, get):
|
def read_font(parent, dest, XPath, get):
|
||||||
ff = 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:
|
||||||
ff = val
|
ff = val
|
||||||
setattr(dest, 'font_family', ff)
|
setattr(dest, 'font_family', ff)
|
||||||
sizes = ('szCs', 'sz') if used_cs else ('sz', 'szCs')
|
for col in XPath('./w:sz[@w:val]')(parent):
|
||||||
for q in sizes:
|
val = simple_float(get(col, 'w:val'), 0.5)
|
||||||
for col in XPath('./w:%s[@w:val]' % q)(parent):
|
if val is not None:
|
||||||
val = simple_float(get(col, 'w:val'), 0.5)
|
setattr(dest, 'font_size', val)
|
||||||
if val is not None:
|
return
|
||||||
setattr(dest, 'font_size', val)
|
|
||||||
return
|
|
||||||
setattr(dest, 'font_size', inherit)
|
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',
|
'border_color', 'border_style', 'border_width', 'padding', 'color', 'highlight', 'background_color',
|
||||||
'letter_spacing', 'font_size', 'text_decoration', 'vert_align', 'lang', 'font_family', 'position',
|
'letter_spacing', 'font_size', 'text_decoration', 'vert_align', 'lang', 'font_family', 'position',
|
||||||
|
'cs_font_size', 'cs_font_family'
|
||||||
}
|
}
|
||||||
|
|
||||||
toggle_properties = {
|
toggle_properties = {
|
||||||
@ -191,6 +205,7 @@ class RunStyle(object):
|
|||||||
setattr(self, p, binary_property(rPr, p, X, g))
|
setattr(self, p, binary_property(rPr, p, X, g))
|
||||||
|
|
||||||
read_font(rPr, self, X, g)
|
read_font(rPr, self, X, g)
|
||||||
|
read_font_cs(rPr, self, X, g)
|
||||||
read_text_border(rPr, self, X, g)
|
read_text_border(rPr, self, X, g)
|
||||||
read_color(rPr, self, X, g)
|
read_color(rPr, self, X, g)
|
||||||
read_highlight(rPr, self, X, g)
|
read_highlight(rPr, self, X, g)
|
||||||
|
@ -339,7 +339,7 @@ class Styles(object):
|
|||||||
has_links = '1' in {r.get('is-link', None) for r in runs}
|
has_links = '1' in {r.get('is-link', None) for r in runs}
|
||||||
char_styles = [self.resolve_run(r) for r in runs]
|
char_styles = [self.resolve_run(r) for r in runs]
|
||||||
block_style = self.resolve_paragraph(p)
|
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':
|
if has_links and prop == 'color':
|
||||||
# We cannot promote color as browser rendering engines will
|
# We cannot promote color as browser rendering engines will
|
||||||
# override the link color setting it to blue, unless the
|
# override the link color setting it to blue, unless the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user