1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-09-11 20:47:56 +03:00

Fix linear gradients transform matrix

This commit is contained in:
Guillaume Ayoub 2022-11-13 17:47:30 +01:00
parent 2b94b922f9
commit df97154331
2 changed files with 5 additions and 2 deletions

View File

@ -133,7 +133,6 @@ def test_linear_gradient_multicolor_userspace(assert_pixels):
''')
@pytest.mark.xfail
@assert_no_logs
def test_linear_gradient_transform(assert_pixels):
assert_pixels('''

View File

@ -206,15 +206,19 @@ 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 = 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(0, 0)
x2, y2 = transform_matrix.invert.transform_point(width, height)
width, height = x2 - x1, y2 - y1
matrix = transform_matrix @ matrix
matrix = matrix @ svg.stream.ctm
pattern = svg.stream.add_pattern(width, height, width, height, matrix)
group = pattern.add_group([0, 0, width, height])
group = pattern.add_group([x1, y1, width, height])
domain = (positions[0], positions[-1])
extend = spread not in ('repeat', 'reflect')