1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-10-04 16:07:57 +03:00

Fix margin collapsing between caption and table wrapper.

This commit is contained in:
grewn0uille 2019-07-19 18:31:17 +02:00
parent abcd386e2f
commit a86627943f
2 changed files with 64 additions and 4 deletions

View File

@ -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 = []

View File

@ -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)