Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix right-to-left tables with collapsed borders #2058

Merged
merged 3 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions tests/draw/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,106 @@ def test_tables_23(assert_pixels):
<tbody><tr><td>abc abc</td><td></td></tr></tbody>''')


@assert_no_logs
def test_tables_24(assert_pixels):
assert_pixels('''
__________________
_RKKKKgYYYYYYGGG__
_RKKKKgKKYYKKGGG__
_BBBBBBKKYYKKGGG__
_BBBBBBYYYYYYGGG__
_BBBBBBCCCCCCGGG__
_BBBBBB___________
_BBBBBB___________
__________________
__________________
''', '''
<style>
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
@page { size: 18px 10px }
table {
border-collapse: collapse;
font: 2px/1 weasyprint;
margin: 1px;
}
tr {
border-left: 1px solid red;
border-right: 3px solid lime;
}
td.left {
background-color: magenta;
border-bottom: 5px solid blue;
border-right: 1px solid green;
}
td.right {
background-color: yellow;
border-bottom: 1px solid cyan;
border-left: 1px dotted orange;
}
td {
vertical-align: middle;
}
</style>
<table>
<tr>
<td class="left">XX</td>
<td class="right">X X</td>
</tr>
</table>
''')


@assert_no_logs
def test_tables_24_rtl(assert_pixels):
assert_pixels('''
__________________
_RKKKKgYYYYYYGGG__
_RKKKKgKKYYKKGGG__
_BBBBBBKKYYKKGGG__
_BBBBBBYYYYYYGGG__
_BBBBBBCCCCCCGGG__
_BBBBBB___________
_BBBBBB___________
__________________
__________________
''', '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page { size: 18px 10px }
table {
border-collapse: collapse;
direction: rtl;
font: 2px/1 weasyprint;
margin: 1px;
}
tr {
border-left: 1px solid red;
border-right: 3px solid lime;
}
td.left {
background-color: magenta;
border-bottom: 5px solid blue;
border-right: 1px solid green;
}
td.right {
background-color: yellow;
border-bottom: 1px solid cyan;
border-left: 1px dotted orange;
}
td {
vertical-align: middle;
}
</style>
<table>
<tr>
<td class="right">X X</td>
<td class="left">XX</td>
</tr>
</table>
''')



@assert_no_logs
def test_running_elements_table_border_collapse(assert_pixels):
assert_pixels(2 * '''
Expand Down
19 changes: 6 additions & 13 deletions weasyprint/draw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,11 @@ def draw_collapsed_borders(stream, table):
grid_height = len(row_heights)
grid_width = len(column_widths)
assert grid_width == len(column_positions)
# Add the end of the last column, but make a copy from the table attr.
if table.style['direction'] == 'ltr':
column_positions.append(column_positions[-1] + column_widths[-1])
else:
column_positions.insert(0, column_positions[0] + column_widths[0])
# Add the end of the last row. No copy here, we own this list.
row_positions.append(row_positions[-1] + row_heights[-1])
vertical_borders, horizontal_borders = table.collapsed_border_grid
# Add the end of the last column.
column_positions.append(column_positions[-1] + column_widths[-1])
# Add the end of the last row.
row_positions.append(row_positions[-1] + row_heights[-1])
if table.children[0].is_header:
header_rows = len(table.children[0].children)
else:
Expand Down Expand Up @@ -444,12 +441,8 @@ def add_horizontal(x, y):
pos_y = row_positions[y]
shift_before = half_max_width(vertical_borders, [(y - 1, x), (y, x)])
shift_after = half_max_width(vertical_borders, [(y - 1, x + 1), (y, x + 1)])
if table.style['direction'] == 'ltr':
pos_x1 = column_positions[x] - shift_before
pos_x2 = column_positions[x + 1] + shift_after
else:
pos_x1 = column_positions[x + 1] - shift_after
pos_x2 = column_positions[x] + shift_before
pos_x1 = column_positions[x] - shift_before
pos_x2 = column_positions[x + 1] + shift_after
segments.append((
score, style, width, color, 'top', (pos_x1, pos_y, pos_x2 - pos_x1, 0)))

Expand Down
Loading
Loading