Skip to content

Commit 9641098

Browse files
committedApr 25, 2022
Stop rendering when column content doesn’t fit in the page
1 parent e9987fd commit 9641098

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed
 

‎tests/layout/test_column.py

+82
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,88 @@ def test_column_span_6():
301301
assert section.children[0].children[0].text == 'line1'
302302
assert (section.position_x, section.position_y) == (0, 0)
303303

304+
305+
@assert_no_logs
306+
def test_column_span_7():
307+
page1, page2 = render_pages('''
308+
<style>
309+
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
310+
@page { margin: 0; size: 8px 3px }
311+
body { font-family: weasyprint; font-size: 1px }
312+
div { columns: 2; column-gap: 0; line-height: 1 }
313+
section { column-span: all; font-size: 2px }
314+
</style>
315+
<div>
316+
abc def
317+
ghi jkl
318+
<section>l1</section>
319+
mno pqr
320+
</div>
321+
''')
322+
html, = page1.children
323+
body, = html.children
324+
div, = body.children
325+
column1, column2 = div.children
326+
assert (column1.position_x, column1.position_y) == (0, 0)
327+
assert (column2.position_x, column2.position_y) == (4, 0)
328+
329+
assert column1.children[0].children[0].children[0].text == 'abc'
330+
assert column1.children[0].children[1].children[0].text == 'def'
331+
assert column2.children[0].children[0].children[0].text == 'ghi'
332+
assert column2.children[0].children[1].children[0].text == 'jkl'
333+
334+
html, = page2.children
335+
body, = html.children
336+
div, = body.children
337+
section, column1, column2 = div.children
338+
assert (section.position_x, section.position_y) == (0, 0)
339+
assert (column1.position_x, column1.position_y) == (0, 2)
340+
assert (column2.position_x, column2.position_y) == (4, 2)
341+
342+
assert section.children[0].children[0].text == 'l1'
343+
assert column1.children[0].children[0].children[0].text == 'mno'
344+
assert column2.children[0].children[0].children[0].text == 'pqr'
345+
346+
347+
@assert_no_logs
348+
def test_column_span_8():
349+
page1, page2 = render_pages('''
350+
<style>
351+
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
352+
@page { margin: 0; size: 8px 2px }
353+
body { font-family: weasyprint; font-size: 1px }
354+
div { columns: 2; column-gap: 0; line-height: 1 }
355+
section { column-span: all }
356+
</style>
357+
<div>
358+
abc def
359+
ghi jkl
360+
mno pqr
361+
<section>line1</section>
362+
</div>
363+
''')
364+
html, = page1.children
365+
body, = html.children
366+
div, = body.children
367+
column1, column2 = div.children
368+
assert (column1.position_x, column1.position_y) == (0, 0)
369+
assert (column2.position_x, column2.position_y) == (4, 0)
370+
371+
assert column1.children[0].children[0].children[0].text == 'abc'
372+
assert column1.children[0].children[1].children[0].text == 'def'
373+
assert column2.children[0].children[0].children[0].text == 'ghi'
374+
assert column2.children[0].children[1].children[0].text == 'jkl'
375+
376+
html, = page2.children
377+
body, = html.children
378+
div, = body.children
379+
column1, column2, section = div.children
380+
assert (column1.position_x, column1.position_y) == (0, 0)
381+
assert (column2.position_x, column2.position_y) == (4, 0)
382+
assert (section.position_x, section.position_y) == (0, 1)
383+
384+
assert column1.children[0].children[0].children[0].text == 'mno'
385+
assert column2.children[0].children[0].children[0].text == 'pqr'
304386
assert section.children[0].children[0].text == 'line1'
305387

306388

‎weasyprint/layout/column.py

+6
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ def create_column_box(children):
174174
first_probe_run = True
175175
original_page_is_empty = page_is_empty
176176
page_is_empty = False
177+
stop_rendering = False
177178
while True:
178179
column_skip_stack = skip_stack
179180

@@ -251,6 +252,7 @@ def create_column_box(children):
251252
if column_skip_stack or max(consumed_heights) > max_height:
252253
# Even at maximum height, not everything fits. Stop now and
253254
# let the columns continue on the next page.
255+
stop_rendering = True
254256
break
255257
else:
256258
# Everything fit, start expanding columns at the average of
@@ -274,6 +276,7 @@ def create_column_box(children):
274276

275277
if height + add_height > max_height:
276278
height = max_height
279+
stop_rendering = True
277280
break
278281

279282
height += add_height
@@ -328,6 +331,9 @@ def create_column_box(children):
328331
skip_stack = None
329332
page_is_empty = False
330333

334+
if stop_rendering:
335+
break
336+
331337
if box.children and not new_children:
332338
# The box has children but none can be drawn, let's skip the whole box
333339
context.in_column = False

0 commit comments

Comments
 (0)
Please sign in to comment.