Skip to content

Commit

Permalink
Correctly draw borders on the last line of split tables
Browse files Browse the repository at this point in the history
The previous logic used to find if a row is in the footer was broken. Code is
now cleaner, shorter, with an example in comments and a non-regression test.

Fix #1250.
  • Loading branch information
liZe committed Nov 23, 2020
1 parent 3e48724 commit f0231c8
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 8 deletions.
14 changes: 6 additions & 8 deletions weasyprint/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,21 +896,19 @@ def draw_collapsed_borders(context, table, enable_hinting):
body_rows_offset = skipped_rows - header_rows
else:
body_rows_offset = 0
if header_rows == 0:
header_rows = -1
if footer_rows:
first_footer_row = grid_height - footer_rows - 1
else:
first_footer_row = grid_height + 1
original_grid_height = len(vertical_borders)
footer_rows_offset = original_grid_height - grid_height

def row_number(y, horizontal):
if y < (header_rows + int(horizontal)):
# Examples in comments for 2 headers rows, 5 body rows, 3 footer rows
if header_rows and y < header_rows + int(horizontal):
# Row in header: y < 2 for vertical, y < 3 for horizontal
return y
elif y >= (first_footer_row + int(horizontal)):
elif footer_rows and y >= grid_height - footer_rows - int(horizontal):
# Row in footer: y >= 7 for vertical, y >= 6 for horizontal
return y + footer_rows_offset
else:
# Row in body: 2 >= y > 7 for vertical, 3 >= y > 6 for horizontal
return y + body_rows_offset

segments = []
Expand Down
56 changes: 56 additions & 0 deletions weasyprint/tests/test_draw/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,3 +1048,59 @@ def test_tables_14():
x-col { background: red }
x-td { padding: 0; width: 1px; height: 8px }
'''})


@assert_no_logs
@requires('cairo', (1, 12, 0))
def test_tables_15():
# Regression test for colspan in last body line with footer
# https://github.com/Kozea/WeasyPrint/issues/1250
assert_pixels('colspan_last_row', 22, 36, '''
______________________
__RRRRRRRRRRRRRRRRRR__
__R_____R____R_____R__
__R_____R____R_____R__
__R_____R____R_____R__
__RRRRRRRRRRRRRRRRRR__
__R_____R____R_____R__
__R_____R____R_____R__
_BBBBBBBBBBBBBBBBBBBB_
_BBBBBBBBBBBBBBBBBBBB_
_BBB____R____R____BBB_
_BBB____R____R____BBB_
_BBB____R____R____BBB_
_BBBBBBBBBBBBBBBBBBBB_
_BBBBBBBBBBBBBBBBBBBB_
______________________
______________________
______________________
______________________
__RRRRRRRRRRRRRRRRRR__
__R________________R__
__R________________R__
__R________________R__
_BBBBBBBBBBBBBBBBBBBB_
_BBBBBBBBBBBBBBBBBBBB_
_BBB____R____R____BBB_
_BBB____R____R____BBB_
_BBB____R____R____BBB_
_BBBBBBBBBBBBBBBBBBBB_
_BBBBBBBBBBBBBBBBBBBB_
______________________
______________________
______________________
______________________
______________________
______________________
''', '''
<style>
@page { size: 22px 18px; margin: 1px; background: #fff }
td { border: 1px red solid; width: 4px; height: 3px; }
</style>
<table style="table-layout: fixed; margin-left: 1px;
border-collapse: collapse">
<tr><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td></tr>
<tr><td colspan="3"></td></tr>
<tfoot style="border: blue solid; border-width: 2px 3px;
"><td></td><td></td><td></td></tfoot>''')

0 comments on commit f0231c8

Please sign in to comment.