Skip to content

Commit 135dc06

Browse files
committed
Handle recto/verso on page break.
1 parent 204e719 commit 135dc06

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

weasyprint/layout/pages.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -716,9 +716,16 @@ def remake_page(index, context, root_box, html, style_for):
716716
page_state = copy.deepcopy(initial_page_state)
717717
next_page_name = initial_next_page['page']
718718
first = index == 0
719-
# TODO: handle recto/verso and add test
720-
blank = ((initial_next_page['break'] == 'left' and right_page) or
721-
(initial_next_page['break'] == 'right' and not right_page))
719+
if initial_next_page['break'] in ('left', 'right'):
720+
next_page_side = initial_next_page['break']
721+
elif initial_next_page['break'] in ('recto', 'verso'):
722+
direction_ltr = root_box.style['direction'] == 'ltr'
723+
break_verso = initial_next_page['break'] == 'verso'
724+
next_page_side = 'right' if direction_ltr ^ break_verso else 'left'
725+
else:
726+
next_page_side = None
727+
blank = ((next_page_side == 'left' and right_page) or
728+
(next_page_side == 'right' and not right_page))
722729
if blank:
723730
next_page_name = ''
724731
side = 'right' if right_page else 'left'

weasyprint/tests/test_layout/test_page.py

+23
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,29 @@ def test_margin_break_clearance():
497497
assert div_2.content_box_y() == 5
498498

499499

500+
@assert_no_logs
501+
@pytest.mark.parametrize('direction, page_break, pages_number', (
502+
('ltr', 'recto', 3),
503+
('ltr', 'verso', 2),
504+
('rtl', 'recto', 3),
505+
('rtl', 'verso', 2),
506+
('ltr', 'right', 3),
507+
('ltr', 'left', 2),
508+
('rtl', 'right', 2),
509+
('rtl', 'left', 3),
510+
))
511+
def test_recto_verso_break(direction, page_break, pages_number):
512+
pages = render_pages('''
513+
<style>
514+
html { direction: %s }
515+
p { break-before: %s }
516+
</style>
517+
abc
518+
<p>def</p>
519+
''' % (direction, page_break))
520+
assert len(pages) == pages_number
521+
522+
500523
@assert_no_logs
501524
def test_page_names_1():
502525
pages = render_pages('''

0 commit comments

Comments
 (0)