Skip to content

Commit

Permalink
Don’t crash with normal column gap
Browse files Browse the repository at this point in the history
Fix #2217.
  • Loading branch information
liZe committed Aug 1, 2024
1 parent 8b210bd commit 3f07e03
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
22 changes: 22 additions & 0 deletions tests/draw/test_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,25 @@ def test_column_rule_span(assert_pixels):
<img src=blue.jpg>
<img src=blue.jpg>
</div>''')


@assert_no_logs
def test_column_rule_normal(assert_pixels):
# Test regression: https://github.com/Kozea/WeasyPrint/issues/2217
assert_pixels('''
a___a
a___a
_____
''', '''
<style>
img { display: inline-block; width: 1px; height: 1px }
div { columns: 2; column-gap: normal }
body { margin: 0; font-size: 3px; line-height: 0 }
@page { margin: 0; size: 5px 3px }
</style>
<div>
<img src=blue.jpg>
<img src=blue.jpg>
<img src=blue.jpg>
<img src=blue.jpg>
</div>''')
5 changes: 4 additions & 1 deletion weasyprint/draw/border.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ def draw_border(stream, box):
with stacked(stream):
rule_width = box.style['column_rule_width']
rule_style = box.style['column_rule_style']
gap = percentage(box.style['column_gap'], box.width)
if box.style['column_gap'] == 'normal':
gap = box.style['font_size'] # normal equals 1em
else:
gap = percentage(box.style['column_gap'], box.width)
position_x = (
child.position_x - (box.style['column_rule_width'] + gap) / 2)
border_box = (position_x, child.position_y, rule_width, child.height)
Expand Down

0 comments on commit 3f07e03

Please sign in to comment.