Skip to content
Permalink
Browse files

Fix margin collapsing between caption and table wrapper.

  • Loading branch information...
grewn0uille committed Jul 19, 2019
1 parent abcd386 commit a86627943f461e117e68c7847f659d2bdca04e1a
Showing with 64 additions and 4 deletions.
  1. +6 −4 weasyprint/layout/blocks.py
  2. +58 −0 weasyprint/tests/test_layout/test_table.py
@@ -461,7 +461,6 @@ def block_container_layout(context, box, max_position_y, skip_stack,
new_containing_block = box

if not new_containing_block.is_table_wrapper:
# TODO: there's no collapsing margins inside tables, right?
resolve_percentages(child, new_containing_block)
if (child.is_in_normal_flow() and
last_in_flow_child is None and
@@ -493,7 +492,7 @@ def block_container_layout(context, box, max_position_y, skip_stack,
adjoining_margins = []
position_y = box.content_box_y()

if adjoining_margins and isinstance(child, boxes.TableBox):
if adjoining_margins and box.is_table_wrapper:
collapsed_margin = collapse_margin(adjoining_margins)
child.position_y += collapsed_margin
position_y += collapsed_margin
@@ -625,8 +624,11 @@ def block_container_layout(context, box, max_position_y, skip_stack,
# not adjoining. (position_y is not used afterwards.)
adjoining_margins = []

if box.border_bottom_width or box.padding_bottom or (
establishes_formatting_context(box) or box.is_for_root_element):
if (box.border_bottom_width or
box.padding_bottom or
establishes_formatting_context(box) or
box.is_for_root_element or
box.is_table_wrapper):
position_y += collapse_margin(adjoining_margins)
adjoining_margins = []

@@ -2075,3 +2075,61 @@ def test_inline_table_baseline(vertical_align, table_position_y):
assert text1.position_y == text2.position_y == 0
assert table.height == 10 * 2
assert table.position_y == table_position_y


@assert_no_logs
def test_table_caption_margin_top():
page, = render_pages('''
<style>
table { margin: 20px; }
caption, h1, h2 { margin: 20px; height: 10px }
td { height: 10px }
</style>
<h1></h1>
<table>
<caption></caption>
<tr>
<td></td>
</tr>
</table>
<h2></h2>
''')
html, = page.children
body, = html.children
h1, wrapper, h2 = body.children
caption, table = wrapper.children
tbody, = table.children
assert (h1.content_box_x(), h1.content_box_y()) == (20, 20)
assert (wrapper.content_box_x(), wrapper.content_box_y()) == (20, 50)
assert (caption.content_box_x(), caption.content_box_y()) == (40, 70)
assert (tbody.content_box_x(), tbody.content_box_y()) == (20, 100)
assert (h2.content_box_x(), h2.content_box_y()) == (20, 130)


@assert_no_logs
def test_table_caption_margin_bottom():
page, = render_pages('''
<style>
table { margin: 20px; }
caption, h1, h2 { margin: 20px; height: 10px; caption-side: bottom }
td { height: 10px }
</style>
<h1></h1>
<table>
<caption></caption>
<tr>
<td></td>
</tr>
</table>
<h2></h2>
''')
html, = page.children
body, = html.children
h1, wrapper, h2 = body.children
table, caption = wrapper.children
tbody, = table.children
assert (h1.content_box_x(), h1.content_box_y()) == (20, 20)
assert (wrapper.content_box_x(), wrapper.content_box_y()) == (20, 50)
assert (tbody.content_box_x(), tbody.content_box_y()) == (20, 50)
assert (caption.content_box_x(), caption.content_box_y()) == (40, 80)
assert (h2.content_box_x(), h2.content_box_y()) == (20, 130)

0 comments on commit a866279

Please sign in to comment.
You can’t perform that action at this time.