Fix CSS linear gradient stroke offsets#506
Merged
Merged
Conversation
This was referenced May 12, 2026
This was referenced May 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix CSS Linear Gradient Stroke Offsets
Summary
Fixes #441 by correcting how SVG gradient stop offsets are converted into shader stop positions. The previous implementation converted each
<stop offset>throughToDeviceValue(..., skBounds)and divided by the target bounds width. That works only when the target geometry has non-zero width. For vertical line strokes, the geometry bounds width can be zero, producingNaNstop positions in the retained shader model.The change now normalizes stop offsets directly from the parsed SVG stop value:
0..100to0..10..1The same helper was added to both the primary model paint path and the retained scene graph paint path so Skia rendering and retained/Avalonia conversion stay consistent.
Changes
Svg.Model.Services.PaintingServicegradient stop collection to avoid dividing stop offsets by rendered element width.Svg.Skia.SvgScenePaintingServicewith the same offset normalization for retained scene graph rendering.Issue441Testscovering the reported CSS pattern:.cls-3{stroke:url(#linear-gradient);stroke-width:3px;}gradientUnits="userSpaceOnUse"SKSvg.Modelshader inspectionWhy
Issue #441 reported that linear gradients appeared unsupported in an Avalonia app when rendering an SVG containing a CSS-defined gradient stroke. Current Skia output could still look correct in direct rendering, but the retained model exposed the underlying problem: stop offsets could become
NaNfor zero-width vertical line bounds. Those invalid offsets are especially problematic for consumers that convert the retained shader model into Avalonia gradient brushes.Normalizing stop offsets from the SVG stop value matches the semantics of gradient stop positions and avoids geometry-dependent invalid values.
Validation
dotnet format Svg.Skia.slnx --no-restore --verify-no-changes --include src/Svg.Model/Services/PaintingService.cs src/Svg.SceneGraph/SvgScenePaintingService.cs tests/Svg.Skia.UnitTests/Issue441Tests.csdotnet test tests/Svg.Skia.UnitTests/Svg.Skia.UnitTests.csproj -f net10.0 -c Release --no-restore --filter "FullyQualifiedName~Issue441Tests" -v minimaldotnet build Svg.Skia.slnx -c Releasedotnet test Svg.Skia.slnx -c Release --no-buildFull solution tests passed with existing skips.
Commits
bfe859f78Fix gradient stop offset normalizationd90eedaf9Add issue 441 gradient stroke regression