Skip to content

Incorrect svg simplification by usvg for images with clipPath, use and transform #921

@woodroof

Description

@woodroof

Minimal reproducible example:

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 20 20">
    <defs>
        <rect id="id1" y="0.4" transform="matrix(-1 0 0 -1 20 20)" width="20" height="19.2"/>
    </defs>
    <clipPath id="id2">
        <use xlink:href="#id1" />
    </clipPath>
    <rect clip-path="url(#id2)" x="5" y="5" width="10" height="10" fill="red"/>
</svg>

Usvg result:

<svg width="20" height="20" xmlns="http://www.w3.org/2000/svg">
    <defs>
        <clipPath id="id2"/>
    </defs>
    <g clip-path="url(#id2)">
        <path fill="#ff0000" stroke="none" d="M 5 5 L 15 5 L 15 15 L 5 15 Z"/>
    </g>
</svg>

clipPath doesn't have any geometry, and it should.
Everything works correctly if I remove transform or replace use with rect. It also works with identity matrix, i.e. transform="matrix(1 0 0 1 0 0)".

Tried to modify this example and use mask instead, and it also works correctly.

The example above can be simplified, but I discovered this problem on a way more complex thirdparty image.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions