From 3943e672b87a4cb65f7fcad4b41d8edc7ce05a4a Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Fri, 15 Mar 2019 22:32:36 +0100 Subject: [PATCH] Fix box-decoration-text for inline boxes And add related tests of course! Related to #771. --- weasyprint/layout/inlines.py | 8 ++- weasyprint/tests/test_layout/test_inline.py | 62 +++++++++++++++++++++ 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/weasyprint/layout/inlines.py b/weasyprint/layout/inlines.py index 2a367489a..6720c9d83 100644 --- a/weasyprint/layout/inlines.py +++ b/weasyprint/layout/inlines.py @@ -922,8 +922,12 @@ def split_inline_box(context, box, position_x, max_x, skip_stack, new_box.width = 0 else: new_box.position_x = initial_position_x - if (is_start and box.style['direction'] == 'ltr') or ( - is_end and box.style['direction'] == 'rtl'): + if box.style['box_decoration_break'] == 'clone': + translation_needed = True + else: + translation_needed = ( + is_start if box.style['direction'] == 'ltr' else is_end) + if translation_needed: for child in new_box.children: child.translate(dx=left_spacing) new_box.width = position_x - content_box_left diff --git a/weasyprint/tests/test_layout/test_inline.py b/weasyprint/tests/test_layout/test_inline.py index f71bfc34b..8018dc4dd 100644 --- a/weasyprint/tests/test_layout/test_inline.py +++ b/weasyprint/tests/test_layout/test_inline.py @@ -854,3 +854,65 @@ def test_vertical_align_13(): img_1, = line_2.children assert img_1.element_tag == 'img' assert img_1.position_y == 0 + + +@assert_no_logs +def test_box_decoration_break_inline_slice(): + # http://www.w3.org/TR/css3-background/#the-box-decoration-break + page_1, = parse(''' + + a
b
c
''') + html, = page_1.children + body, = html.children + line_1, line_2, line_3 = body.children + span, = line_1.children + assert span.width == 16 + assert span.margin_width() == 16 + 5 + 1 + text, br = span.children + assert text.position_x == 5 + 1 + span, = line_2.children + assert span.width == 16 + assert span.margin_width() == 16 + text, br = span.children + assert text.position_x == 0 + span, = line_3.children + assert span.width == 16 + assert span.margin_width() == 16 + 5 + 1 + text, = span.children + assert text.position_x == 0 + + +@assert_no_logs +def test_box_decoration_break_inline_clone(): + # http://www.w3.org/TR/css3-background/#the-box-decoration-break + page_1, = parse(''' + + a
b
c
''') + html, = page_1.children + body, = html.children + line_1, line_2, line_3 = body.children + span, = line_1.children + assert span.width == 16 + assert span.margin_width() == 16 + 2 * (5 + 1) + text, br = span.children + assert text.position_x == 5 + 1 + span, = line_2.children + assert span.width == 16 + assert span.margin_width() == 16 + 2 * (5 + 1) + text, br = span.children + assert text.position_x == 5 + 1 + span, = line_3.children + assert span.width == 16 + assert span.margin_width() == 16 + 2 * (5 + 1) + text, = span.children + assert text.position_x == 5 + 1