-
Notifications
You must be signed in to change notification settings - Fork 236
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
Add support for stylesheet injection #785
Conversation
crates/usvg/src/parser/mod.rs
Outdated
pub has_priority: bool, | ||
/// The stylesheet that should be injected. | ||
pub style_sheet: &'a str, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An owned string here is fine.
Shouldn't we simply call The reason why I haven't added such "simple" feature yet is because I'm still confused about user styles order. PS: remember that we do not support |
As I mentioned, the problem is that the injected stylesheet then can't overwrite values that are defined via an inline
I don't know the details about those different style origins, but imo it makes sense to just let the user decide what they want, i.e. making it configurable.
No idea either. Guess we'd have to figure it out once we add it. |
But maybe it does make sense to figure out the |
Can you explain your use case? Do you want to be able to inject Also, simply putting Basically, it all boils down to what behavior do you expect. And the original author of #277 didn't specified it either. Like something in SVG can be described as "self-explanatory"... |
For me it's the first one. If I define |
Can you try it out using |
Will try. |
Alright, I ran an experiment with 0: <svg id="svg1" viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
<rect id="rect1" x="20" y="20" width="160" height="160"/>
</svg> 1: <svg id="svg1" viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
<rect id="rect1" x="20" y="20" width="160" height="160" fill="green"/>
</svg> 2: <svg id="svg1" viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
<rect id="rect1" x="20" y="20" width="160" style="fill: green" height="160"/>
</svg> 3: <svg id="svg1" viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
<rect id="rect1" x="20" y="20" width="160" style="fill: green" height="160"/>
</svg> Style sheet: rect {
fill: blue;
} Results: So indeed, looks like |
Looks good overall. Thanks again! |
Not really in a mergeable state yet, but opening it for discussion. In particular:
style
attribute, which is pretty important (at least for my use case).But if I put that into a function, I once again will have to add some more lifetime annotations which are currently omitted.
Fixes #277.