Skip to content

Commit

Permalink
Merge pull request #2125 from xavidotron/main
Browse files Browse the repository at this point in the history
Add basic support for border-image-source and border-image-slice.
  • Loading branch information
liZe authored Apr 26, 2024
2 parents 70cafe1 + c863373 commit df7c9b9
Show file tree
Hide file tree
Showing 13 changed files with 1,127 additions and 16 deletions.
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

0 comments on commit df7c9b9

Please sign in to comment.