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

Propose fix for issue #1278 #1884

Merged
merged 26 commits into from
Jan 29, 2024
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ecc7941
Add test case for table with border-collapse in page margins
kygoh May 21, 2023
93e77a4
Backup border properties before setting to transparent borders
kygoh May 21, 2023
a9d0191
Restore original border properties before resolving border conflicts …
kygoh May 21, 2023
345d1f1
Coding style fix for lines exceeding 79 characters
kygoh May 21, 2023
4427d9f
Retain border width only when resolving collapsed borders
kygoh May 23, 2023
9e59b20
Store harmonized border-{...}-width in computed value collapse_border…
kygoh May 25, 2023
800a683
Set collapse_border_{...}_width as border_{...}_width used values in …
kygoh May 25, 2023
d87034f
Calculate margin width using collapse_border_{left,right}_width for c…
kygoh May 25, 2023
d4a79bc
Fix check for collapsed-borders mode in preferred margin width
kygoh May 25, 2023
fd1dbc7
Move collapsed-borders conflict resolution logic to layout.table module
kygoh May 26, 2023
0c9a6a1
Resolve border-{...}-width used values during collapsed-borders confl…
kygoh May 26, 2023
68f3486
Keep source updated
kygoh May 26, 2023
b3bdff8
Rename function to set used values for collapsed-borders width
kygoh May 26, 2023
16f8410
Sync source with upstream
kygoh May 31, 2023
bb382b5
Add references to computing table measures spec
kygoh May 31, 2023
5976f6d
Move collapse border test cases to layout
kygoh May 31, 2023
af141ba
Fix coding style
kygoh May 31, 2023
b18bbb3
Sync fix with master
kygoh Sep 3, 2023
6fc2eef
Test drawing for border collapse
liZe Sep 10, 2023
2a3747a
Mark extra test as xfail
liZe Sep 10, 2023
ce46dbe
Restore collapsed-borders conflict resolution to formatting_structure…
kygoh Sep 11, 2023
ce42883
Sync fix with master
kygoh Sep 18, 2023
d09ab65
Restore unit tests for collapsed borders conflict resolution logic
kygoh Sep 18, 2023
a9f719c
Merge branch 'main' into fix_issue_1278
liZe Jan 26, 2024
ad63510
Clean imports
liZe Jan 26, 2024
f11fcc4
Don’t store extra attributes only for tests
liZe Jan 26, 2024
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
220 changes: 220 additions & 0 deletions tests/draw/test_table.py
Original file line number Diff line number Diff line change
@@ -1298,3 +1298,223 @@ def test_tables_23(assert_pixels):
<table>
<thead><tr><td>abcde</td><td>abcde</td></tr></thead>
<tbody><tr><td>abc abc</td><td></td></tr></tbody>''')


@assert_no_logs
def test_running_elements_table_border_collapse(assert_pixels):
assert_pixels(2 * '''
KK_____________
KK_____________
_______________
_______________
_______________
KKKKKKK________
KRRKRRK________
KRRKRRK________
KKKKKKK________
KRRKRRK________
KRRKRRK________
KKKKKKK________
_______________
_______________
_______________
''', '''
<style>
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
@page {
margin: 0 0 10px 0;
size: 15px;
@bottom-left { content: element(table) }
}
body { font: 2px/1 weasyprint }
table {
border: 1px solid black;
border-collapse: collapse;
color: red;
position: running(table);
}
td { border: 1px solid black }
div { page-break-after: always }
</style>
<table>
<tr> <td>A</td> <td>B</td> </tr>
<tr> <td>C</td> <td>D</td> </tr>
</table>
<div>1</div>
<div>2</div>
''')


@assert_no_logs
def test_running_elements_table_border_collapse_empty(assert_pixels):
assert_pixels(2 * '''
KK________
KK________
__________
__________
__________
__________
__________
__________
__________
__________
''', '''
<style>
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
@page {
margin: 0 0 5px 0;
size: 10px;
@bottom-left { content: element(table) }
}
body { font: 2px/1 weasyprint }
table {
border: 1px solid black;
border-collapse: collapse;
color: red;
position: running(table);
}
td { border: 1px solid black }
div { page-break-after: always }
</style>
<table></table>
<div>1</div>
<div>2</div>
''')


@pytest.mark.xfail
@assert_no_logs
def test_running_elements_table_border_collapse_border_style(assert_pixels):
assert_pixels(2 * '''
KK_____________
KK_____________
_______________
_______________
_______________
KKKZ___________
KRR_RR_________
KRR_RR_________
KKKK__Z________
KRRKRRK________
KRRKRRK________
KKKKKKK________
_______________
_______________
_______________
''', '''
<style>
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
@page {
margin: 0 0 10px 0;
size: 15px;
@bottom-left { content: element(table) }
}
body { font: 2px/1 weasyprint }
table {
border: 1px solid black;
border-collapse: collapse;
color: red;
position: running(table);
}
td { border: 1px solid black }
div { page-break-after: always }
</style>
<table>
<tr> <td>A</td> <td style="border-style: hidden">B</td> </tr>
<tr> <td>C</td> <td style="border-style: none">D</td> </tr>
</table>
<div>1</div>
<div>2</div>
''')


@assert_no_logs
def test_running_elements_table_border_collapse_span(assert_pixels):
assert_pixels(2 * '''
KK_____________
KK_____________
_______________
_______________
_______________
KKKKKKKKKK_____
KRRKRRKRRK_____
KRRKRRKRRK_____
K__KKKKKKK_____
K__KRR___K_____
K__KRR___K_____
KKKKKKKKKK_____
_______________
_______________
_______________
''', '''
<style>
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
@page {
margin: 0 0 10px 0;
size: 15px;
@bottom-left { content: element(table) }
}
body { font: 2px/1 weasyprint }
table {
border: 1px solid black;
border-collapse: collapse;
color: red;
position: running(table);
}
td { border: 1px solid black }
div { page-break-after: always }
</style>
<table>
<tr> <td rowspan=2>A</td> <td>B</td> <td>C</td> </tr>
<tr> <td colspan=2>D</td> </tr>
</table>
<div>1</div>
<div>2</div>
''')


@pytest.mark.xfail
@assert_no_logs
def test_running_elements_table_border_collapse_margin(assert_pixels):
assert_pixels(2 * '''
KK_____________
KK_____________
_______________
_______________
_______________
_______________
____KKKKKKK____
____KRRKRRK____
____KRRKRRK____
____KKKKKKK____
____KRRKRRK____
____KRRKRRK____
____KKKKKKK____
_______________
_______________
''', '''
<style>
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
@page {
margin: 0 0 10px 0;
size: 15px;
@bottom-center { content: element(table); width: 100% }
}
body { font: 2px/1 weasyprint }
table {
border: 1px solid black;
border-collapse: collapse;
color: red;
margin: 1px auto;
position: running(table);
}
td { border: 1px solid black }
div { page-break-after: always }
</style>
<table>
<tr> <td>A</td> <td>B</td> </tr>
<tr> <td>C</td> <td>D</td> </tr>
</table>
<div>1</div>
<div>2</div>
''')
134 changes: 133 additions & 1 deletion tests/layout/test_table.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
"""Tests for layout of tables."""

import pytest
from weasyprint.formatting_structure import boxes
from weasyprint.layout.table import collapse_table_borders

from ..testing_utils import assert_no_logs, capture_logs, render_pages
from ..testing_utils import (
assert_no_logs, capture_logs, parse_all, render_pages)


def _get_grid(html, grid_width, grid_height):
html = parse_all(html)
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
border_lists = collapse_table_borders(table, grid_width, grid_height)
return tuple(
[[(style, width, color) if width else None
for _score, (style, width, color) in border]
for border in border_list]
for border_list in border_lists)


@assert_no_logs
@@ -2991,3 +3007,119 @@ def test_min_width_with_overflow():

assert table1_td1.min_width == table2_td1.min_width
assert table1_td1.width == table2_td1.width


black = (0, 0, 0, 1)
red = (1, 0, 0, 1)
green = (0, 1, 0, 1) # lime in CSS
blue = (0, 0, 1, 1)
yellow = (1, 1, 0, 1)
black_3 = ('solid', 3, black)
red_1 = ('solid', 1, red)
yellow_5 = ('solid', 5, yellow)
green_5 = ('solid', 5, green)
dashed_blue_5 = ('dashed', 5, blue)


@assert_no_logs
def test_border_collapse_1():
html = parse_all('<table></table>')
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
assert isinstance(table, boxes.TableBox)
assert not hasattr(table, 'collapsed_border_grid')

grid = _get_grid('<table style="border-collapse: collapse"></table>', 0, 0)
assert grid == ([], [])


@assert_no_logs
def test_border_collapse_2():
vertical_borders, horizontal_borders = _get_grid('''
<style>td { border: 1px solid red }</style>
<table style="border-collapse: collapse; border: 3px solid black">
<tr> <td>A</td> <td>B</td> </tr>
<tr> <td>C</td> <td>D</td> </tr>
</table>
''', 2, 2)
assert vertical_borders == [
[black_3, red_1, black_3],
[black_3, red_1, black_3],
]
assert horizontal_borders == [
[black_3, black_3],
[red_1, red_1],
[black_3, black_3],
]


@assert_no_logs
def test_border_collapse_3():
# hidden vs. none
vertical_borders, horizontal_borders = _get_grid('''
<style>table, td { border: 3px solid }</style>
<table style="border-collapse: collapse">
<tr> <td>A</td> <td style="border-style: hidden">B</td> </tr>
<tr> <td>C</td> <td style="border-style: none">D</td> </tr>
</table>
''', 2, 2)
assert vertical_borders == [
[black_3, None, None],
[black_3, black_3, black_3],
]
assert horizontal_borders == [
[black_3, None],
[black_3, None],
[black_3, black_3],
]


@assert_no_logs
def test_border_collapse_4():
vertical_borders, horizontal_borders = _get_grid('''
<style>td { border: 1px solid red }</style>
<table style="border-collapse: collapse; border: 5px solid yellow">
<col style="border: 3px solid black" />
<tr> <td></td> <td></td> <td></td> </tr>
<tr> <td></td> <td style="border: 5px dashed blue"></td>
<td style="border: 5px solid lime"></td> </tr>
<tr> <td></td> <td></td> <td></td> </tr>
<tr> <td></td> <td></td> <td></td> </tr>
</table>
''', 3, 4)
assert vertical_borders == [
[yellow_5, black_3, red_1, yellow_5],
[yellow_5, dashed_blue_5, green_5, green_5],
[yellow_5, black_3, red_1, yellow_5],
[yellow_5, black_3, red_1, yellow_5],
]
assert horizontal_borders == [
[yellow_5, yellow_5, yellow_5],
[red_1, dashed_blue_5, green_5],
[red_1, dashed_blue_5, green_5],
[red_1, red_1, red_1],
[yellow_5, yellow_5, yellow_5],
]


@assert_no_logs
def test_border_collapse_5():
# rowspan and colspan
vertical_borders, horizontal_borders = _get_grid('''
<style>col, tr { border: 3px solid }</style>
<table style="border-collapse: collapse">
<col /><col /><col />
<tr> <td rowspan=2></td> <td></td> <td></td> </tr>
<tr> <td colspan=2></td> </tr>
</table>
''', 3, 2)
assert vertical_borders == [
[black_3, black_3, black_3, black_3],
[black_3, black_3, None, black_3],
]
assert horizontal_borders == [
[black_3, black_3, black_3],
[None, black_3, black_3],
[black_3, black_3, black_3],
]
Loading
Loading