Skip to content

Commit

Permalink
Ensure that gradient size is positive to please some PDF readers
Browse files Browse the repository at this point in the history
This was broken with Chrome and macOS Preview for example.
  • Loading branch information
liZe committed May 30, 2024
1 parent 96286be commit ff2acf1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions weasyprint/svg/defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ def draw_gradient(svg, node, gradient, font_size, opacity, stroke):
bx2, by2 = transform_matrix.invert.transform_point(width, height)
width, height = bx2 - bx1, by2 - by1

# Ensure that width and height are positive to please some PDF readers
if bx1 > bx2:
width = -width
bx1, bx2 = bx2, bx1
if by1 > by2:
height = -height
by1, by2 = by2, by1

pattern = svg.stream.add_pattern(
bx1, by1, width, height, width, height, matrix @ svg.stream.ctm)
group = pattern.add_group(bx1, by1, width, height)
Expand Down

0 comments on commit ff2acf1

Please sign in to comment.