Svg.Model is the intermediate layer between the parsed SVG DOM and the final SkiaSharp output. It owns the drawable tree, the command-model picture representation, load parameters, hit-testing services, and editing helpers used by the rest of the repository.
dotnet add package Svg.Model
| Area | Main types |
|---|---|
| Input and parsing | SvgService, SvgParameters |
| Intermediate drawables | DrawableBase and the Drawables.Elements.* types |
| Model output | ShimSkiaSharp.SKPicture, SKDrawable |
| Hit testing | HitTestService |
| Editing | DrawableWalker, DrawableEditingExtensions |
| Asset lookup abstraction | ISvgAssetLoader |
Svg.Model can parse content and produce either a drawable tree or a ShimSkiaSharp.SKPicture. Asset resolution still requires an ISvgAssetLoader implementation, which usually comes from Svg.Skia or an application-specific host.
using ShimSkiaSharp;
using Svg.Model.Drawables;
using Svg.Model.Services;
using Svg.Skia;
var skiaModel = new SkiaModel(new SKSvgSettings());
var assetLoader = new SkiaSvgAssetLoader(skiaModel);
var document = SvgService.Open("Assets/icon.svg");
var model = SvgService.ToModel(document!, assetLoader, out var drawable, out var bounds);
if (drawable is DrawableBase root)
{
foreach (var element in HitTestService.HitTestElements(root, new SKPoint(24, 24)))
{
Console.WriteLine(element.ID);
}
}
This is the right level when you want to work on the model before choosing a rendering backend.
The editing helpers operate on the drawable tree, not on the final SkiaSharp.SKPicture.
using ShimSkiaSharp;
using ShimSkiaSharp.Editing;
using Svg.Model.Drawables;
using Svg.Model.Editing;
if (drawable is DrawableBase root)
{
root.UpdateFills(
paint => paint.Color.Alpha != 0,
paint => paint.Color = new SKColor(0x00, 0x7A, 0xCC, paint.Color.Alpha),
EditMode.CloneOnWrite);
var updatedModel = root.Snapshot(root.Bounds);
var updatedPicture = skiaModel.ToSKPicture(updatedModel);
}
Common uses:
SvgParametersSvgParameters carries the parsing-time knobs that most applications care about:
The UI packages use the same type to implement runtime restyling of SVG sources.
ISvgAssetLoaderSvg.Model does not hard-code how referenced raster images or font metrics are resolved. ISvgAssetLoader abstracts:
Use this interface directly when integrating the model layer into a new host environment.
Svg.Model turns that DOM into drawables and a command-model picture.SkiaSharp.SKPicture.Svg.Model