Closed LetsMelon closed 2 years ago
While you can, you shouldn't. You must treat usvg::Tree
as read-only. It's mutable now due to the fact that the tree is based on Rc
, which cannot be immutable, kinda. Future resvg
updates, hopefully, would have a read-only tree. Or maybe not a tree at all. Will see.
As for now, simply use tree.root().append()
and append_to_defs()
for each node. If you're looking for some sort of existing solution - there is none.
Yeah I'm kinda exploiting the kinda immutable tree for a project of mine (relevant code). But nevertheless thanks for the fast response.
As for animations, I would suggest converting usvg::Tree
into your own representation. usvg
is mainly designed as an SVG preprocessor to remove all the complexity it has. And there are a lot.
Also, resvg isn't really validating the input usvg::Tree
which may lead to weird bugs.
Also, tiny-skia is too slow for real-time rendering. Hopefully someone would eventually write a decent 2D GPU library. Skia (not tiny-skia) is 400 KLOC for a reason...
Sorry if the question is silly, but I have no idea what's the best method to append a
usvg::Tree
with anotherusvg::Tree
.Let's say we modify the code of
examples/minimal.rs
to accept two SVG files and combine them into one tree and render them. I tried everything from a loop overrtree.root().descendants()
to hack something together with 'thousand' methods, but it wasn't really working.Modified
examples/minimal.rs
code: