-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide capability to modify SVG
before str serialization
#13
Comments
SVG
before xml serializationSVG
before str serialization
Perhaps both ideas should lie in an svg crate instead...it's only been 15 minutes and I'm realizing that this is most likely out of scope for the repo...but I'd still like to be able to identify the shapes somehow...hmm. Edit: I could also
Edit 2: The conflict I'm having is that I don't know much about what the scope of this crate should be. There are unique properties of SVGs that don't line up with the types necessarily, which is why I'd like to be able to identify the outputs at some point during the serialization process. This becomes a lot harder though if the outputs are not 1:1 with the types, especially with regard to having children nodes and whatnot. |
Thanks for the initiative! I appreciate it! I also had some similar issues with the current implementation in the past which led me to a attempt to refactor the lib in it's core. I failed though, since I got stuck at some point due to some not-so-well-thought-through designs. Back then I also attempted to structure it more like a tree, since this seems more natural. After giving it some more though nowadays after your comment I think this here (a slight modification of your idea) might work though: pub struct SvgTree {
// main content
pub tag: String,
pub content: String,
pub attrs: HashMap<String, String>,
// meta, isn't this "just" another attribute though?
pub id: Option<String>,
pub viewbox: Viewbox,
// structure
pub children: Vec<SvgTree>,
} The main issue here is that we need to keep the SVG virtually editable until it's "Stringified". This is where I failed previously since I kept the As for complexity and performance: I'm currently not really worried about neither of those. In my eyes this crate mainly serves as a debug or static visualization utility. As long as no-one opens an issue about creating 1000s of SVGs per frame at 30FPS my opinion won't change and I'll keep being more focused on usability rather than performance. |
I played around with the idea a bit further. Code can be found here. Not going to work on it for a moment. Feel free to base something off of it if you want. Looks like it might work out this time. |
Awesome, thanks! Will work from there...potentially using |
Update: I've come up with an interesting plan. I've actually written a lot of code already tackling this specific issue, along with the capability of resolving #4. I wrote a library that is able to take a type and generate svgs (and therefore bitmap rasterizations), HTML Canvas, docx (and therefore pdf), and pptx. I even temporarily parked a crate package called |
Hey! I'm back again...wondering if you'd be interested in having the capability of turning these into actual HtmlElements via websys? fastest way to get there would probably be via edit: here is an example I'm working on right now. Haven't pulled in all of the components I'd like for drawable backends, but hopefully that's a good thing for simplicity... definitely needs a lot of work though, especially comment-wise. last edit: An easy thing to do on an |
I'm not really seeing myself actively maintaining such a feature. Furthermore this is a bit out of scope for this crate. I think it would fit better in an extra crate. Does that make sense to you too or is there anything you definitely need from geo-svg. I still supporting the general idea. I think the best thing I could offer is to add a small note about the extta crate in the readme if you choose that path. |
Hello! I'm working on a project that requires adding additional attributes to particular xml nodes of the svg, of which are derived by the svg's external environment. In other words, I would like to target particular shapes on the SVG using css animations via an
id
attribute or inline style.Since the
ToSvg
accepts aBox<dyn ToSvgStr>
, it is difficult to add additional attributes to the nodes. If it's alright, I'd like to suggest some approaches (and implement one) to allow users to edit values for an SVG prior to and/or during serialization. Both invert/detach the connection betweenToSvg
andToSvgStr
Vec
of targeting attributes during serialization via.to_svg()
An implementation could include attaching an identifier to
svg
'sNode
types. i.e:and using the
assign
method to update attributes.The drawback is that after processing of the svg data into an
svg::Document
, it's difficult (impossible?) to add additional attributes to the SVG, since there is no way to identify a type that implementsNode
.This partially does what exists now...so maybe would it be alright to "target" particular nodes with additional attributes by passing in a Vec<(Identifier, (String, String))> into
.to_svg()
?to_string()
and serialize viaquick_xml::Writer
.Something of this sort?
The drawback of course is that this is slower than the existing implementation of
ToSvgStr
. What if there could be a hybrid situation of the two where onlyToSvg
utilizes this?If an approach here feels like it would be an improvement to the crate, I would be more than happy to contribute an implementation. Thank you for your consideration!
The text was updated successfully, but these errors were encountered: