DOCX Input: Fix numbering styles that inherit their id from parent styles notbeing correctly applied

This commit is contained in:
Kovid Goyal 2019-12-20 14:39:42 +05:30
parent 53ec8c5b8e
commit 540edf6b05
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 23 additions and 21 deletions

View File

@ -237,7 +237,7 @@ def read_shd(parent, dest, XPath, get):
def read_numbering(parent, dest, XPath, get):
lvl = num_id = None
lvl = num_id = inherit
for np in XPath('./w:numPr')(parent):
for ilvl in XPath('./w:ilvl[@w:val]')(np):
try:
@ -246,8 +246,8 @@ def read_numbering(parent, dest, XPath, get):
pass
for num in XPath('./w:numId[@w:val]')(np):
num_id = get(num, 'w:val')
val = (num_id, lvl) if num_id is not None or lvl is not None else inherit
setattr(dest, 'numbering', val)
setattr(dest, 'numbering_id', num_id)
setattr(dest, 'numbering_level', lvl)
class Frame(object):
@ -355,7 +355,7 @@ class ParagraphStyle(object):
# Misc.
'text_indent', 'text_align', 'line_height', 'background_color',
'numbering', 'font_family', 'font_size', 'color', 'frame',
'numbering_id', 'numbering_level', 'font_family', 'font_size', 'color', 'frame',
'cs_font_size', 'cs_font_family',
)

View File

@ -248,21 +248,23 @@ class Styles(object):
if default_para.character_style is not None:
self.para_char_cache[p] = default_para.character_style
is_numbering = direct_formatting.numbering is not inherit
def has_numbering(block_style):
num_id, lvl = getattr(block_style, 'numbering_id', inherit), getattr(block_style, 'numbering_level', inherit)
return num_id is not None and num_id is not inherit and lvl is not None and lvl is not inherit
is_numbering = has_numbering(direct_formatting)
is_section_break = is_section_break and not self.namespace.XPath('./w:r')(p)
if is_numbering and not is_section_break:
num_id, lvl = direct_formatting.numbering
if num_id is not None:
num_id, lvl = direct_formatting.numbering_id, direct_formatting.numbering_level
p.set('calibre_num_id', '%s:%s' % (lvl, num_id))
if num_id is not None and lvl is not None:
ps = self.numbering.get_para_style(num_id, lvl)
if ps is not None:
parent_styles.append(ps)
if (
not is_numbering and not is_section_break and linked_style is not None and getattr(
linked_style.paragraph_style, 'numbering', inherit) is not inherit):
num_id, lvl = linked_style.paragraph_style.numbering
if num_id is not None:
not is_numbering and not is_section_break and linked_style is not None and has_numbering(linked_style.paragraph_style)
):
num_id, lvl = linked_style.paragraph_style.numbering_id, linked_style.paragraph_style.numbering_level
p.set('calibre_num_id', '%s:%s' % (lvl, num_id))
is_numbering = True
ps = self.numbering.get_para_style(num_id, lvl)
@ -395,12 +397,12 @@ class Styles(object):
self.numbering = numbering
for style in self:
ps = style.paragraph_style
if ps is not None and ps.numbering is not inherit:
lvl = numbering.get_pstyle(ps.numbering[0], style.style_id)
if ps is not None and ps.numbering_id is not inherit:
lvl = numbering.get_pstyle(ps.numbering_id, style.style_id)
if lvl is None:
ps.numbering = inherit
ps.numbering_id = ps.numbering_level = inherit
else:
ps.numbering = (ps.numbering[0], lvl)
ps.numbering_level = lvl
def apply_contextual_spacing(self, paras):
last_para = None