Support clipPath in Svg.Controls.Avalonia#502
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.
PR Summary: Fix Avalonia clip-path rendering
Summary
Fixes
Svg.Controls.Avaloniaclip-path rendering for SVGs loaded through the pure Avalonia control path. Previously, Skia picture recording preservedClipPathCanvasCommandentries, but the Avalonia conversion layer returnednullforClipPath.ToGeometry, soclip-path="url(#...)"was effectively ignored by the Avalonia drawing command recorder.This change converts retained clip-path payloads into Avalonia geometries and records them as geometry clips, allowing clipped SVG content to render correctly in
Svg.Controls.Avalonia.Issue
Addresses GitHub issue #438:
Svg.Controls.Avaloniadid not honor a simple SVG clip path:The reported behavior showed the rounded rectangle rendered without the expected 10x10 clip. The expected result is that only the clipped upper-left portion is visible.
Implementation Details
ClipPathto AvaloniaGeometryconversion inAvaloniaModelExtensions.PathClipentries, including nested clips.GeometryCombineMode.Union, matching SVG clip-path behavior where child clip shapes contribute to the clipping region.GeometryCombineMode.Intersect, preserving nested clip constraints.SKPath.ToGeometryto handle compact single-command shape paths:AddRectPathCommandAddRoundRectPathCommandAddOvalPathCommandAddCirclePathCommandAddPolyPathCommandAvaloniaPictureclip recording to request filled geometry for clip paths.Tests
Added a regression test using the issue SVG sample:
SvgSource.LoadFromSvg.SKPictureinto anAvaloniaPicture.GeometryClipDrawCommandis emitted.0,0,10,10.Validation
Validated locally with:
dotnet build src/Svg.Controls.Avalonia/Svg.Controls.Avalonia.csproj -f net8.0 -c Release --no-restore dotnet build src/Svg.Controls.Avalonia/Svg.Controls.Avalonia.csproj -f net10.0 -c Release --no-restore dotnet test tests/Svg.Controls.Avalonia.UnitTests/Svg.Controls.Avalonia.UnitTests.csproj -f net10.0 -c Release --no-restoreThe net10.0 package build passed cleanly. The net8.0 package build passed with existing warnings from dependency projects. The affected Avalonia unit-test project passed all 11 tests.
Notes
The full solution build was not used as the final validation target because this checkout initially lacked restored assets and, before submodule initialization, could not compile
Svg.Custom. After runninggit submodule update --init --recursiveand restoring the affected test project, the targeted package and unit-test validation completed successfully.