mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
DOCX Input: Add support for contextual spacing
DOCX Input: Add support for the Word setting "No space between paragraphs with the same style". Fixes #1191001 [docx conversion bug](https://bugs.launchpad.net/calibre/+bug/1191001)
This commit is contained in:
parent
877810c134
commit
8bc65df29a
@ -260,6 +260,7 @@ class Styles(object):
|
|||||||
for attr in ans.all_properties:
|
for attr in ans.all_properties:
|
||||||
if not (is_numbering and attr == 'text_indent'): # skip text-indent for lists
|
if not (is_numbering and attr == 'text_indent'): # skip text-indent for lists
|
||||||
setattr(ans, attr, self.para_val(parent_styles, direct_formatting, attr))
|
setattr(ans, attr, self.para_val(parent_styles, direct_formatting, attr))
|
||||||
|
ans.linked_style = direct_formatting.linked_style
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
def resolve_run(self, r):
|
def resolve_run(self, r):
|
||||||
@ -389,6 +390,19 @@ class Styles(object):
|
|||||||
else:
|
else:
|
||||||
ps.numbering = (ps.numbering[0], lvl)
|
ps.numbering = (ps.numbering[0], lvl)
|
||||||
|
|
||||||
|
def apply_contextual_spacing(self, paras):
|
||||||
|
last_para = None
|
||||||
|
for p in paras:
|
||||||
|
if last_para is not None:
|
||||||
|
ls = self.resolve_paragraph(last_para)
|
||||||
|
ps = self.resolve_paragraph(p)
|
||||||
|
if ls.linked_style is not None and ls.linked_style == ps.linked_style:
|
||||||
|
if ls.contextualSpacing:
|
||||||
|
ls.margin_bottom = 0
|
||||||
|
if ps.contextualSpacing:
|
||||||
|
ps.margin_top = 0
|
||||||
|
last_para = p
|
||||||
|
|
||||||
def register(self, css, prefix):
|
def register(self, css, prefix):
|
||||||
h = hash(frozenset(css.iteritems()))
|
h = hash(frozenset(css.iteritems()))
|
||||||
ans, _ = self.classes.get(h, (None, None))
|
ans, _ = self.classes.get(h, (None, None))
|
||||||
|
@ -86,6 +86,7 @@ class Convert(object):
|
|||||||
self.framed_map = {}
|
self.framed_map = {}
|
||||||
self.anchor_map = {}
|
self.anchor_map = {}
|
||||||
self.link_map = defaultdict(list)
|
self.link_map = defaultdict(list)
|
||||||
|
paras = []
|
||||||
|
|
||||||
self.log.debug('Converting Word markup to HTML')
|
self.log.debug('Converting Word markup to HTML')
|
||||||
self.read_page_properties(doc)
|
self.read_page_properties(doc)
|
||||||
@ -94,6 +95,8 @@ class Convert(object):
|
|||||||
if wp.tag.endswith('}p'):
|
if wp.tag.endswith('}p'):
|
||||||
p = self.convert_p(wp)
|
p = self.convert_p(wp)
|
||||||
self.body.append(p)
|
self.body.append(p)
|
||||||
|
paras.append(wp)
|
||||||
|
self.styles.apply_contextual_spacing(paras)
|
||||||
|
|
||||||
notes_header = None
|
notes_header = None
|
||||||
if self.footnotes.has_notes:
|
if self.footnotes.has_notes:
|
||||||
@ -107,12 +110,16 @@ class Convert(object):
|
|||||||
dl.append(DT('[', A('←' + text, href='#back_%s' % anchor, title=text), id=anchor))
|
dl.append(DT('[', A('←' + text, href='#back_%s' % anchor, title=text), id=anchor))
|
||||||
dl[-1][0].tail = ']'
|
dl[-1][0].tail = ']'
|
||||||
dl.append(DD())
|
dl.append(DD())
|
||||||
|
paras = []
|
||||||
for wp in note:
|
for wp in note:
|
||||||
if wp.tag.endswith('}tbl'):
|
if wp.tag.endswith('}tbl'):
|
||||||
self.tables.register(wp, self.styles)
|
self.tables.register(wp, self.styles)
|
||||||
self.page_map[wp] = self.current_page
|
self.page_map[wp] = self.current_page
|
||||||
p = self.convert_p(wp)
|
else:
|
||||||
dl[-1].append(p)
|
p = self.convert_p(wp)
|
||||||
|
dl[-1].append(p)
|
||||||
|
paras.append(wp)
|
||||||
|
self.styles.apply_contextual_spacing(paras)
|
||||||
|
|
||||||
self.resolve_links(relationships_by_id)
|
self.resolve_links(relationships_by_id)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user