Skip to content

(#601) - Compute correct bounds for objects with stroke-width=0

Inkscape sometimes generates SVGs with stroke-width=0. Per the SVG spec, these objects should not be rendered.

Cairo indeed does not render them, but cairo_stroke_extents() will return extents of (0, 0, 0, 0), which the boounding box code interprets as a single point at the origin; it does not interpret it as an empty rectangle that should not be included in the bbox.

This caused a bug when running "rsvg-convert --export-id=foo", since it actually tries to compute the bounds for a single object, instead of the whole document. Trying to render a single subtree that contains an object with stroke_width=0 would create an image whose bounds include the origin, even though the subtree may be far away.

In this commit, we directly compare the stroke_width to 0, and just not compute the stroke extents in that case.

This could be refactored to be done in the step that resolves a paint server or converts it to user space; maybe that code should be made aware of the stroke_width and resolve to UserSpacePaintSource::None if the stroke_width=0.

The code as it is in the master branch makes this a bit hard to test; I'll put the actual test in rustify-rsvg-convert branch.

Fixes #601 (closed)

Merge request reports