Skip to content

Commit ff2acf1

Browse files
committed
Ensure that gradient size is positive to please some PDF readers
This was broken with Chrome and macOS Preview for example.
1 parent 96286be commit ff2acf1

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

weasyprint/svg/defs.py

+8
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ def draw_gradient(svg, node, gradient, font_size, opacity, stroke):
188188
bx2, by2 = transform_matrix.invert.transform_point(width, height)
189189
width, height = bx2 - bx1, by2 - by1
190190

191+
# Ensure that width and height are positive to please some PDF readers
192+
if bx1 > bx2:
193+
width = -width
194+
bx1, bx2 = bx2, bx1
195+
if by1 > by2:
196+
height = -height
197+
by1, by2 = by2, by1
198+
191199
pattern = svg.stream.add_pattern(
192200
bx1, by1, width, height, width, height, matrix @ svg.stream.ctm)
193201
group = pattern.add_group(bx1, by1, width, height)

0 commit comments

Comments
 (0)