Closed Tameflame closed 8 months ago
Well, the image is rendered correctly, therefore SVG was parsed correctly. That's something.
I guess something is wrong with usvg
API. Will take a look.
Should be fixed in the next release.
Awesome thanks very much!
Btw @RazrFalcon, if I wanted to draw the bounding box for a specific node in the tree, is there a way to do that? I basically want to use the bounding boxes as a quick way of getting the intrinsic size of a node on the tree. Can I use nodeID or something?
You can use usvg::Tree::node_by_id
.
@RazrFalcon thanks but for some reason I can't get it to fetch even a simple node:
#[test]
pub fn find_text_node_by_id() {
let svg = r#"
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">
<svg id="unique">
<text x="10" y="10">Hello World</text>
</svg>
</svg>
"#;
let tree = usvg::Tree::from_str(
svg,
&usvg::Options::default(),
&Default::default(),
)
.unwrap();
println!("{:#?}", tree.node_by_id("unique"));
}
Output:
running 1 test
None
test tests::find_text_node_by_id ... ok
It's not a simple node. Nested svg
elements are very complicated and in this case usvg
looses the id. Will fix.
Awesome, thanks so much!
See #734
I've got an SVG (see attached image below), which has a lot of nested SVGs to emulate layers (I do this because I want to specify width/height and I can't do that with g tags), but the the following draw bboxes function fails to draw the boundary boxes correctly (see attached output below).
Here is my function:
Source svg file:
Output png file:
If the solution is to change my use of nested SVG tags, please advise, I really need them to emulate layers because I want to be able to programmatically modify the SVG. If the issue can be solved by adding attributes to specific tags or something like that please let me know. Thanks