Skip to content

Commit

Permalink
Fix the way column rules are drawn
Browse files Browse the repository at this point in the history
liZe committed Aug 18, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 22d6362 commit 9a4c5fc
Showing 2 changed files with 44 additions and 2 deletions.
31 changes: 31 additions & 0 deletions tests/draw/test_column.py
Original file line number Diff line number Diff line change
@@ -49,3 +49,34 @@ def test_column_rule_2(assert_pixels):
<img src=blue.jpg>
<img src=blue.jpg>
</div>''')


@assert_no_logs
def test_column_rule_span(assert_pixels):
assert_pixels('''
___________
___________
___________
___a_______
___a_r_a___
___a_r_a___
___________
___________
___________
''', '''
<style>
img { display: inline-block; width: 1px; height: 1px }
div { columns: 2; column-rule: 1px solid red; column-gap: 3px }
article { column-span: all }
body { margin: 0; font-size: 0 }
@page { margin: 3px; size: 11px 9px }
</style>
<div>
<article>
<img src=blue.jpg>
</article>
<img src=blue.jpg>
<img src=blue.jpg>
<img src=blue.jpg>
<img src=blue.jpg>
</div>''')
15 changes: 13 additions & 2 deletions weasyprint/draw.py
Original file line number Diff line number Diff line change
@@ -415,6 +415,17 @@ def draw_border(stream, box):
# We need a plan to draw beautiful borders, and that's difficult, no need
# to lie. Let's try to find the cases that we can handle in a smart way.

def get_columns_with_rule():
"""Yield columns that have a rule drawn on the left."""
skip_next = True
for child in box.children:
if child.style['column_span'] == 'all':
skip_next = True
elif skip_next:
skip_next = False
else:
yield child

def draw_column_border():
"""Draw column borders."""
columns = (
@@ -423,14 +434,14 @@ def draw_column_border():
box.style['column_count'] != 'auto'))
if columns and box.style['column_rule_width']:
border_widths = (0, 0, 0, box.style['column_rule_width'])
for child in box.children[1:]:
for child in get_columns_with_rule():
with stacked(stream):
position_x = (child.position_x - (
box.style['column_rule_width'] +
box.style['column_gap']) / 2)
border_box = (
position_x, child.position_y,
box.style['column_rule_width'], box.height)
box.style['column_rule_width'], child.height)
clip_border_segment(
stream, box.style['column_rule_style'],
box.style['column_rule_width'], 'left', border_box,

0 comments on commit 9a4c5fc

Please sign in to comment.