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

Add support for border-image-source and border-image-slice. #2125

Merged
merged 31 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
69e9c55
Add basic support for border-image-source and border-image-slice with…
xavidotron Apr 10, 2024
136ab09
Handle borders of uneven width with border images.
xavidotron Apr 10, 2024
c1966b6
Support non-percent-based coordinates in border-image-slice.
xavidotron Apr 11, 2024
9be367d
Fix silly mistake with fill in border-image-slice.
xavidotron Apr 11, 2024
f6a30fc
Avoid mutating the image-slice
xavidotron Apr 20, 2024
3060263
Rename tests and remove extra comments
liZe Apr 24, 2024
aea95e0
Simplify SVG file
liZe Apr 24, 2024
9e042c2
Correctly split specified and computed values
liZe Apr 24, 2024
6f9550b
Clean border image drawing code
liZe Apr 24, 2024
0bb0f5d
Add validation tests
liZe Apr 25, 2024
e87fc5c
Merge branch 'Kozea:main' into main
xavidotron Apr 25, 2024
d7bd828
Add support for the border-image-repeat CSS property.
xavidotron Apr 26, 2024
e9ac268
Remove unnecessary check for length of border-image-repeat, that's ha…
xavidotron Apr 26, 2024
bd51459
Move border-image-repeat logic to not be in the middle of the slice c…
xavidotron Apr 26, 2024
2fe3364
Add support for border-image-outset.
xavidotron Apr 26, 2024
b3efa78
Support border-image-width.
xavidotron Apr 26, 2024
eae6ebc
Clean coding style
liZe Apr 26, 2024
8005207
Handle gradients for border images
liZe Apr 26, 2024
1f702be
Correctly handle border image slices larger than the image
liZe Apr 26, 2024
703cd03
Don’t swap border image repeat values
liZe Apr 26, 2024
dbcd901
Avoid divisions by 0 when drawing border images
liZe Apr 26, 2024
9c098d6
Use consistent variable name
liZe Apr 26, 2024
acd91eb
Calculate scale and repeat outside the drawing stack
liZe Apr 26, 2024
76197f5
Avoid nested stacks for border images
liZe Apr 26, 2024
d5275f3
Fix corner cases for border images
liZe Apr 26, 2024
48a30e8
Avoid more divisions by 0
liZe Apr 26, 2024
1e20535
Display border images even when there’s no border
liZe Apr 26, 2024
aa79825
Fix extra space value
liZe Apr 26, 2024
65bcfbb
Test border-image shorthand
liZe Apr 26, 2024
886cefe
Put border image drawing in a specific function
liZe Apr 26, 2024
c863373
Update documentation about border images
liZe Apr 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
8 changes: 4 additions & 4 deletions docs/api_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,10 @@ background layers per box), including the ``background``, ``background-color``,
WeasyPrint also supports the `rounded corners part`_ of this module, including
the ``border-radius`` property.

WeasyPrint does **not** support the `border images part`_ of this module,
including the ``border-image``, ``border-image-source``,
``border-image-slice``, ``border-image-width``, ``border-image-outset`` and
``border-image-repeat`` properties.
WeasyPrint also supports the `border images part`_ of this module, including the
``border-image``, ``border-image-source``, ``border-image-slice``,
``border-image-width``, ``border-image-outset`` and ``border-image-repeat``
properties.

WeasyPrint does **not** support the `box shadow part`_ of this module,
including the ``box-shadow`` property. This feature has been implemented in a
Expand Down
56 changes: 56 additions & 0 deletions tests/css/test_expanders.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,62 @@ def test_border_radius_invalid(rule, message):
assert_invalid(f'border-radius: {rule}', message)


@assert_no_logs
@pytest.mark.parametrize('rule, result', (
('url(border.png) 27', {
'border_image_source': ('url', 'https://weasyprint.org/foo/border.png'),
'border_image_slice': ((27, None),),
}),
('url(border.png) 10 / 4 / 2 round stretch', {
'border_image_source': ('url', 'https://weasyprint.org/foo/border.png'),
'border_image_slice': ((10, None),),
'border_image_width': ((4, None),),
'border_image_outset': ((2, None),),
'border_image_repeat': (('round', 'stretch')),
}),
('10 // 2', {
'border_image_slice': ((10, None),),
'border_image_outset': ((2, None),),
}),
('5.5%', {
'border_image_slice': ((5.5, '%'),),
}),
('stretch 2 url("border.png")', {
'border_image_source': ('url', 'https://weasyprint.org/foo/border.png'),
'border_image_slice': ((2, None),),
'border_image_repeat': (('stretch',)),
}),
('1/2 round', {
'border_image_slice': ((1, None),),
'border_image_width': ((2, None),),
'border_image_repeat': (('round',)),
}),
('none', {
'border_image_source': ('none', None),
}),
))
def test_border_image(rule, result):
assert expand_to_dict(f'border-image: {rule}') == result


@assert_no_logs
@pytest.mark.parametrize('rule, reason', (
('url(border.png) url(border.png)', 'multiple source'),
('10 10 10 10 10', 'multiple slice'),
('1 / 2 / 3 / 4', 'invalid'),
('/1', 'invalid'),
('/1', 'invalid'),
('round round round', 'invalid'),
('-1', 'invalid'),
('1 repeat 2', 'multiple slice'),
('1% // 1%', 'invalid'),
('1 / repeat', 'invalid'),
('', 'no value'),
))
def test_border_image_invalid(rule, reason):
assert_invalid(f'border-image: {rule}', reason)


@assert_no_logs
@pytest.mark.parametrize('rule, result', (
('12px My Fancy Font, serif', {
Expand Down
108 changes: 108 additions & 0 deletions tests/css/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,114 @@ def test_image_orientation_invalid(rule):
assert_invalid(f'image-orientation: {rule}')


@assert_no_logs
@pytest.mark.parametrize('rule, value', (
('1', ((1, None),)),
('1 2 3 4', ((1, None), (2, None), (3, None), (4, None))),
('50% 1000.1 0', ((50, '%'), (1000.1, None), (0, None))),
('1% 2% 3% 4%', ((1, '%'), (2, '%'), (3, '%'), (4, '%'))),
('fill 10% 20', ('fill', (10, '%'), (20, None))),
('0 1 0.5 fill', ((0, None), (1, None), (0.5, None), 'fill')),
))
def test_border_image_slice(rule, value):
assert get_value(f'border-image-slice: {rule}') == value


@assert_no_logs
@pytest.mark.parametrize('rule', (
'none',
'1, 2',
'-10',
'-10%',
'1 2 3 -10%',
'-0.3',
'1 fill 2',
'fill 1 2 3 fill',
))
def test_border_image_slice_invalid(rule):
assert_invalid(f'border-image-slice: {rule}')


@assert_no_logs
@pytest.mark.parametrize('rule, value', (
('1', ((1, None),)),
('1 2 3 4', ((1, None), (2, None), (3, None), (4, None))),
('50% 1000.1 0', ((50, '%'), (1000.1, None), (0, None))),
('1% 2px 3em 4', ((1, '%'), (2, 'px'), (3, 'em'), (4, None))),
('auto', ('auto',)),
('1 auto', ((1, None), 'auto')),
('auto auto', ('auto', 'auto')),
('auto auto auto 2', ('auto', 'auto', 'auto', (2, None))),
))
def test_border_image_width(rule, value):
assert get_value(f'border-image-width: {rule}') == value


@assert_no_logs
@pytest.mark.parametrize('rule', (
'none',
'1, 2',
'1 -2',
'-10',
'-10%',
'1px 2px 3px -10%',
'-3px',
'auto auto auto auto auto',
'1 2 3 4 5',
))
def test_border_image_width_invalid(rule):
assert_invalid(f'border-image-width: {rule}')


@assert_no_logs
@pytest.mark.parametrize('rule, value', (
('1', ((1, None),)),
('1 2 3 4', ((1, None), (2, None), (3, None), (4, None))),
('50px 1000.1 0', ((50, 'px'), (1000.1, None), (0, None))),
('1in 2px 3em 4', ((1, 'in'), (2, 'px'), (3, 'em'), (4, None))),
))
def test_border_image_outset(rule, value):
assert get_value(f'border-image-outset: {rule}') == value


@assert_no_logs
@pytest.mark.parametrize('rule', (
'none',
'auto',
'1, 2',
'-10',
'1 -2',
'10%',
'1px 2px 3px -10px',
'-3px',
'1 2 3 4 5',
))
def test_border_image_outset_invalid(rule):
assert_invalid(f'border-image-outset: {rule}')


@assert_no_logs
@pytest.mark.parametrize('rule, value', (
('stretch', ('stretch',)),
('repeat repeat', ('repeat', 'repeat')),
('round space', ('round', 'space')),
))
def test_border_image_repeat(rule, value):
assert get_value(f'border-image-repeat: {rule}') == value


@assert_no_logs
@pytest.mark.parametrize('rule', (
'none',
'test',
'round round round',
'stretch space round',
'repeat test',
))
def test_border_image_repeat_invalid(rule):
assert_invalid(f'border-image-repeat: {rule}')


@assert_no_logs
@pytest.mark.parametrize('rule, value', (
('test content(text)', (('test', (('content()', 'text'),)),)),
Expand Down
3 changes: 3 additions & 0 deletions tests/draw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
'G': (0, 255, 0), # lime green
'V': (191, 0, 64), # average of 1*B and 3*R
'S': (255, 63, 63), # R above R above _
'C': (0, 255, 255), # cyan
'M': (255, 0, 255), # magenta
'Y': (255, 255, 0), # yellow
'K': (0, 0, 0), # black
'r': (255, 0, 0), # red
'g': (0, 128, 0), # half green
Expand Down
Loading
Loading