Skip to content

Commit

Permalink
Use margin box of children to define available width for leaders
Browse files Browse the repository at this point in the history
Fix #1946.
  • Loading branch information
liZe committed Aug 31, 2023
1 parent 3fdd3c5 commit 7d45356
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 1 deletion.
136 changes: 136 additions & 0 deletions tests/draw/test_leader.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,139 @@ def test_leader_absolute(assert_pixels):
</style>
<div>aa<article>bb</article>aa</div>
''')


@assert_no_logs
def test_leader_padding(assert_pixels):
assert_pixels('''
RR__BBBBBBBB__BB
RR__BBBBBBBB__BB
__RR__BBBB__BBBB
__RR__BBBB__BBBB
''', '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
size: 16px 4px;
}
body {
color: red;
counter-reset: count;
font-family: weasyprint;
font-size: 2px;
line-height: 1;
}
div::after {
color: blue;
content: ' ' leader(dotted) ' ' counter(count, lower-roman);
counter-increment: count;
}
div + div {
padding-left: 2px;
}
</style>
<div>a</div>
<div>b</div>
''')


@assert_no_logs
def test_leader_inline_padding(assert_pixels):
assert_pixels('''
RR__BBBBBBBB__BB
RR__BBBBBBBB__BB
__RR__BBBB__BBBB
__RR__BBBB__BBBB
''', '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
size: 16px 4px;
}
body {
color: red;
counter-reset: count;
font-family: weasyprint;
font-size: 2px;
line-height: 1;
}
span::after {
color: blue;
content: ' ' leader(dotted) ' ' counter(count, lower-roman);
counter-increment: count;
}
div + div span {
padding-left: 2px;
}
</style>
<div><span>a</span></div>
<div><span>b</span></div>
''')


@assert_no_logs
def test_leader_margin(assert_pixels):
assert_pixels('''
RR__BBBBBBBB__BB
RR__BBBBBBBB__BB
__RR__BBBB__BBBB
__RR__BBBB__BBBB
''', '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
size: 16px 4px;
}
body {
color: red;
counter-reset: count;
font-family: weasyprint;
font-size: 2px;
line-height: 1;
}
div::after {
color: blue;
content: ' ' leader(dotted) ' ' counter(count, lower-roman);
counter-increment: count;
}
div + div {
margin-left: 2px;
}
</style>
<div>a</div>
<div>b</div>
''')


@assert_no_logs
def test_leader_inline_margin(assert_pixels):
assert_pixels('''
RR__BBBBBBBB__BB
RR__BBBBBBBB__BB
__RR__BBBB__BBBB
__RR__BBBB__BBBB
''', '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
size: 16px 4px;
}
body {
color: red;
counter-reset: count;
font-family: weasyprint;
font-size: 2px;
line-height: 1;
}
span::after {
color: blue;
content: ' ' leader(dotted) ' ' counter(count, lower-roman);
counter-increment: count;
}
div + div span {
margin-left: 2px;
}
</style>
<div><span>a</span></div>
<div><span>b</span></div>
''')
2 changes: 1 addition & 1 deletion weasyprint/layout/leader.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def handle_leader(context, line, containing_block):

# Extra width is the additional width taken by the leader box
extra_width = containing_block.width - sum(
child.width for child in line.children
child.margin_width() for child in line.children
if child.is_in_normal_flow())

# Take care of excluded shapes
Expand Down

0 comments on commit 7d45356

Please sign in to comment.