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:
- Closes #297 (closed); this is mostly a side effect of my CSS/Style work - inline styles, presentation attributes and CSS styles are fully supported.
- Closes #358 (closed); we don't output Names anymore (except for top-level resources), and these names are sanitized according to the naming syntax of XAML.
- Closes #78 (closed); all elements are correctly rendered.
- Closes #200 (closed); all elements are correctly rendered.
- Closes #203 (closed), Closes #204 (closed); all properties are run through
to_dimensionless()
. - Closes #496 (closed), gradient attributes are taken from the href as well.
- Fixes https://bugs.launchpad.net/inkscape/+bug/1521688; The xml:space="preserve" property is correctly handled for "editable" text export (only WPF Canvas currently).
- Fixes https://bugs.launchpad.net/inkscape/+bug/1728183; the clip is correctly processed
- Fixes https://bugs.launchpad.net/inkscape/+bug/1457898; clones are supported
- Fixes https://bugs.launchpad.net/inkscape/+bug/1750220; the gradients stops are correctly exported
- Fixes https://bugs.launchpad.net/inkscape/+bug/1789401; transforms are generally stored as matrices.
- Fixes https://bugs.launchpad.net/inkscape/+bug/1789406; markers are supported.
- Fixes https://bugs.launchpad.net/inkscape/+bug/1767724; file exports as expected.
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