mirror of
https://github.com/Kozea/WeasyPrint.git
synced 2024-09-17 15:37:34 +03:00
Improve tests and fix code for SVG gradients
This commit is contained in:
parent
a7f46b272c
commit
a843257e54
@ -8,16 +8,16 @@ from ...testing_utils import assert_no_logs
|
||||
@assert_no_logs
|
||||
def test_linear_gradient(assert_pixels):
|
||||
assert_pixels('''
|
||||
BBBBBBBBBB
|
||||
BBBBBBBBBB
|
||||
BBBBBBBBBB
|
||||
BBBBBBBBBB
|
||||
BBBBBBBBBB
|
||||
RRRRRRRRRR
|
||||
RRRRRRRRRR
|
||||
RRRRRRRRRR
|
||||
RRRRRRRRRR
|
||||
RRRRRRRRRR
|
||||
__________
|
||||
_BBBBBBBB_
|
||||
_BBBBBBBB_
|
||||
_BBBBBBBB_
|
||||
_BBBBBBBB_
|
||||
_RRRRRRRR_
|
||||
_RRRRRRRR_
|
||||
_RRRRRRRR_
|
||||
_RRRRRRRR_
|
||||
__________
|
||||
''', '''
|
||||
<style>
|
||||
@page { size: 10px }
|
||||
@ -31,7 +31,7 @@ def test_linear_gradient(assert_pixels):
|
||||
<stop stop-color="red" offset="50%"></stop>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect x="0" y="0" width="10" height="10" fill="url(#grad)" />
|
||||
<rect x="1" y="1" width="8" height="8" fill="url(#grad)" />
|
||||
</svg>
|
||||
''')
|
||||
|
||||
@ -39,16 +39,16 @@ def test_linear_gradient(assert_pixels):
|
||||
@assert_no_logs
|
||||
def test_linear_gradient_userspace(assert_pixels):
|
||||
assert_pixels('''
|
||||
BBBBBBBBBB
|
||||
BBBBBBBBBB
|
||||
BBBBBBBBBB
|
||||
BBBBBBBBBB
|
||||
BBBBBBBBBB
|
||||
RRRRRRRRRR
|
||||
RRRRRRRRRR
|
||||
RRRRRRRRRR
|
||||
RRRRRRRRRR
|
||||
RRRRRRRRRR
|
||||
__________
|
||||
_BBBBBBBB_
|
||||
_BBBBBBBB_
|
||||
_BBBBBBBB_
|
||||
_BBBBBBBB_
|
||||
_RRRRRRRR_
|
||||
_RRRRRRRR_
|
||||
_RRRRRRRR_
|
||||
_RRRRRRRR_
|
||||
__________
|
||||
''', '''
|
||||
<style>
|
||||
@page { size: 10px }
|
||||
@ -62,7 +62,7 @@ def test_linear_gradient_userspace(assert_pixels):
|
||||
<stop stop-color="red" offset="50%"></stop>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect x="0" y="0" width="10" height="10" fill="url(#grad)" />
|
||||
<rect x="1" y="1" width="8" height="8" fill="url(#grad)" />
|
||||
</svg>
|
||||
''')
|
||||
|
||||
@ -70,6 +70,7 @@ def test_linear_gradient_userspace(assert_pixels):
|
||||
@assert_no_logs
|
||||
def test_linear_gradient_multicolor(assert_pixels):
|
||||
assert_pixels('''
|
||||
__________
|
||||
BBBBBBBBBB
|
||||
BBBBBBBBBB
|
||||
RRRRRRRRRR
|
||||
@ -78,12 +79,13 @@ def test_linear_gradient_multicolor(assert_pixels):
|
||||
GGGGGGGGGG
|
||||
vvvvvvvvvv
|
||||
vvvvvvvvvv
|
||||
__________
|
||||
''', '''
|
||||
<style>
|
||||
@page { size: 10px 8px }
|
||||
@page { size: 10px 10px }
|
||||
svg { display: block }
|
||||
</style>
|
||||
<svg width="10px" height="8px" xmlns="https://www.w3.org/2000/svg">
|
||||
<svg width="10px" height="10px" xmlns="https://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<linearGradient id="grad" x1="0" y1="0" x2="0" y2="1"
|
||||
gradientUnits="objectBoundingBox">
|
||||
@ -95,7 +97,7 @@ def test_linear_gradient_multicolor(assert_pixels):
|
||||
<stop stop-color="rgb(128,0,128)" offset="75%"></stop>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect x="0" y="0" width="10" height="8" fill="url(#grad)" />
|
||||
<rect x="0" y="1" width="10" height="8" fill="url(#grad)" />
|
||||
</svg>
|
||||
''')
|
||||
|
||||
@ -103,6 +105,7 @@ def test_linear_gradient_multicolor(assert_pixels):
|
||||
@assert_no_logs
|
||||
def test_linear_gradient_multicolor_userspace(assert_pixels):
|
||||
assert_pixels('''
|
||||
__________
|
||||
BBBBBBBBBB
|
||||
BBBBBBBBBB
|
||||
RRRRRRRRRR
|
||||
@ -111,24 +114,25 @@ def test_linear_gradient_multicolor_userspace(assert_pixels):
|
||||
GGGGGGGGGG
|
||||
vvvvvvvvvv
|
||||
vvvvvvvvvv
|
||||
__________
|
||||
''', '''
|
||||
<style>
|
||||
@page { size: 10px 8px }
|
||||
@page { size: 10px 10px }
|
||||
svg { display: block }
|
||||
</style>
|
||||
<svg width="10px" height="8px" xmlns="https://www.w3.org/2000/svg">
|
||||
<svg width="10px" height="10px" xmlns="https://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<linearGradient id="grad" x1="0" y1="0" x2="0" y2="8"
|
||||
<linearGradient id="grad" x1="0" y1="0" x2="0" y2="10"
|
||||
gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="blue" offset="25%"></stop>
|
||||
<stop stop-color="red" offset="25%"></stop>
|
||||
<stop stop-color="blue" offset="30%"></stop>
|
||||
<stop stop-color="red" offset="30%"></stop>
|
||||
<stop stop-color="red" offset="50%"></stop>
|
||||
<stop stop-color="lime" offset="50%"></stop>
|
||||
<stop stop-color="lime" offset="75%"></stop>
|
||||
<stop stop-color="rgb(128,0,128)" offset="75%"></stop>
|
||||
<stop stop-color="lime" offset="70%"></stop>
|
||||
<stop stop-color="rgb(128,0,128)" offset="70%"></stop>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect x="0" y="0" width="10" height="8" fill="url(#grad)" />
|
||||
<rect x="0" y="1" width="10" height="8" fill="url(#grad)" />
|
||||
</svg>
|
||||
''')
|
||||
|
||||
@ -136,6 +140,7 @@ def test_linear_gradient_multicolor_userspace(assert_pixels):
|
||||
@assert_no_logs
|
||||
def test_linear_gradient_transform(assert_pixels):
|
||||
assert_pixels('''
|
||||
__________
|
||||
BBBBBBBBBB
|
||||
BBBBBBBBBB
|
||||
BBBBBBBBBB
|
||||
@ -144,12 +149,13 @@ def test_linear_gradient_transform(assert_pixels):
|
||||
RRRRRRRRRR
|
||||
GGGGGGGGGG
|
||||
vvvvvvvvvv
|
||||
__________
|
||||
''', '''
|
||||
<style>
|
||||
@page { size: 10px 8px}
|
||||
@page { size: 10px 10px}
|
||||
svg { display: block }
|
||||
</style>
|
||||
<svg width="10px" height="8px" xmlns="https://www.w3.org/2000/svg">
|
||||
<svg width="10px" height="10px" xmlns="https://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<linearGradient id="grad" x1="0" y1="0" x2="0" y2="1"
|
||||
gradientUnits="objectBoundingBox"
|
||||
@ -162,7 +168,7 @@ def test_linear_gradient_transform(assert_pixels):
|
||||
<stop stop-color="rgb(128,0,128)" offset="75%"></stop>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect x="0" y="0" width="10" height="8" fill="url(#grad)" />
|
||||
<rect x="0" y="1" width="10" height="8" fill="url(#grad)" />
|
||||
</svg>
|
||||
''')
|
||||
|
||||
@ -170,6 +176,7 @@ def test_linear_gradient_transform(assert_pixels):
|
||||
@assert_no_logs
|
||||
def test_linear_gradient_repeat(assert_pixels):
|
||||
assert_pixels('''
|
||||
__________
|
||||
BBBBBBBBBB
|
||||
BBBBBBBBBB
|
||||
RRRRRRRRRR
|
||||
@ -186,12 +193,13 @@ def test_linear_gradient_repeat(assert_pixels):
|
||||
GGGGGGGGGG
|
||||
vvvvvvvvvv
|
||||
vvvvvvvvvv
|
||||
__________
|
||||
''', '''
|
||||
<style>
|
||||
@page { size: 10px 16px }
|
||||
@page { size: 10px 18px }
|
||||
svg { display: block }
|
||||
</style>
|
||||
<svg width="11px" height="16px" xmlns="https://www.w3.org/2000/svg">
|
||||
<svg width="11px" height="18px" xmlns="https://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<linearGradient id="grad" x1="0" y1="0" x2="0" y2="0.5"
|
||||
gradientUnits="objectBoundingBox" spreadMethod="repeat">
|
||||
@ -203,7 +211,7 @@ def test_linear_gradient_repeat(assert_pixels):
|
||||
<stop stop-color="rgb(128,0,128)" offset="75%"></stop>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect x="0" y="0" width="11" height="16" fill="url(#grad)" />
|
||||
<rect x="0" y="1" width="11" height="16" fill="url(#grad)" />
|
||||
</svg>
|
||||
''')
|
||||
|
||||
@ -211,6 +219,7 @@ def test_linear_gradient_repeat(assert_pixels):
|
||||
@assert_no_logs
|
||||
def test_linear_gradient_repeat_long(assert_pixels):
|
||||
assert_pixels('''
|
||||
__________
|
||||
BBBBBBBBBB
|
||||
RRRRRRRRRR
|
||||
GGGGGGGGGG
|
||||
@ -227,12 +236,13 @@ def test_linear_gradient_repeat_long(assert_pixels):
|
||||
RRRRRRRRRR
|
||||
GGGGGGGGGG
|
||||
vvvvvvvvvv
|
||||
__________
|
||||
''', '''
|
||||
<style>
|
||||
@page { size: 10px 16px }
|
||||
@page { size: 10px 18px }
|
||||
svg { display: block }
|
||||
</style>
|
||||
<svg width="11px" height="16px" xmlns="https://www.w3.org/2000/svg">
|
||||
<svg width="11px" height="18px" xmlns="https://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<linearGradient id="grad" x1="0" y1="0" x2="0" y2="0.25"
|
||||
gradientUnits="objectBoundingBox" spreadMethod="repeat">
|
||||
@ -244,7 +254,50 @@ def test_linear_gradient_repeat_long(assert_pixels):
|
||||
<stop stop-color="rgb(128,0,128)" offset="75%"></stop>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect x="0" y="0" width="11" height="16" fill="url(#grad)" />
|
||||
<rect x="0" y="1" width="11" height="16" fill="url(#grad)" />
|
||||
</svg>
|
||||
''')
|
||||
|
||||
|
||||
@assert_no_logs
|
||||
def test_linear_gradient_repeat_userspace(assert_pixels):
|
||||
assert_pixels('''
|
||||
__________
|
||||
BBBBBBBBBB
|
||||
BBBBBBBBBB
|
||||
RRRRRRRRRR
|
||||
RRRRRRRRRR
|
||||
GGGGGGGGGG
|
||||
GGGGGGGGGG
|
||||
vvvvvvvvvv
|
||||
vvvvvvvvvv
|
||||
BBBBBBBBBB
|
||||
BBBBBBBBBB
|
||||
RRRRRRRRRR
|
||||
RRRRRRRRRR
|
||||
GGGGGGGGGG
|
||||
GGGGGGGGGG
|
||||
vvvvvvvvvv
|
||||
vvvvvvvvvv
|
||||
__________
|
||||
''', '''
|
||||
<style>
|
||||
@page { size: 10px 18px }
|
||||
svg { display: block }
|
||||
</style>
|
||||
<svg width="11px" height="18px" xmlns="https://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<linearGradient id="grad" x1="0" y1="1" x2="0" y2="9"
|
||||
gradientUnits="userSpaceOnUse" spreadMethod="repeat">
|
||||
<stop stop-color="blue" offset="25%"></stop>
|
||||
<stop stop-color="red" offset="25%"></stop>
|
||||
<stop stop-color="red" offset="50%"></stop>
|
||||
<stop stop-color="lime" offset="50%"></stop>
|
||||
<stop stop-color="lime" offset="75%"></stop>
|
||||
<stop stop-color="rgb(128,0,128)" offset="75%"></stop>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect x="0" y="1" width="11" height="16" fill="url(#grad)" />
|
||||
</svg>
|
||||
''')
|
||||
|
||||
@ -252,6 +305,7 @@ def test_linear_gradient_repeat_long(assert_pixels):
|
||||
@assert_no_logs
|
||||
def test_linear_gradient_reflect(assert_pixels):
|
||||
assert_pixels('''
|
||||
__________
|
||||
BBBBBBBBBB
|
||||
BBBBBBBBBB
|
||||
RRRRRRRRRR
|
||||
@ -268,12 +322,13 @@ def test_linear_gradient_reflect(assert_pixels):
|
||||
RRRRRRRRRR
|
||||
BBBBBBBBBB
|
||||
BBBBBBBBBB
|
||||
__________
|
||||
''', '''
|
||||
<style>
|
||||
@page { size: 10px 16px }
|
||||
@page { size: 10px 18px }
|
||||
svg { display: block }
|
||||
</style>
|
||||
<svg width="11px" height="16px" xmlns="https://www.w3.org/2000/svg">
|
||||
<svg width="11px" height="18px" xmlns="https://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<linearGradient id="grad" x1="0" y1="0" x2="0" y2="0.5"
|
||||
gradientUnits="objectBoundingBox" spreadMethod="reflect">
|
||||
@ -285,7 +340,50 @@ def test_linear_gradient_reflect(assert_pixels):
|
||||
<stop stop-color="rgb(128,0,128)" offset="75%"></stop>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect x="0" y="0" width="11" height="16" fill="url(#grad)" />
|
||||
<rect x="0" y="1" width="11" height="16" fill="url(#grad)" />
|
||||
</svg>
|
||||
''')
|
||||
|
||||
|
||||
@assert_no_logs
|
||||
def test_linear_gradient_reflect_userspace(assert_pixels):
|
||||
assert_pixels('''
|
||||
__________
|
||||
BBBBBBBBBB
|
||||
BBBBBBBBBB
|
||||
RRRRRRRRRR
|
||||
RRRRRRRRRR
|
||||
GGGGGGGGGG
|
||||
GGGGGGGGGG
|
||||
vvvvvvvvvv
|
||||
vvvvvvvvvv
|
||||
vvvvvvvvvv
|
||||
vvvvvvvvvv
|
||||
GGGGGGGGGG
|
||||
GGGGGGGGGG
|
||||
RRRRRRRRRR
|
||||
RRRRRRRRRR
|
||||
BBBBBBBBBB
|
||||
BBBBBBBBBB
|
||||
__________
|
||||
''', '''
|
||||
<style>
|
||||
@page { size: 10px 18px }
|
||||
svg { display: block }
|
||||
</style>
|
||||
<svg width="11px" height="18px" xmlns="https://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<linearGradient id="grad" x1="0" y1="1" x2="0" y2="9"
|
||||
gradientUnits="userSpaceOnUse" spreadMethod="reflect">
|
||||
<stop stop-color="blue" offset="25%"></stop>
|
||||
<stop stop-color="red" offset="25%"></stop>
|
||||
<stop stop-color="red" offset="50%"></stop>
|
||||
<stop stop-color="lime" offset="50%"></stop>
|
||||
<stop stop-color="lime" offset="75%"></stop>
|
||||
<stop stop-color="rgb(128,0,128)" offset="75%"></stop>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect x="0" y="1" width="11" height="16" fill="url(#grad)" />
|
||||
</svg>
|
||||
''')
|
||||
|
||||
@ -395,22 +493,24 @@ def test_linear_gradient_inherit_no_override(assert_pixels):
|
||||
@assert_no_logs
|
||||
def test_radial_gradient(assert_pixels):
|
||||
assert_pixels('''
|
||||
rrrrrrrrrr
|
||||
rrrrrrrrrr
|
||||
rrrrBBrrrr
|
||||
rrrBBBBrrr
|
||||
rrBBBBBBrr
|
||||
rrBBBBBBrr
|
||||
rrrBBBBrrr
|
||||
rrrrBBrrrr
|
||||
rrrrrrrrrr
|
||||
rrrrrrrrrr
|
||||
____________
|
||||
_rrrrrrrrrr_
|
||||
_rrrrrrrrrr_
|
||||
_rrrrBBrrrr_
|
||||
_rrrBBBBrrr_
|
||||
_rrBBBBBBrr_
|
||||
_rrBBBBBBrr_
|
||||
_rrrBBBBrrr_
|
||||
_rrrrBBrrrr_
|
||||
_rrrrrrrrrr_
|
||||
_rrrrrrrrrr_
|
||||
____________
|
||||
''', '''
|
||||
<style>
|
||||
@page { size: 10px }
|
||||
@page { size: 12px }
|
||||
svg { display: block }
|
||||
</style>
|
||||
<svg width="10px" height="10px" xmlns="https://www.w3.org/2000/svg">
|
||||
<svg width="12px" height="12px" xmlns="https://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<radialGradient id="grad" cx="0.5" cy="0.5" r="0.5"
|
||||
fx="0.5" fy="0.5" fr="0.2"
|
||||
@ -419,7 +519,7 @@ def test_radial_gradient(assert_pixels):
|
||||
<stop stop-color="red" offset="25%"></stop>
|
||||
</radialGradient>
|
||||
</defs>
|
||||
<rect x="0" y="0" width="10" height="10" fill="url(#grad)" />
|
||||
<rect x="1" y="1" width="10" height="10" fill="url(#grad)" />
|
||||
</svg>
|
||||
''')
|
||||
|
||||
@ -427,30 +527,32 @@ def test_radial_gradient(assert_pixels):
|
||||
@assert_no_logs
|
||||
def test_radial_gradient_userspace(assert_pixels):
|
||||
assert_pixels('''
|
||||
rrrrrrrrrr
|
||||
rrrrrrrrrr
|
||||
rrrrBBrrrr
|
||||
rrrBBBBrrr
|
||||
rrBBBBBBrr
|
||||
rrBBBBBBrr
|
||||
rrrBBBBrrr
|
||||
rrrrBBrrrr
|
||||
rrrrrrrrrr
|
||||
rrrrrrrrrr
|
||||
____________
|
||||
_rrrrrrrrrr_
|
||||
_rrrrrrrrrr_
|
||||
_rrrrBBrrrr_
|
||||
_rrrBBBBrrr_
|
||||
_rrBBBBBBrr_
|
||||
_rrBBBBBBrr_
|
||||
_rrrBBBBrrr_
|
||||
_rrrrBBrrrr_
|
||||
_rrrrrrrrrr_
|
||||
_rrrrrrrrrr_
|
||||
____________
|
||||
''', '''
|
||||
<style>
|
||||
@page { size: 10px }
|
||||
@page { size: 12px }
|
||||
svg { display: block }
|
||||
</style>
|
||||
<svg width="10px" height="10px" xmlns="https://www.w3.org/2000/svg">
|
||||
<svg width="12px" height="12px" xmlns="https://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<radialGradient id="grad" cx="5" cy="5" r="5" fx="5" fy="5" fr="2"
|
||||
<radialGradient id="grad" cx="6" cy="6" r="5" fx="6" fy="6" fr="2"
|
||||
gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="blue" offset="25%"></stop>
|
||||
<stop stop-color="red" offset="25%"></stop>
|
||||
</radialGradient>
|
||||
</defs>
|
||||
<rect x="0" y="0" width="10" height="10" fill="url(#grad)" />
|
||||
<rect x="1" y="1" width="10" height="10" fill="url(#grad)" />
|
||||
</svg>
|
||||
''')
|
||||
|
||||
@ -458,22 +560,24 @@ def test_radial_gradient_userspace(assert_pixels):
|
||||
@assert_no_logs
|
||||
def test_radial_gradient_multicolor(assert_pixels):
|
||||
assert_pixels('''
|
||||
rrrrrrrrrr
|
||||
rrrGGGGrrr
|
||||
rrGGBBGGrr
|
||||
rGGBBBBGGr
|
||||
rGBBBBBBGr
|
||||
rGBBBBBBGr
|
||||
rGGBBBBGGr
|
||||
rrGGBBGGrr
|
||||
rrrGGGGrrr
|
||||
rrrrrrrrrr
|
||||
____________
|
||||
_rrrrrrrrrr_
|
||||
_rrrGGGGrrr_
|
||||
_rrGGBBGGrr_
|
||||
_rGGBBBBGGr_
|
||||
_rGBBBBBBGr_
|
||||
_rGBBBBBBGr_
|
||||
_rGGBBBBGGr_
|
||||
_rrGGBBGGrr_
|
||||
_rrrGGGGrrr_
|
||||
_rrrrrrrrrr_
|
||||
____________
|
||||
''', '''
|
||||
<style>
|
||||
@page { size: 10px }
|
||||
@page { size: 12px }
|
||||
svg { display: block }
|
||||
</style>
|
||||
<svg width="10px" height="10px" xmlns="https://www.w3.org/2000/svg">
|
||||
<svg width="12px" height="12px" xmlns="https://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<radialGradient id="grad" cx="0.5" cy="0.5" r="0.5"
|
||||
fx="0.5" fy="0.5" fr="0.2"
|
||||
@ -484,7 +588,7 @@ def test_radial_gradient_multicolor(assert_pixels):
|
||||
<stop stop-color="red" offset="66%"></stop>
|
||||
</radialGradient>
|
||||
</defs>
|
||||
<rect x="0" y="0" width="10" height="10" fill="url(#grad)" />
|
||||
<rect x="1" y="1" width="10" height="10" fill="url(#grad)" />
|
||||
</svg>
|
||||
''')
|
||||
|
||||
@ -492,25 +596,27 @@ def test_radial_gradient_multicolor(assert_pixels):
|
||||
@assert_no_logs
|
||||
def test_radial_gradient_multicolor_userspace(assert_pixels):
|
||||
assert_pixels('''
|
||||
rrrrrrrrrr
|
||||
rrrGGGGrrr
|
||||
rrGGBBGGrr
|
||||
rGGBBBBGGr
|
||||
rGBBBBBBGr
|
||||
rGBBBBBBGr
|
||||
rGGBBBBGGr
|
||||
rrGGBBGGrr
|
||||
rrrGGGGrrr
|
||||
rrrrrrrrrr
|
||||
____________
|
||||
_rrrrrrrrrr_
|
||||
_rrrGGGGrrr_
|
||||
_rrGGBBGGrr_
|
||||
_rGGBBBBGGr_
|
||||
_rGBBBBBBGr_
|
||||
_rGBBBBBBGr_
|
||||
_rGGBBBBGGr_
|
||||
_rrGGBBGGrr_
|
||||
_rrrGGGGrrr_
|
||||
_rrrrrrrrrr_
|
||||
____________
|
||||
''', '''
|
||||
<style>
|
||||
@page { size: 10px }
|
||||
@page { size: 12px }
|
||||
svg { display: block }
|
||||
</style>
|
||||
<svg width="10px" height="10px" xmlns="https://www.w3.org/2000/svg">
|
||||
<svg width="12px" height="12px" xmlns="https://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<radialGradient id="grad" cx="5" cy="5" r="5"
|
||||
fx="5" fy="5" fr="2"
|
||||
<radialGradient id="grad" cx="6" cy="6" r="5"
|
||||
fx="6" fy="6" fr="2"
|
||||
gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="blue" offset="33%"></stop>
|
||||
<stop stop-color="lime" offset="33%"></stop>
|
||||
@ -518,7 +624,7 @@ def test_radial_gradient_multicolor_userspace(assert_pixels):
|
||||
<stop stop-color="red" offset="66%"></stop>
|
||||
</radialGradient>
|
||||
</defs>
|
||||
<rect x="0" y="0" width="10" height="10" fill="url(#grad)" />
|
||||
<rect x="1" y="1" width="10" height="10" fill="url(#grad)" />
|
||||
</svg>
|
||||
''')
|
||||
|
||||
@ -526,22 +632,24 @@ def test_radial_gradient_multicolor_userspace(assert_pixels):
|
||||
@assert_no_logs
|
||||
def test_radial_gradient_repeat(assert_pixels):
|
||||
assert_pixels('''
|
||||
GBBrrrrBBG
|
||||
BrrGGGGrrB
|
||||
BrGBBBBGrB
|
||||
rGBBrrBBGr
|
||||
rGBrGGrBGr
|
||||
rGBrGGrBGr
|
||||
rGBBrrBBGr
|
||||
BrGBBBBGrB
|
||||
BrrGGGGrrB
|
||||
GBBrrrrBBG
|
||||
____________
|
||||
_GBBrrrrBBG_
|
||||
_BrrGGGGrrB_
|
||||
_BrGBBBBGrB_
|
||||
_rGBBrrBBGr_
|
||||
_rGBrGGrBGr_
|
||||
_rGBrGGrBGr_
|
||||
_rGBBrrBBGr_
|
||||
_BrGBBBBGrB_
|
||||
_BrrGGGGrrB_
|
||||
_GBBrrrrBBG_
|
||||
____________
|
||||
''', '''
|
||||
<style>
|
||||
@page { size: 10px }
|
||||
@page { size: 12px }
|
||||
svg { display: block }
|
||||
</style>
|
||||
<svg width="10px" height="10px" xmlns="https://www.w3.org/2000/svg">
|
||||
<svg width="12px" height="12px" xmlns="https://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<radialGradient id="grad" cx="0.5" cy="0.5" r="0.5"
|
||||
fx="0.5" fy="0.5" fr="0.2"
|
||||
@ -552,7 +660,7 @@ def test_radial_gradient_repeat(assert_pixels):
|
||||
<stop stop-color="red" offset="66%"></stop>
|
||||
</radialGradient>
|
||||
</defs>
|
||||
<rect x="0" y="0" width="10" height="10" fill="url(#grad)" />
|
||||
<rect x="1" y="1" width="10" height="10" fill="url(#grad)" />
|
||||
</svg>
|
||||
''')
|
||||
|
||||
@ -560,22 +668,24 @@ def test_radial_gradient_repeat(assert_pixels):
|
||||
@assert_no_logs
|
||||
def test_radial_gradient_reflect(assert_pixels):
|
||||
assert_pixels('''
|
||||
GrrrrrrrrG
|
||||
rrrGGGGrrr
|
||||
rrGBBBBGrr
|
||||
rGBBBBBBGr
|
||||
rGBBGGBBGr
|
||||
rGBBGGBBGr
|
||||
rGBBBBBBGr
|
||||
rrGBBBBGrr
|
||||
rrrGGGGrrr
|
||||
GrrrrrrrrG
|
||||
____________
|
||||
_GrrrrrrrrG_
|
||||
_rrrGGGGrrr_
|
||||
_rrGBBBBGrr_
|
||||
_rGBBBBBBGr_
|
||||
_rGBBGGBBGr_
|
||||
_rGBBGGBBGr_
|
||||
_rGBBBBBBGr_
|
||||
_rrGBBBBGrr_
|
||||
_rrrGGGGrrr_
|
||||
_GrrrrrrrrG_
|
||||
____________
|
||||
''', '''
|
||||
<style>
|
||||
@page { size: 10px }
|
||||
@page { size: 12px }
|
||||
svg { display: block }
|
||||
</style>
|
||||
<svg width="10px" height="10px" xmlns="https://www.w3.org/2000/svg">
|
||||
<svg width="12px" height="12px" xmlns="https://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<radialGradient id="grad" cx="0.5" cy="0.5" r="0.5"
|
||||
fx="0.5" fy="0.5" fr="0.2"
|
||||
@ -586,7 +696,7 @@ def test_radial_gradient_reflect(assert_pixels):
|
||||
<stop stop-color="red" offset="66%"></stop>
|
||||
</radialGradient>
|
||||
</defs>
|
||||
<rect x="0" y="0" width="10" height="10" fill="url(#grad)" />
|
||||
<rect x="1" y="1" width="10" height="10" fill="url(#grad)" />
|
||||
</svg>
|
||||
''')
|
||||
|
||||
|
@ -105,10 +105,8 @@ def draw_gradient(svg, node, gradient, font_size, opacity, stroke):
|
||||
if not is_valid_bounding_box(bounding_box):
|
||||
return False
|
||||
if gradient.get('gradientUnits') == 'userSpaceOnUse':
|
||||
x, y = bounding_box[0], bounding_box[1]
|
||||
width, height = svg.inner_width, svg.inner_height
|
||||
else:
|
||||
x, y = 0, 0
|
||||
width, height = bounding_box[2], bounding_box[3]
|
||||
|
||||
spread = gradient.get('spreadMethod', 'pad')
|
||||
@ -136,8 +134,7 @@ def draw_gradient(svg, node, gradient, font_size, opacity, stroke):
|
||||
if gradient.get('gradientUnits') == 'userSpaceOnUse':
|
||||
matrix = Matrix()
|
||||
else:
|
||||
matrix = Matrix(
|
||||
a=width, d=height, e=bounding_box[0], f=bounding_box[1])
|
||||
matrix = Matrix(a=width, d=height)
|
||||
if gradient.tag == 'linearGradient':
|
||||
shading_type = 2
|
||||
x1, y1 = (
|
||||
@ -163,6 +160,8 @@ def draw_gradient(svg, node, gradient, font_size, opacity, stroke):
|
||||
spread, positions, colors, fx, fy, fr, cx, cy, r, width, height,
|
||||
matrix)
|
||||
|
||||
if gradient.get('gradientUnits') != 'userSpaceOnUse':
|
||||
matrix @= Matrix(e=bounding_box[0], f=bounding_box[1])
|
||||
matrix @= svg.stream.ctm
|
||||
|
||||
alphas = [color[3] for color in colors]
|
||||
@ -184,20 +183,18 @@ def draw_gradient(svg, node, gradient, font_size, opacity, stroke):
|
||||
if 0 not in (a0, a1) and (a0, a1) != (1, 1):
|
||||
color_couples[i][2] = a0 / a1
|
||||
|
||||
x1, y1 = x, y
|
||||
x, y = 0, 0
|
||||
if 'gradientTransform' in gradient.attrib:
|
||||
transform_matrix = transform(
|
||||
gradient.get('gradientTransform'), font_size,
|
||||
svg.normalized_diagonal)
|
||||
x1, y1 = transform_matrix.invert.transform_point(x1, y1)
|
||||
x2, y2 = transform_matrix.invert.transform_point(
|
||||
x1 + width, y1 + height)
|
||||
width, height = x2 - x1, y2 - y1
|
||||
x, y = transform_matrix.invert.transform_point(x, y)
|
||||
width, height = transform_matrix.invert.transform_point(width, height)
|
||||
matrix = transform_matrix @ matrix
|
||||
|
||||
pattern = svg.stream.add_pattern(
|
||||
x1, y1, width, height, width, height, matrix)
|
||||
group = pattern.add_group([x1, y1, width, height])
|
||||
x, y, width, height, width, height, matrix)
|
||||
group = pattern.add_group([x, y, width, height])
|
||||
|
||||
domain = (positions[0], positions[-1])
|
||||
extend = spread not in ('repeat', 'reflect')
|
||||
@ -212,7 +209,7 @@ def draw_gradient(svg, node, gradient, font_size, opacity, stroke):
|
||||
shading_type, 'RGB', domain, coords, extend, function)
|
||||
|
||||
if any(alpha != 1 for alpha in alphas):
|
||||
alpha_stream = group.set_alpha_state(x1, y1, width, height)
|
||||
alpha_stream = group.set_alpha_state(x, y, width, height)
|
||||
domain = (positions[0], positions[-1])
|
||||
extend = spread not in ('repeat', 'reflect')
|
||||
encode = (len(colors) - 1) * (0, 1)
|
||||
|
Loading…
Reference in New Issue
Block a user