diff --git a/weasyprint/layout/pages.py b/weasyprint/layout/pages.py index e621a01bc..43cca6e3b 100644 --- a/weasyprint/layout/pages.py +++ b/weasyprint/layout/pages.py @@ -716,9 +716,16 @@ def remake_page(index, context, root_box, html, style_for): page_state = copy.deepcopy(initial_page_state) next_page_name = initial_next_page['page'] first = index == 0 - # TODO: handle recto/verso and add test - blank = ((initial_next_page['break'] == 'left' and right_page) or - (initial_next_page['break'] == 'right' and not right_page)) + if initial_next_page['break'] in ('left', 'right'): + next_page_side = initial_next_page['break'] + elif initial_next_page['break'] in ('recto', 'verso'): + direction_ltr = root_box.style['direction'] == 'ltr' + break_verso = initial_next_page['break'] == 'verso' + next_page_side = 'right' if direction_ltr ^ break_verso else 'left' + else: + next_page_side = None + blank = ((next_page_side == 'left' and right_page) or + (next_page_side == 'right' and not right_page)) if blank: next_page_name = '' side = 'right' if right_page else 'left' diff --git a/weasyprint/tests/test_layout/test_page.py b/weasyprint/tests/test_layout/test_page.py index 5203b8186..e2c2e74b8 100644 --- a/weasyprint/tests/test_layout/test_page.py +++ b/weasyprint/tests/test_layout/test_page.py @@ -497,6 +497,29 @@ def test_margin_break_clearance(): assert div_2.content_box_y() == 5 +@assert_no_logs +@pytest.mark.parametrize('direction, page_break, pages_number', ( + ('ltr', 'recto', 3), + ('ltr', 'verso', 2), + ('rtl', 'recto', 3), + ('rtl', 'verso', 2), + ('ltr', 'right', 3), + ('ltr', 'left', 2), + ('rtl', 'right', 2), + ('rtl', 'left', 3), +)) +def test_recto_verso_break(direction, page_break, pages_number): + pages = render_pages(''' + + abc +

def

+ ''' % (direction, page_break)) + assert len(pages) == pages_number + + @assert_no_logs def test_page_names_1(): pages = render_pages('''