Skip to content

Commit

Permalink
Remove borders from flex containers when split between pages
Browse files Browse the repository at this point in the history
Related to #2066.
  • Loading branch information
liZe committed Feb 7, 2025
1 parent 55933c6 commit f573f20
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 11 deletions.
36 changes: 36 additions & 0 deletions tests/layout/test_flex.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,42 @@ def test_flex_direction_column_break():
assert div.height == 2


@assert_no_logs
def test_flex_direction_column_break_border():
page1, page2 = render_pages('''
<style>
@page { size: 8px 7px }
article, div { border: 1px solid black }
</style>
<article style="display: flex; flex-direction: column; font: 2px weasyprint">
<div>A B C</div>
</article>
''')
html, = page1.children
body, = html.children
article, = body.children
assert article.border_height() == 7
assert article.border_top_width == 1
assert article.border_bottom_width == 0
div, = article.children
assert div.children[0].children[0].text == 'A'
assert div.children[1].children[0].text == 'B'
assert div.border_height() == 6
assert div.border_top_width == 1
assert div.border_bottom_width == 0
html, = page2.children
body, = html.children
article, = body.children
assert article.border_height() == 4
assert article.border_top_width == 0
assert article.border_bottom_width == 1
div, = article.children
assert div.children[0].children[0].text == 'C'
assert div.border_height() == 3
assert div.border_top_width == 0
assert div.border_bottom_width == 1


@assert_no_logs
def test_flex_item_min_width():
page, = render_pages('''
Expand Down
2 changes: 1 addition & 1 deletion weasyprint/layout/absolute.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def absolute_block(context, box, containing_block, fixed_boxes, bottom_space,
new_box, resume_at, _, _, _ = flex_layout(
context, box, bottom_space, skip_stack, containing_block,
page_is_empty=True, absolute_boxes=absolute_boxes,
fixed_boxes=fixed_boxes)
fixed_boxes=fixed_boxes, discard=False)
elif isinstance(box, (boxes.GridContainerBox)):
new_box, resume_at, _, _, _ = grid_layout(
context, box, bottom_space, skip_stack, containing_block,
Expand Down
2 changes: 1 addition & 1 deletion weasyprint/layout/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def block_level_layout_switch(context, box, bottom_space, skip_stack,
elif isinstance(box, boxes.FlexBox):
result = flex_layout(
context, box, bottom_space, skip_stack, containing_block,
page_is_empty, absolute_boxes, fixed_boxes)
page_is_empty, absolute_boxes, fixed_boxes, discard)
elif isinstance(box, boxes.GridBox):
result = grid_layout(
context, box, bottom_space, skip_stack, containing_block,
Expand Down
24 changes: 17 additions & 7 deletions weasyprint/layout/flex.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@ class FlexLine(list):


def flex_layout(context, box, bottom_space, skip_stack, containing_block,
page_is_empty, absolute_boxes, fixed_boxes):
page_is_empty, absolute_boxes, fixed_boxes, discard):
from . import block, preferred

context.create_block_formatting_context()
resume_at = None

is_start = skip_stack is None
box.remove_decoration(start=not is_start, end=False)

discard |= box.style['continue'] == 'discard'
draw_bottom_decoration = (
discard or box.style['box_decoration_break'] == 'clone')

if draw_bottom_decoration:
bottom_space += (
box.padding_bottom + box.border_bottom_width + box.margin_bottom)

if box.style['position'] == 'relative':
# New containing block, use a new absolute list
absolute_boxes = []
Expand Down Expand Up @@ -294,10 +305,7 @@ def flex_layout(context, box, bottom_space, skip_stack, containing_block,
for index, child in enumerate(children):
if not child.is_flex_item:
continue
child_height = (
child.hypothetical_main_size +
child.border_top_width + child.border_bottom_width +
child.padding_top + child.padding_bottom)
child_height = child.hypothetical_main_size
if getattr(box, axis) == 'auto' and (
child_height + box.height > available_main_space):
resume_at = {index: None}
Expand Down Expand Up @@ -557,7 +565,7 @@ def flex_layout(context, box, bottom_space, skip_stack, containing_block,
block.block_level_layout_switch(
context, child_copy, -inf, child_skip_stack, parent_box,
page_is_empty, absolute_boxes, fixed_boxes,
[], False, None))
[], discard, None))

child._baseline = find_in_flow_baseline(new_child) or 0
if cross == 'height':
Expand Down Expand Up @@ -1023,7 +1031,7 @@ def flex_layout(context, box, bottom_space, skip_stack, containing_block,
new_child, child_resume_at = block.block_level_layout_switch(
context, child, bottom_space, child_skip_stack, box,
page_is_empty, absolute_boxes, fixed_boxes,
adjoining_margins=[], discard=False, max_lines=None)[:2]
adjoining_margins=[], discard=discard, max_lines=None)[:2]
if new_child is None:
if resume_at:
resume_index, = resume_at
Expand Down Expand Up @@ -1072,6 +1080,8 @@ def flex_layout(context, box, bottom_space, skip_stack, containing_block,
else:
box.baseline = 0

box.remove_decoration(start=False, end=resume_at and not discard)

context.finish_block_formatting_context(box)

# TODO: Check these returned values.
Expand Down
2 changes: 1 addition & 1 deletion weasyprint/layout/float.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def float_layout(context, box, containing_block, absolute_boxes, fixed_boxes,
context, box, bottom_space=bottom_space,
skip_stack=skip_stack, containing_block=containing_block,
page_is_empty=True, absolute_boxes=absolute_boxes,
fixed_boxes=fixed_boxes)
fixed_boxes=fixed_boxes, discard=False)
elif isinstance(box, boxes.GridContainerBox):
box, resume_at, _, _, _ = grid_layout(
context, box, bottom_space=bottom_space,
Expand Down
2 changes: 1 addition & 1 deletion weasyprint/layout/inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def split_inline_level(context, box, position_x, max_x, bottom_space,
setattr(box, f'margin_{side}', 0)
new_box, resume_at, _, _, _ = flex_layout(
context, box, -inf, skip_stack, containing_block, False,
absolute_boxes, fixed_boxes)
absolute_boxes, fixed_boxes, False)
preserved_line_break = False
first_letter = '\u2e80'
last_letter = '\u2e80'
Expand Down

0 comments on commit f573f20

Please sign in to comment.