SVGs with blur create broken code
Opened this issue · 1 comments
Me again:
I meant to file this one earlier. I found that if I have blur in something in inkscape, svg2cairo doesn't gracefully ignore it, rather it creates uncompilable code. I know blur isn't supported yet in cairo (I'm applying it manually later) but it would be nice to not need to have a extra step removing it. Here is an example svg:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="26.299999"
height="26.299999"
id="svg8365"
version="1.1"
inkscape:version="0.48.4 r9939"
sodipodi:docname="MWE.svg">
<defs
id="defs8367">
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4200"
id="linearGradient5888"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.1558885,0,0,0.53769429,142.55874,116.2103)"
x1="128.75"
y1="337.91769"
x2="128.75"
y2="355.34933" />
<linearGradient
id="linearGradient4200">
<stop
id="stop4202"
style="stop-color:#ff0000;stop-opacity:0"
offset="0" />
<stop
id="stop4204"
style="stop-color:#ff0000;stop-opacity:1"
offset="0.21795145" />
<stop
id="stop4206"
style="stop-color:#ff0000;stop-opacity:1"
offset="0.77006018" />
<stop
id="stop4208"
style="stop-color:#ff0000;stop-opacity:0"
offset="1" />
</linearGradient>
<linearGradient
id="linearGradient5847">
<stop
style="stop-color:#000000;stop-opacity:1;"
offset="0"
id="stop5849" />
<stop
style="stop-color:#ffffff;stop-opacity:1;"
offset="1"
id="stop5851" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient5839"
id="linearGradient5884"
gradientUnits="userSpaceOnUse"
gradientTransform="translate(-9.1361885,22.416719)"
x1="943.0932"
y1="475.09332"
x2="922.98602"
y2="448.48618" />
<linearGradient
id="linearGradient5839">
<stop
style="stop-color:#000000;stop-opacity:1;"
offset="0"
id="stop5841" />
<stop
style="stop-color:#ffffff;stop-opacity:1;"
offset="1"
id="stop5843" />
</linearGradient>
<filter
inkscape:collect="always"
id="filter3785"
x="-0.12"
width="1.24"
y="-0.12"
height="1.24"
color-interpolation-filters="sRGB">
<feGaussianBlur
inkscape:collect="always"
stdDeviation="1"
id="feGaussianBlur3787" />
</filter>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="5.6"
inkscape:cx="-17.574422"
inkscape:cy="6.0524942"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:window-width="1596"
inkscape:window-height="861"
inkscape:window-x="0"
inkscape:window-y="18"
inkscape:window-maximized="0" />
<metadata
id="metadata8370">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-786.85,-427.7875)">
<rect
style="fill:none;stroke:#000000;stroke-width:1.5;stroke-opacity:1;filter:url(#filter3785)"
id="rect5876"
width="20"
height="20"
x="790.0014"
y="430.93277"
ry="0" />
</g>
</svg>
And the code it creates:
int cairo_code_draw_MWEblur_get_width() { return 26; }
int cairo_code_draw_MWEblur_get_height() { return 26; }
void cairo_code_draw_MWEblur_render(cairo_t *cr) {
cairo_surface_t *temp_surface;
cairo_t *old_cr;
cairo_pattern_t *pattern;
cairo_matrix_t matrix;
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
int cairo_code_draw_MWEblur_get_width() { return 26; }
int cairo_code_draw_MWEblur_get_height() { return 26; }
void cairo_code_draw_MWEblur_render(cairo_t *cr) {
cairo_surface_t *temp_surface;
cairo_t *old_cr;
cairo_pattern_t *pattern;
cairo_matrix_t matrix;
}
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_NONE);
cairo_pattern_set_filter(pattern, CAIRO_FILTER_GOOD);
cairo_set_source(cr, pattern);
cairo_pattern_destroy(pattern);
cairo_paint(cr);
/********************/
}
You see it throws an extra curly brace in there where it should be defining a pattern and path. It would be nice if it could just leave out the blur and draw the stroke or at least ignore strokes with blur.
THANKS!!!!
The problem is in the generated xml file:
<image width='26' height='26'>
<paint>
<operator>OVER</operator>
<source-pattern>
<image width='26' height='26' format='ARGB32'>iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAYAAACpSkzOAAAABmJLR0QA/wD/AP+gvaeTAAAA9ElEQVRIie3WvUoDQRSG4WeTjRJNYVBSKAhqZ5MLsPDK7bwG2ygIaUQQf1bZSCzObFgljbsRLPaF08wM552f4psMxzjBAfras8QLZrhDAXmSXOIIZaqm9DFMoms81EX7OEQP93hqIRriDJNUW9VEnqrELa4wbyEa4w1TZGLzKxEsxEnm4lRNKfCId/FWK3prl/8BnagTdaJO1Ik2SBUTfeyIPCla9BtjhIHIo2+ipUjGU1yIPGnKCOdJmKllUi7y/VlE71SEVlMG2MNH6rmoi2biIzERb7Zc0+A39JLkBq/VYCaubRfbftxrC8okKfC5oZ7/jC+2YC525iMICwAAAABJRU5ErkJggg==</image>
<extend>EXTEND_NONE</extend>
<filter>FILTER_GOOD</filter>
</source-pattern>
</paint>
</image>
As you can see, Cairo does not support blur and replaces the blurred rectangle with an image file (base64-encoded PNG). One possible solution is to preprocess the SVG file and to remove the part filter:url(#filter3785)
from the rectangle definition. Then, the Cairo code is correctly generated (without blur).