Fix SVG C# codegen gradient output#505
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.
Summary
Fixes #460.
This PR fixes two SVG C# code generation failures reported in issue #460:
NaNfIt also fixes the renderer path that produced non-finite gradient stop positions for zero-width geometry bounds, so retained shader models are built with valid, clamped SVG stop offsets before code generation runs.
Root Cause
The C# generator emitted verbatim strings with raw embedded quotes. For a font family such as
"Black Ops One", this produced invalid generated C# like@""Black Ops One""instead of doubling quotes inside the verbatim string.Gradient color positions had two related problems:
ToFloatArrayappendedfto every formatted float, which made non-finite values compile as invalid C# tokens such asNaNf.ToDeviceValue(...)and dividing byskBounds.Width. For zero-width bounds, percentage stops could become0 / 0, producingNaNpositions.Changes
float.NaNfloat.PositiveInfinityfloat.NegativeInfinitynullgradient color positions when retained shader positions are missing or non-finite, matching SkiaSharp's optional color-position behavior.0..1nullcolor positions remain valid instead of dropping the shader.Validation
dotnet format Svg.Skia.slnx --no-restoredotnet test tests/Svg.Skia.UnitTests/Svg.Skia.UnitTests.csproj -f net10.0 -c Release --no-restore --filter "FullyQualifiedName~SkiaCSharpCodeGenTests" --logger "console;verbosity=normal"dotnet build Svg.Skia.slnx -c Releasedotnet test Svg.Skia.slnx -c Release --no-restoreFull solution tests passed. The main
Svg.Skia.UnitTestsrun ended with 1,640 passed, 593 skipped, and 0 failed.