resvg icon indicating copy to clipboard operation
resvg copied to clipboard

Feature request: stylesheet injection

Open pontaoski opened this issue 4 years ago • 4 comments

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

pontaoski avatar Apr 11 '20 00:04 pontaoski

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.

RazrFalcon avatar Apr 11 '20 13:04 RazrFalcon

@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).

JoKalliauer avatar May 25 '21 07:05 JoKalliauer

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

edhebi avatar Jun 02 '23 15:06 edhebi

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

RazrFalcon avatar Jun 02 '23 18:06 RazrFalcon