Skip to content

Commit

Permalink
Correctly detect empty split lines at the end of tables
Browse files Browse the repository at this point in the history
The previous detection was failing when some cells were empty (or fully
rendered) and when the current rendering position was not overflowing the page.
In this case, the line with empty cells was rendered and was visible for
example when cells had padding.
  • Loading branch information
liZe committed Jul 7, 2022
1 parent 3bd9a8e commit cb9540b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
37 changes: 37 additions & 0 deletions tests/draw/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,3 +1198,40 @@ def test_tables_20(assert_pixels):
<col></col><col></col>
<tbody><tr></tr><tr><td></td></tr></tbody>
<tfoot></tfoot>''')


@assert_no_logs
def test_tables_21(assert_pixels):
assert_pixels('''
_________________________
_rrrrrrrrrrrrrrrrrrrrrrr_
_rBBBBBBBBBBrBBBBBBBBBBr_
_rBKKKKKKBBBrBKKKKKKBBBr_
_rBKKKKKKBBBrBKKKKKKBBBr_
_rBBBBBBBBBBrBBBBBBBBBBr_
_rrrrrrrrrrrrrrrrrrrrrrr_
_________________________
_________________________
_________________________
_________________________
_________________________
_rrrrrrrrrrrrrrrrrrrrrrr_
_rBBBBBBBBBBrBBBBBBBBBBr_
_rBKKKKKKBBBrBBBBBBBBBBr_
_rBKKKKKKBBBrBBBBBBBBBBr_
_rBBBBBBBBBBrBBBBBBBBBBr_
_rrrrrrrrrrrrrrrrrrrrrrr_
_________________________
_________________________
_________________________
_________________________
''', '''
<style>
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
@page { size: 25px 11px; margin: 1px }
table { border-collapse: collapse; font: 2px weasyprint; width: 100% }
td { background: blue; padding: 1px; border: 1px solid red }
</style>
<table>
<tr><td>abc</td><td>abc</td></tr>
<tr><td>abc</td><td></td></tr>''')
16 changes: 5 additions & 11 deletions weasyprint/layout/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,11 @@ def group_layout(group, position_y, bottom_space, page_is_empty,
# Break if one cell was broken
break_cell = False
if resume_at:
values, = list(resume_at.values())
if len(row.children) == len(values):
for cell_resume_at in values.values():
if cell_resume_at != {0: None}:
break_cell = True
break
else:
# No cell was displayed, give up row
next_position_y = inf
page_is_empty = False
resume_at = None
if all(child.empty for child in row.children):
# No cell was displayed, give up row
next_position_y = inf
page_is_empty = False
resume_at = None
else:
break_cell = True

Expand Down

0 comments on commit cb9540b

Please sign in to comment.