Repository: Kozea/WeasyPrint

Issue:
Balance columns before "column-span: all"
Is the [column-span](https://www.w3.org/TR/css-multicol-1/#column-span) attribute correctly handled? In my experimentation it seems just ignored, but maybe I am missing something. I used it as a property of an img tag.

Discussion:

Patch:
diff --git a/weasyprint/layout/column.py b/weasyprint/layout/column.py
index deb7e17f..6f6e2c6d 100644
--- a/weasyprint/layout/column.py
+++ b/weasyprint/layout/column.py
@@ -261,7 +261,8 @@ def columns_layout(context, box, bottom_space, skip_stack, containing_block,
                     # Everything fits, start expanding columns at the average
                     # of the column heights
                     max_height -= last_footnotes_height
-                    if style['column_fill'] == 'balance':
+                    if (style['column_fill'] == 'balance' or
+                            index < columns_and_blocks[-1][0]):
                         balancing = True
                         height = sum(consumed_heights) / count
                     else:


Test patch:
diff --git a/tests/layout/test_column.py b/tests/layout/test_column.py
index be266bd2..bb7fe4c3 100644
--- a/tests/layout/test_column.py
+++ b/tests/layout/test_column.py
@@ -417,6 +417,38 @@ def test_column_span_9():
     assert column3.children[0].children[0].children[0].text == 'ghi'
 
 
+@assert_no_logs
+def test_column_span_balance():
+    page, = render_pages('''
+      <style>
+        @font-face { src: url(weasyprint.otf); font-family: weasyprint }
+        @page { margin: 0; size: 8px 5px }
+        body { font-family: weasyprint; font-size: 1px }
+        div { columns: 2; column-gap: 0; line-height: 1; column-fill: auto }
+        section { column-span: all }
+      </style>
+      <div>
+        abc def
+        <section>line1</section>
+        ghi jkl
+      </div>
+    ''')
+    html, = page.children
+    body, = html.children
+    div, = body.children
+    column1, column2, section, column3 = div.children
+    assert (column1.position_x, column1.position_y) == (0, 0)
+    assert (column2.position_x, column2.position_y) == (4, 0)
+    assert (section.position_x, section.position_y) == (0, 1)
+    assert (column3.position_x, column3.position_y) == (0, 2)
+
+    assert column1.children[0].children[0].children[0].text == 'abc'
+    assert column2.children[0].children[0].children[0].text == 'def'
+    assert section.children[0].children[0].text == 'line1'
+    assert column3.children[0].children[0].children[0].text == 'ghi'
+    assert column3.children[0].children[1].children[0].text == 'jkl'
+
+
 @assert_no_logs
 def test_columns_multipage():
     page1, page2 = render_pages('''