linebender / resvg

An SVG rendering library.
Apache License 2.0
2.84k stars 229 forks source link

Fix context paint on shape with zero-size bbox #725

Closed LaurenzV closed 8 months ago

LaurenzV commented 8 months ago

Consider the following SVG:

<svg id="svg1" viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
    <title>`context-stroke` on shape with zero-size bbox</title>

    <marker id="marker1" refX="10" refY="10" markerWidth="20" markerHeight="20">
        <path id="path-marker" d="M 10 0 16 20 H 4 Z" fill="context-stroke"/>
    </marker>
    <path id="path1" stroke="green" d="M 100 25 L 100 175"
          marker-end="url(#marker1)"/>
    <!-- image frame -->
    <rect id="frame" x="1" y="1" width="198" height="198" fill="none" stroke="black"/>
</svg>

Currently, it renders like this: test

The reason being that in my previous implementation, I wrongly assumed that we always need to have a bbox for context-fill/context-stroke, which is not true for solid paints. Since a line doesn't have a bbox, this example would fail to render correctly previously. This PR fixes this: test

RazrFalcon commented 8 months ago

Thanks. Zero width/height bbox are tricky to handle in SVG.