Skip to content

Rewrite the svg2xaml extension using inkex

What does the merge request do?

This MR introduces a new XAML exporter. Improvents over the old XSLT-based one:

  • It supports high-fidelity conversion to both the high-level representation (Canvas) and the low-level DrawingGroup,
  • it allows to target the open-source, cross-platform UI toolkit Avalonia UI
  • it handles Inkscape semantics, such as layers and swatches and thus generally performs better with Inkscape generated SVGs than other exporters (SharpVectors is a good free alternative)

By high fidelity, I mean that basically all SVGs created with Inkscape are supported; in particular flowed texts, masks, clips, markers, paint order, gradients (except mesh gradients), CSS styles etc.

See the user-facing documentation at https://joneuhauser.gitlab.io/-/extensions/-/jobs/3139344500/artifacts/build/html/extensions/svg2xaml.html for more details.

The following issues are fixed:

Implementation notes

  • Test coverage is about 98% for the new code. I decided to write tests specific to certain functionality, and test only for those attributes. There are however a few run-though tests defined to check namespaces etc.
  • The main library, xamllib.py, has about the same number of lines as the old exporter, but significantly more functionality.
  • I fixed a bunch of inkex issues along the way.
  • Currently all commits are squashed into one; this could of course be changed. Imo the history of me working on that branch is not particularly interesting.
  • @ Reviewer: if you want a high-level overview of the code, please don't hesitate to ask. It's a lot of code.

Summary for release notes

XAML export has been completely rewritten and now supports AvaloniaUI, export to DrawingGroup, conserving swatches for easy styling and exporting Layers to individual resources which allows to maintain an icon library in a single SVG file. For more info, check the extensions documentation [insert link once merged].

Checklist

  • Add unit tests (if applicable)
  • Changes to inkex/ are well documented
  • Clean merge request history
Edited by Jonathan Neuhauser

Merge request reports