Skip to content

Commit

Permalink
Handle recto/verso on page break.
Browse files Browse the repository at this point in the history
  • Loading branch information
grewn0uille committed Jul 18, 2019
1 parent 204e719 commit 135dc06
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
13 changes: 10 additions & 3 deletions weasyprint/layout/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
23 changes: 23 additions & 0 deletions weasyprint/tests/test_layout/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('''
<style>
html { direction: %s }
p { break-before: %s }
</style>
abc
<p>def</p>
''' % (direction, page_break))
assert len(pages) == pages_number


@assert_no_logs
def test_page_names_1():
pages = render_pages('''
Expand Down

0 comments on commit 135dc06

Please sign in to comment.