1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-10-05 00:21:15 +03:00

Explicitely remove box decorations when needed

This commit is contained in:
Guillaume Ayoub 2019-09-24 18:42:25 +02:00
parent b4ff03c7a8
commit 5cb24e2cbc
5 changed files with 18 additions and 19 deletions

View File

@ -302,12 +302,14 @@ class ParentBox(Box):
setattr(self, 'border_%s_width' % side, 0)
def _remove_decoration(self, start, end):
if self.style['box_decoration_break'] == 'clone':
return
if start:
self._reset_spacing('top')
if end:
self._reset_spacing('bottom')
def copy_with_children(self, new_children, is_start=True, is_end=True):
def copy_with_children(self, new_children):
"""Create a new equivalent box with given ``new_children``."""
new_box = self.copy()
new_box.children = tuple(new_children)
@ -315,8 +317,6 @@ class ParentBox(Box):
# Clear and reset removed decorations as we don't want to keep the
# previous data, for example when a box is split between two pages.
self.remove_decoration_sides = set()
if self.style['box_decoration_break'] == 'slice':
new_box._remove_decoration(not is_start, not is_end)
return new_box
@ -411,6 +411,8 @@ class InlineLevelBox(Box):
"""
def _remove_decoration(self, start, end):
if self.style['box_decoration_break'] == 'clone':
return
ltr = self.style['direction'] == 'ltr'
if start:
self._reset_spacing('left' if ltr else 'right')

View File

@ -1467,13 +1467,11 @@ def _inner_block_in_inline(box, skip_stack=None):
new_children.append(new_child)
if block_level_box is not None:
resume_at = (index, resume_at)
box = box.copy_with_children(
new_children, is_start=is_start, is_end=False)
box = box.copy_with_children(new_children)
break
else:
if changed or skip:
box = box.copy_with_children(
new_children, is_start=is_start, is_end=True)
box = box.copy_with_children(new_children)
return box, block_level_box, resume_at

View File

@ -275,9 +275,7 @@ def block_container_layout(context, box, max_position_y, skip_stack,
context.create_block_formatting_context()
is_start = skip_stack is None
if box.style['box_decoration_break'] == 'slice' and not is_start:
# Remove top margin, border and padding:
box._remove_decoration(start=True, end=False)
box._remove_decoration(start=not is_start, end=False)
if adjoining_margins is None:
adjoining_margins = []
@ -640,8 +638,8 @@ def block_container_layout(context, box, max_position_y, skip_stack,
position_y += collapse_margin(adjoining_margins)
adjoining_margins = []
new_box = box.copy_with_children(
new_children, is_start=is_start, is_end=resume_at is None)
new_box = box.copy_with_children(new_children)
new_box._remove_decoration(start=not is_start, end=resume_at is not None)
# TODO: See corner cases in
# http://www.w3.org/TR/CSS21/visudet.html#normal-block

View File

@ -899,8 +899,8 @@ def split_inline_box(context, box, position_x, max_x, skip_stack,
is_end = resume_at is None
new_box = box.copy_with_children(
[box_child for index, box_child in children],
is_start=is_start, is_end=is_end)
[box_child for index, box_child in children])
new_box._remove_decoration(start=not is_start, end=not is_end)
if isinstance(box, boxes.LineBox):
# We must reset line box width according to its new children
in_flow_children = [

View File

@ -249,9 +249,9 @@ def table_layout(context, table, max_position_y, skip_stack, containing_block,
not new_group_children):
return None, None, next_page
group = group.copy_with_children(
new_group_children,
is_start=is_group_start, is_end=resume_at is None)
group = group.copy_with_children(new_group_children)
group._remove_decoration(
start=not is_group_start, end=resume_at is not None)
# Set missing baselines in a second loop because of rowspan
for row in group.children:
@ -442,8 +442,9 @@ def table_layout(context, table, max_position_y, skip_stack, containing_block,
table = table.copy_with_children(
([header] if header is not None else []) +
new_table_children +
([footer] if footer is not None else []),
is_start=skip_stack is None, is_end=resume_at is None)
([footer] if footer is not None else []))
table._remove_decoration(
start=skip_stack is not None, end=resume_at is not None)
if table.style['border_collapse'] == 'collapse':
table.skipped_rows = skipped_rows