Skip to content

LinearGradient/RadialGradient: raise a clear error for bounds outside [0, 1] or decreasing - #2134

Merged
andersonhc merged 2 commits into
py-pdf:masterfrom
RavSinghChandan:gradient-bounds-range
Nov 10, 2026
Merged

andersonhc merged 2 commits into
py-pdf:masterfrom
RavSinghChandan:gradient-bounds-range

Conversation

@RavSinghChandan

Copy link
Copy Markdown

LinearGradient(..., bounds=[1.5, 0.8]) wrote /Bounds [1.5 0.8] into the stitching function, and [-0.2, ...], decreasing values or NaN went through the same way. The PDF specification requires the bounds to be increasing and within the function's domain [0, 1], and the docstring already says they are "in the range (0, 1)".

The gradient now raises ValueError: Bounds must be increasing numbers between 0 and 1: ..., next to the existing check on the number of bounds. Equal bounds and bounds of exactly 0 or 1 are still accepted, so the gradients built from SVG and shape_*_gradient() stops are unchanged.

  • A unit test is covering the code added / modified by this PR
  • A mention of the change is present in CHANGELOG.md
  • This PR is ready to be merged

@andersonhc
andersonhc merged commit ff51135 into py-pdf:master Nov 10, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants