Add Android VectorDrawable import support#468
Merged
Conversation
|
Thank you for your excellent work! This is exactly what I wanted. Thank you in advance! Since I am a Chinese citizen within China and have no foreign exchange payment channels, I cannot donate to you now. If I resolve this problem(exchange payment channels), I will remember to come back and donate. Once again, thank you! |
This was referenced Mar 9, 2026
This was referenced Mar 23, 2026
This was referenced Apr 6, 2026
This was referenced Apr 17, 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: Add Android VectorDrawable import support
Overview
This change implements static Android
VectorDrawableimport support forSvg.SkiaandSvg.Model, based on issue#467.The implementation converts Android
VectorDrawableXML into a realSvgDocument, then reuses the existingSvg.Skiamodel and rendering pipeline for raster, PDF, XPS, and SVG output paths. In addition to the importer itself, this PR adds:.xmlauto-detection for AndroidVectorDrawabledocumentsattrs.xmlso Android contract coverage is explicit and reviewableMain Changes
1. VectorDrawable importer
Added an internal converter in
Svg.Modelthat:vectorroots using the Android XML namespacewidth,height,viewportWidth,viewportHeight, andalphagroupelements intoSvgGroupinstances with a single computed matrix transformpathelements intoSvgPathwith mapped fill, stroke, alpha, fill rule, line cap, line join, and miter limitclip-pathelements into shared SVG defs and applies them to the correct group scopeandroid:namevalues as SVG IDs where possibleUnsupported features currently rejected include:
animated-vectoraapt:attrtinttintModeautoMirrored="true"@...and?...trimPathStarttrimPathEndtrimPathOffsetThe importer also now enforces Android-style positive root metrics:
width > 0height > 0viewportWidth > 0viewportHeight > 02. Public API additions
Added
SvgServiceentry points:OpenVectorDrawable(string path, SvgParameters? parameters = null)OpenVectorDrawable(Stream stream, SvgParameters? parameters = null)OpenVectorDrawable(XmlReader reader)FromVectorDrawable(string xml)Added
SKSvgentry points:CreateFromVectorDrawable(string path, SvgParameters? parameters = null)CreateFromVectorDrawable(Stream stream, SvgParameters? parameters = null)CreateFromVectorDrawable(XmlReader reader)LoadVectorDrawable(string path, SvgParameters? parameters = null)LoadVectorDrawable(Stream stream, SvgParameters? parameters = null)LoadVectorDrawable(XmlReader reader)FromVectorDrawable(string xml)SKSvg.Load(path)andSvgService.Open(path, ...)now auto-detect.xmlfiles whose root is an AndroidVectorDrawableand route them through the new importer.3. Converter sample updates
The converter sample now:
VectorDrawableXML inputsvgoutput by writing the convertedSvgDocumentdirectlySKSvgrendering path4. Documentation updates
The README now includes:
SKSvg.LoadVectorDrawable(...)usageSvgService.OpenVectorDrawable(...)usageSKSvg.Load("file.xml")auto-detection for AndroidVectorDrawableAndroid Contract Validation
This PR adds a test-only validator generated from a pinned Android framework source file:
android-15.0.0_r1frameworks/base/core/res/res/values/attrs.xmlThe validator parses the Android
VectorDrawable,VectorDrawableGroup,VectorDrawablePath, andVectorDrawableClipPathstyleables and uses them to validate:This gives the test suite a stable Android contract to validate against without adding runtime schema validation cost.
The validator also makes one implementation extension explicit:
clip-path.android:fillTypeThat attribute is supported by the importer and renderer, but it is not part of the pinned AOSP
VectorDrawableClipPathstyleable. The test contract treats it as an explicit Svg.Skia extension instead of assuming it is standard Android behavior.Tests
Added model tests covering:
Added renderer/API tests covering:
SKSvg.LoadVectorDrawable(Stream).xmlauto-detectionAdded contract tests covering:
Commit Breakdown
6336afc5Add VectorDrawable import support18620b28Update converter for VectorDrawable filese7a91218Add pinned VectorDrawable spec validatorattrs.xmlVerification
Validated with:
dotnet format Svg.Skia.slnx --no-restoredotnet build Svg.Skia.slnx -c Release --no-restoredotnet test Svg.Skia.slnx -c Release --no-buildFull solution build and test passed. Existing repository warnings remain, but there were no test failures from this change set.
Fixes #467