From bd753560b4c650a0b08a1fb4603f2fb0bc6c2cb3 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Tue, 12 Oct 2021 14:38:04 +0200 Subject: [PATCH] Remove float width from inline box available width --- tests/test_float.py | 110 +++++++++++++++++++++++++++++++++++- weasyprint/layout/inline.py | 2 + 2 files changed, 111 insertions(+), 1 deletion(-) diff --git a/tests/test_float.py b/tests/test_float.py index 449abcd1..6a2edc1d 100644 --- a/tests/test_float.py +++ b/tests/test_float.py @@ -510,7 +510,7 @@ def test_preferred_widths_5(): @assert_no_logs -def test_float_in_inline(): +def test_float_in_inline_1(): page, = render_pages(''' +
+ +
a b c
+ 1 2 3 4 5 6 +
+
''') + html, = page.children + body, = html.children + article, = body.children + line1, line2 = article.children + span1, = line1.children + div, text = span1.children + assert div.children[0].children[0].text.strip() == 'a b c' + assert text.text.strip() == '1 2 3' + span2, = line2.children + text, = span2.children + assert text.text.strip() == '4 5 6' + + +@assert_no_logs +def test_float_in_inline_3(): + page, = render_pages(''' + +
+ + 1 2 3
a b c
4 5 6 +
+
''') + html, = page.children + body, = html.children + article, = body.children + line1, line2 = article.children + span1, = line1.children + text, div = span1.children + assert text.text.strip() == '1 2 3' + assert div.children[0].children[0].text.strip() == 'a b c' + span2, = line2.children + text, = span2.children + assert text.text.strip() == '4 5 6' + + +@assert_no_logs +def test_float_in_inline_4(): + page, = render_pages(''' + +
+ + 1 2 3 4
a b c
5 6 +
+
''') + html, = page.children + body, = html.children + article, = body.children + line1, line2 = article.children + span1, div = line1.children + text1, text2 = span1.children + assert text1.text.strip() == '1 2 3 4' + assert text2.text.strip() == '5' + assert div.position_y == 16 + assert div.children[0].children[0].text.strip() == 'a b c' + span2, = line2.children + text, = span2.children + assert text.text.strip() == '6' + + @assert_no_logs def test_float_next_line(): page, = render_pages(''' diff --git a/weasyprint/layout/inline.py b/weasyprint/layout/inline.py index e6410722..f91e6f52 100644 --- a/weasyprint/layout/inline.py +++ b/weasyprint/layout/inline.py @@ -709,6 +709,8 @@ def split_inline_box(context, box, position_x, max_x, skip_stack, max_x, position_x) if child.is_floated(): float_resume_index = index + 1 + if child not in waiting_floats: + max_x -= child.margin_width() continue is_last_child = (index == len(box.children) - 1)