From 35f005062431d299b622e5c2fa576ac280136cf4 Mon Sep 17 00:00:00 2001 From: Johannes Duschl Date: Tue, 27 May 2014 17:22:31 +0200 Subject: [PATCH 1/5] Respect page-break-after: avoid of previous elements when pushing floats to the next page --- weasyprint/layout/blocks.py | 9 +++ weasyprint/tests/test_layout.py | 119 ++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+) diff --git a/weasyprint/layout/blocks.py b/weasyprint/layout/blocks.py index 69d9864a8..cd47ba7ea 100644 --- a/weasyprint/layout/blocks.py +++ b/weasyprint/layout/blocks.py @@ -289,6 +289,15 @@ def block_container_layout(context, box, max_position_y, skip_stack, new_child.index = index new_children.append(new_child) else: + if new_children \ + and new_children[-1].style.page_break_after \ + == 'avoid': + result = find_earlier_page_break( + new_children, absolute_boxes, fixed_boxes) + if result: + new_children, resume_at = result + break + resume_at = (index, None) break continue diff --git a/weasyprint/tests/test_layout.py b/weasyprint/tests/test_layout.py index 26d97d934..c9416bf31 100644 --- a/weasyprint/tests/test_layout.py +++ b/weasyprint/tests/test_layout.py @@ -4584,6 +4584,125 @@ def test_floats_page_breaks(): assert positions_y == [[10, 40], [10, 40], [10]] + # last float does not fit, pushed to next page + pages = parse(''' + + +
+
+
+ ''') + + assert len(pages) == 2 + page_divs = [] + for page in pages: + divs = [div for div in page.descendants() if div.element_tag == 'div'] + assert all([div.element_tag == 'div' for div in divs]) + page_divs.append(divs) + del divs + + positions_y = [[div.position_y for div in divs] + for divs in page_divs] + assert positions_y == [[10, 70], [10]] + + + # last float does not fit, pushed to next page + # center div must not + pages = parse(''' + + +
+
+
+ ''') + + assert len(pages) == 2 + page_divs = [] + for page in pages: + divs = [div for div in page.descendants() if div.element_tag == 'div'] + assert all([div.element_tag == 'div' for div in divs]) + page_divs.append(divs) + del divs + + positions_y = [[div.position_y for div in divs] + for divs in page_divs] + assert positions_y == [[10], [10, 30]] + + # center div must be the last element, + # but float won't fit and will get pushed anyway + pages = parse(''' + + +
+
+
+ ''') + + assert len(pages) == 3 + page_divs = [] + for page in pages: + divs = [div for div in page.descendants() if div.element_tag == 'div'] + assert all([div.element_tag == 'div' for div in divs]) + page_divs.append(divs) + del divs + + positions_y = [[div.position_y for div in divs] + for divs in page_divs] + assert positions_y == [[10], [10], [10]] + + + + @assert_no_logs def test_font_stretch(): page, = parse(''' From 324255ba591b2decc3bd0ef3ab8347421495a275 Mon Sep 17 00:00:00 2001 From: Johannes Duschl Date: Tue, 27 May 2014 17:24:42 +0200 Subject: [PATCH 2/5] Removed blank line --- weasyprint/layout/blocks.py | 1 - 1 file changed, 1 deletion(-) diff --git a/weasyprint/layout/blocks.py b/weasyprint/layout/blocks.py index cd47ba7ea..dc507decf 100644 --- a/weasyprint/layout/blocks.py +++ b/weasyprint/layout/blocks.py @@ -297,7 +297,6 @@ def block_container_layout(context, box, max_position_y, skip_stack, if result: new_children, resume_at = result break - resume_at = (index, None) break continue From 81796cae34f46ebbafc87a0678e87b5c78c11ffc Mon Sep 17 00:00:00 2001 From: Johannes Duschl Date: Tue, 27 May 2014 17:38:13 +0200 Subject: [PATCH 3/5] Remove trailing white spaces --- weasyprint/tests/test_layout.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/weasyprint/tests/test_layout.py b/weasyprint/tests/test_layout.py index c9416bf31..16051d160 100644 --- a/weasyprint/tests/test_layout.py +++ b/weasyprint/tests/test_layout.py @@ -4583,7 +4583,6 @@ def test_floats_page_breaks(): for images in page_images] assert positions_y == [[10, 40], [10, 40], [10]] - # last float does not fit, pushed to next page pages = parse('''