mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
355fc6f84b
commit
45681fef78
@ -200,7 +200,7 @@ class Convert(object):
|
|||||||
if block_style.is_hidden:
|
if block_style.is_hidden:
|
||||||
return
|
return
|
||||||
if html_block.tag.endswith('}img'):
|
if html_block.tag.endswith('}img'):
|
||||||
b = Block(self.styles_manager, html_block, stylizer.style(html_block))
|
b = Block(self.styles_manager, html_block, None)
|
||||||
self.blocks.append(b)
|
self.blocks.append(b)
|
||||||
self.images_manager.add_image(html_block, b, stylizer)
|
self.images_manager.add_image(html_block, b, stylizer)
|
||||||
else:
|
else:
|
||||||
@ -218,15 +218,15 @@ class Convert(object):
|
|||||||
else:
|
else:
|
||||||
self.process_inline(child, self.blocks[-1], stylizer)
|
self.process_inline(child, self.blocks[-1], stylizer)
|
||||||
|
|
||||||
if ignore_tail is False and html_block.tail and html_block.tail.strip():
|
|
||||||
b = docx_block
|
|
||||||
if b is not self.blocks[-1]:
|
|
||||||
b = Block(self.styles_manager, html_block, block_style)
|
|
||||||
self.blocks.append(b)
|
|
||||||
b.add_text(html_block.tail, stylizer.style(html_block.getparent()), is_parent_style=True)
|
|
||||||
if block_style['page-break-after'] == 'avoid':
|
if block_style['page-break-after'] == 'avoid':
|
||||||
self.blocks[-1].keep_next = True
|
self.blocks[-1].keep_next = True
|
||||||
|
|
||||||
|
if ignore_tail is False and html_block.tail and html_block.tail.strip():
|
||||||
|
style = stylizer.style(html_block.getparent())
|
||||||
|
b = Block(self.styles_manager, html_block.getparent(), style)
|
||||||
|
self.blocks.append(b)
|
||||||
|
b.add_text(html_block.tail, style, is_parent_style=True)
|
||||||
|
|
||||||
def process_inline(self, html_child, docx_block, stylizer):
|
def process_inline(self, html_child, docx_block, stylizer):
|
||||||
tag = barename(html_child.tag)
|
tag = barename(html_child.tag)
|
||||||
style = stylizer.style(html_child)
|
style = stylizer.style(html_child)
|
||||||
|
@ -236,24 +236,39 @@ class BlockStyle(DOCXStyle):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, css, html_block, is_first_block=False):
|
def __init__(self, css, html_block, is_first_block=False):
|
||||||
self.page_break_before = html_block.tag.endswith('}body') or (not is_first_block and css['page-break-before'] == 'always')
|
if css is None:
|
||||||
self.keep_lines = css['page-break-inside'] == 'avoid'
|
self.page_break_before = self.keep_lines = False
|
||||||
for edge in border_edges:
|
for edge in border_edges:
|
||||||
# In DOCX padding can only be a positive integer
|
setattr(self, 'padding_' + edge, 0)
|
||||||
setattr(self, 'padding_' + edge, max(0, int(css['padding-' + edge])))
|
setattr(self, 'margin_' + edge, 0)
|
||||||
# In DOCX margin must be a positive integer in twips (twentieth of a point)
|
setattr(self, 'css_margin_' + edge, '')
|
||||||
setattr(self, 'margin_' + edge, max(0, int(css['margin-' + edge] * 20)))
|
setattr(self, 'border_%s_width' % edge, 2)
|
||||||
setattr(self, 'css_margin_' + edge, css._style.get('margin-' + edge, ''))
|
setattr(self, 'border_%s_color' % edge, None)
|
||||||
val = min(96, max(2, int({'thin':0.2, 'medium':1, 'thick':2}.get(css['border-%s-width' % edge], 0) * 8)))
|
setattr(self, 'border_%s_style' % edge, 'none')
|
||||||
setattr(self, 'border_%s_width' % edge, val)
|
self.text_indent = 0
|
||||||
setattr(self, 'border_%s_color' % edge, convert_color(css['border-%s-color' % edge]))
|
self.css_text_indent = None
|
||||||
setattr(self, 'border_%s_style' % edge, LINE_STYLES.get(css['border-%s-style' % edge].lower(), 'none'))
|
self.line_height = 280
|
||||||
self.text_indent = max(0, int(css['text-indent'] * 20))
|
self.background_color = None
|
||||||
self.css_text_indent = css._get('text-indent')
|
self.text_align = 'left'
|
||||||
self.line_height = max(0, int(css.lineHeight * 20))
|
else:
|
||||||
self.background_color = convert_color(css['background-color'])
|
self.page_break_before = html_block.tag.endswith('}body') or (not is_first_block and css['page-break-before'] == 'always')
|
||||||
self.text_align = {'start':'left', 'left':'left', 'end':'right', 'right':'right', 'center':'center', 'justify':'both', 'centre':'center'}.get(
|
self.keep_lines = css['page-break-inside'] == 'avoid'
|
||||||
css['text-align'].lower(), 'left')
|
for edge in border_edges:
|
||||||
|
# In DOCX padding can only be a positive integer
|
||||||
|
setattr(self, 'padding_' + edge, max(0, int(css['padding-' + edge])))
|
||||||
|
# In DOCX margin must be a positive integer in twips (twentieth of a point)
|
||||||
|
setattr(self, 'margin_' + edge, max(0, int(css['margin-' + edge] * 20)))
|
||||||
|
setattr(self, 'css_margin_' + edge, css._style.get('margin-' + edge, ''))
|
||||||
|
val = min(96, max(2, int({'thin':0.2, 'medium':1, 'thick':2}.get(css['border-%s-width' % edge], 0) * 8)))
|
||||||
|
setattr(self, 'border_%s_width' % edge, val)
|
||||||
|
setattr(self, 'border_%s_color' % edge, convert_color(css['border-%s-color' % edge]))
|
||||||
|
setattr(self, 'border_%s_style' % edge, LINE_STYLES.get(css['border-%s-style' % edge].lower(), 'none'))
|
||||||
|
self.text_indent = max(0, int(css['text-indent'] * 20))
|
||||||
|
self.css_text_indent = css._get('text-indent')
|
||||||
|
self.line_height = max(0, int(css.lineHeight * 20))
|
||||||
|
self.background_color = convert_color(css['background-color'])
|
||||||
|
self.text_align = {'start':'left', 'left':'left', 'end':'right', 'right':'right', 'center':'center', 'justify':'both', 'centre':'center'}.get(
|
||||||
|
css['text-align'].lower(), 'left')
|
||||||
|
|
||||||
DOCXStyle.__init__(self)
|
DOCXStyle.__init__(self)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user