Svg.Skia

repository·master·Indexed 20 days ago

https://github.com/wieslawsoltes/svg.skia

A high-performance, cross-platform SVG rendering library for .NET using SkiaSharp as its backend. It supports the SVG 1.1 full model and a documented subset of SVG 2, offering a more complete document model than SkiaSharp.Extended.Svg. Key features include rendering to raster images or SKCanvas, support for Android VectorDrawable XML, opt-in JavaScript execution via Svg.Skia.JavaScript, and integration packages for Avalonia, .NET MAUI, and Uno.

Tokens
93.5K
Snippets
222
Records
452
Agent score
22%

What's inside Svg.Skia

  1. Overview of XAML support in Svg.Skia

    master

    Svg.Skia provides SVG rendering capabilities for XAML-facing .NET stacks, including Avalonia, Uno Platform, and .NET MAUI. It offers two primary ways to integrate SVG:

    1. Skia-backed controls: High-performance rendering using Skia, suitable for complex SVGs or when using the Svg.Controls.Skia suite.
    2. Inline SVG (SvgML): Authoring SVG elements directly within XAML markup using specialized SvgML syntax for Avalonia, .NET MAUI, or Uno.

    Depending on your requirements, you may choose between Avalonia.Svg.Skia and the standard Avalonia.Svg package (refer to the Overview guide for selection criteria).

  2. Overview of the Svg.Editor package stack

    master

    The Svg.Editor.* packages provide a reusable editor stack designed to be embedded into host applications. Instead of a monolithic application, these packages allow you to host the entire editor surface, specific side-panel workspaces, or individual editing services (like SVG mutation or property inspectors) within your own application shell.

    Use this stack if you need:

    • A ready-made editor surface and side-panel workspace in an Avalonia app.
    • Reusable services for SVG mutation, layers, symbols, swatches, and properties.
    • Editor dialogs and inspectors without the full canvas implementation.
    • Integration into a custom shell where you control menus, previews, and file pickers.
  3. Overview of Svg.Skia ecosystem components

    master

    Svg.Skia is a modular ecosystem for SVG parsing, modeling, and rendering using SkiaSharp. Depending on your target framework and use case, you should select the relevant package group:

    Core SVG Logic

    • Svg.Skia and Svg.Model: Handles SVG parsing, picture-model generation, SkiaSharp output, and model mutation.

    UI Framework Integrations

    • Avalonia: Use Svg.Controls.Avalonia or Svg.Controls.Skia.Avalonia for controls, images, and brush helpers. Skia.Controls.Avalonia provides general-purpose Skia controls.
    • Uno Platform: Use Svg.Controls.Skia.Uno for Skia-backed Uno controls and SvgSource resources.
    • .NET MAUI: Use Svg.Controls.Skia.Maui for Skia-backed MAUI controls and SvgSource resources.

    XAML & SVG 2 Authoring

    • SvgML.Avalonia, SvgML.Maui, and SvgML.Uno: Provide XAML-authored SVG trees, foreignObject control hosting, and support for the SVG 2 static subset authoring surface.

    Editing & Code Generation

    • Svg.Editor.*: Provides the reusable AvalonDraw editor stack (document/session services and interactive Avalonia workspace).
    • Svg.CodeGen.Skia, Svg.SourceGenerator.Skia, svgc, and Svg.Skia.Converter: Tools for generated code and CLI-based workflows.
  4. Overview of Svg.Skia

    master

    Svg.Skia is an SVG rendering library that can be used as a .NET library or as a CLI application. It renders SVG files based on the SVG Full 1.1 document model and a supported subset of SVG 2.

    Key features include:

    • Rendering SVG files to raster images or to a backend's canvas.
    • Using the Svg library to load the Svg object model.
    • Utilizing SkiaSharp as the rendering backend for high performance and cross-platform support.
    • Aiming for a more complete implementation of the SVG document model than SkiaSharp.Extended.Svg.
    • Compatibility with the SkiaSharp.Extended.Svg usage pattern (loading svg files as SKPicture).
  5. Explore Svg.Skia guides

    master

    The Svg.Skia documentation includes several task-oriented guides for specific workflows. Use these guides to learn about:

    • Loading: Comparing file, stream, string, reader, and document load APIs for SvgDocument and VectorDrawable.
    • Document Management: Handling SvgDocument ownership, full-document rebuilds, and reload workflows.
    • Scene Graph: Inspecting nodes, resources, and subtree pictures using the Retained Scene Graph.
    • Exporting: Using output helpers to export to Images, PDF, and XPS formats.
    • Hit Testing: Performing element and scene-node hit testing and model editing.
    • Performance: Understanding staged load costs and using incremental mutation-refresh APIs.
    • Interaction: Implementing animation, pointer-routing, and host backends.
    • CLI: Using the Svg.Skia.Converter command-line tool.
    • Code Generation: Using the Source Generator and svgc workflows.
  6. Project Structure and Module Boundaries

    master

    The project is split into several specialized libraries to separate concerns:

    • Svg.SceneGraph: Contains the retained scene graph runtime, compiler, and resource logic.
    • Svg.Animation: Contains the shared animation runtime.
    • Svg.Skia: Provides SkiaSharp conversion, host integration (Avalonia/Uno), and the SKSvg façade.
    • Svg.Custom: Provides local SVG 1.1 animation element support.
  7. Features covered in the MauiSvgSkiaSample

    master

    The MauiSvgSkiaSample demonstrates several key capabilities of the Svg.Controls.Skia.Maui library, including:

    • Asset Loading: Loading SVG assets using the Path property.
    • Inline SVG: Using the Source property to provide inline SVG text.
    • Resource Management: Utilizing reusable SvgSource resources.
    • Styling: Applying runtime CSS restyling to SVGs.
    • Interactivity: Implementing zoom, pan, and hit testing.
    • Visual Modes: Toggling between wireframe and filter views.
  8. Performance improvements in SVG rendering and resource parity

    master

    Recent updates to Svg.Skia have focused on improving SVG resource parity (matching W3C standards) and enhancing rendering performance. Key areas of improvement include:

    • Path Conversion: Optimized conversion for primitive shapes, SVG paths, and visual paths, resulting in reduced allocation sizes for command-list storage.
    • Transform Flattening: Significant speedups in drawing native pictures by flattening transform-only simple shape groups.
    • Text Rendering: Improved performance for direct positioned text and rotation-scale positioned text blobs.
    • Retained Scene Management: Reduced memory allocations and improved lookup speeds for retained scene node trees, dependency roots, and child lists.
    • Resource Parity: Improved support for paint servers, style resolution, and filter/resource parity to better align with SVG standards.
  9. Features covered in UnoSvgSkiaSample

    master

    The UnoSvgSkiaSample demonstrates the capabilities of Svg.Controls.Skia.Uno, including:

    • Asset Loading: Loading SVG assets via Path.
    • Inline SVG: Using the Source property for inline SVG text.
    • Resource Management: Utilizing reusable SvgSource resources.
    • Styling: Applying runtime CSS restyling.
    • Interactivity: Implementing zoom, pan, and hit testing.
    • Visual Modes: Toggling wireframe and filter views.
  10. Understand the Svg.Skia API Coverage Index

    master

    The API documentation for Svg.Skia is generated from a collection of specific projects across the repository. This includes core runtime packages (Svg.Skia, Svg.Model), animation and scene graph packages (Svg.Animation, Svg.SceneGraph), editor components (Svg.Editor.*), and platform-specific controls for Avalonia and Uno.

    Note that some packages, like Svg.Controls.Skia.Maui, are documented via authored content rather than generated API metadata to avoid dependencies on MAUI workloads in the documentation build environment.

  11. When to use the Svg.Editor.Svg package

    master

    Use Svg.Editor.Svg if your application requires the following capabilities:

    • Loading, saving, and round-tripping SVG documents within an editor workflow.
    • Reusable property-inspector models for editing element attributes.
    • Managing collections of layers, patterns, brushes, swatches, symbols, or styles.
    • Integrating SVG editor services into an existing host application that already has its own UI (e.g., non-Avalonia based).
  12. Understand the Svg.Editor package layout

    master

    The Svg.Editor stack is modularized into several specialized packages. Depending on your integration needs, you may interact with different layers of the editor:

    • Svg.Editor.Core: Manages the fundamental state, including shared sessions, settings, outlines, artboards, clipboard, and history.
    • Svg.Editor.Svg: Provides services for document mutation and editor-specific SVG/resource models.
    • Svg.Editor.Skia: Handles geometry and rendering logic, such as selection math, path editing, alignment/distribution, and overlay rendering.
    • Svg.Editor.Avalonia: Contains UI components like reusable Avalonia panels, editor views, and dialog abstractions.
    • Svg.Editor.Skia.Avalonia: Provides the primary integration surfaces: SvgEditorSurface and SvgEditorWorkspace.