Kozea / CairoSVG

Convert your vector images
https://courtbouillon.org/cairosvg
GNU Lesser General Public License v3.0
753 stars 149 forks source link

Handle external stylesheets #258

Open jaapvandervelde opened 4 years ago

jaapvandervelde commented 4 years ago

I'm including an svg element like this:

    <object type="image/svg+xml" data="chart.svg"></object>

When loading the .svg in a browser, the styling linked to the .svg is applied:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<?xml-stylesheet type="text/css" href="chart_svg.css" ?>
<svg height="345.6pt" version="1.1" viewBox="0 0 460.8 345.6" width="460.8pt" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">

etc.

However, when loading the .html linking the .svg in weasyprint, the svg is rendered correctly, but the linked styling is not applied.

The styling itself is correct, I've verified by copying the content from the .css and moving it into the <style> element inside the .svg, as a child of the <svg> element and it is applied correctly, so the issue appears to be that the svg rendering in weasyprint does not load the external stylesheet.

Although not relevant to the issue, it seems, here's an example statement from that css:

#line2d_147 path {
    stroke: deeppink !important;
}
jaapvandervelde commented 4 years ago

Note that, as a workaround, I can insert the contents of the external stylesheet at the end of the internal <style> element, but of course this requires some munging of the .svg and the use of an external stylesheet seems valid and preferable.

liZe commented 4 years ago

Thanks for this bug report.

It's actually a missing feature in CairoSVG, let's move this issue over there!

liZe commented 4 years ago

See https://www.w3.org/TR/SVG11/styling.html#StylingWithCSS and https://github.com/Kozea/CairoSVG/tree/master/test_non_regression/fail/css