RazrFalcon / resvg

An SVG rendering library.
Mozilla Public License 2.0
2.63k stars 216 forks source link

Feature request: stylesheet injection #277

Open pontaoski opened 4 years ago

pontaoski commented 4 years ago

Title is self-explanatory: the ability to add a stylesheet when rendering an SVG without needing to modify the XML input.

RazrFalcon commented 4 years ago

Yes, I do have plans on such feature, but I still not sure in what order an external css should be applied. Before or after the embedded one.

JoKalliauer commented 3 years ago

@RazrFalcon FYI: @federicomenaquintero declared at librsvg:

The external CSS is loaded as for the User origin; the styles declared in the SVG document have the Author origin. The cascading rules make use of the origin and specificity of a selector to determine what takes precedence.

That makes sense for me, since the svg-specific css is generally imho more specific than the external one.

Example: Wikimedia renders the math-latex-equations somehow from svg2png using librsvg (but wihtout any css). If something is specified in the equation something should overwrite (i.e. higher priority) general one from the surrounding text (e.g. current text-color).

edhebi commented 1 year ago

Hi, are there still plans for that feature and/or are there specific blocking elements or other priorities ? I would be willing to contribute time to implement it, but I'm wondering if this is at the implementation or design stage.

Sincerely

RazrFalcon commented 1 year ago

The main blocking issue is that I have no time. The only hard part here is to figure out the order of CSS. Should the injected CSS override the SVG/embedded CSS properties or not. Which means testing. Which takes time.

If you want to try it, you should start here: https://github.com/RazrFalcon/resvg/blob/6be2f2d396e539ddfcf022dc67f304d307c1211a/crates/usvg-parser/src/svgtree/parse.rs#L505