Skip to content

Commit

Permalink
Fix box-decoration-text for inline boxes
Browse files Browse the repository at this point in the history
And add related tests of course!

Related to #771.
  • Loading branch information
liZe committed Mar 15, 2019
1 parent 468e6fe commit 3943e67
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
8 changes: 6 additions & 2 deletions weasyprint/layout/inlines.py
Expand Up @@ -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
Expand Down
62 changes: 62 additions & 0 deletions weasyprint/tests/test_layout/test_inline.py
Expand Up @@ -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('''
<style>
@font-face { src: url(AHEM____.TTF); font-family: ahem }
@page { size: 100px }
span { font-family: ahem; box-decoration-break: slice;
padding: 5px; border: 1px solid black }
</style>
<span>a<br/>b<br/>c</span>''')
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('''
<style>
@font-face { src: url(AHEM____.TTF); font-family: ahem }
@page { size: 100px }
span { font-family: ahem; box-decoration-break: clone;
padding: 5px; border: 1px solid black }
</style>
<span>a<br/>b<br/>c</span>''')
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

0 comments on commit 3943e67

Please sign in to comment.