scour
scour copied to clipboard
Group collapsing doesn't work for empty groups with a tranform attribute
I use Affinity Designer for creating my svg-files. Unfortunately this tool stores all existing groups in the svg export, also of parts that I do not want to export. This leads to lots of empty groups. I want to remove all those empty groups (recursively).
This works fine in most cases. In some cases, the groups have a transform attribute. Those groups remain in the file.
Input:
<?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">
<svg width="100%" height="100%" viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
<g transform="matrix(1,0,0,1,-325,-55)">
<g transform="matrix(1.10876,0,0,1.26098,-91.0415,-15.3672)">
<g id="Save">
</g>
</g>
<g id="StatusOpen" transform="matrix(1,0,0,1,150,0)">
<path id="Circle" d="M185,55C190.519,55 195,59.481 195,65C195,70.519 190.519,75 185,75C179.481,75 175,70.519 175,65C175,59.481 179.481,55 185,55ZM185,57C189.415,57 193,60.585 193,65C193,69.415 189.415,73 185,73C180.585,73 177,69.415 177,65C177,60.585 180.585,57 185,57Z"/>
</g>
</g>
</svg>
Output:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>
<svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" version="1.1" viewBox="0 0 20 20" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
<g transform="translate(-325 -55)">
<g transform="matrix(1.1088 0 0 1.261 -91.042 -15.367)">
</g>
<g transform="translate(150)">
<path d="m185 55c5.519 0 10 4.481 10 10s-4.481 10-10 10-10-4.481-10-10 4.481-10 10-10zm0 2c4.415 0 8 3.585 8 8s-3.585 8-8 8-8-3.585-8-8 3.585-8 8-8z"/>
</g>
</g>
</svg>
scour-call:
scour -i "Input.svg" -o "Output.svg" --enable-id-stripping --enable-comment-stripping --shorten-ids --indent=none --no-line-breaks
You can find a lot of small svg files that come with this issue here in my repository. Feel free to use them for testing.
This issue might be related to #20 but comes with a slightly different flavour. Stripping the group ID does not help here :)
The fact that --indent=none
and --no-line-breaks
have no effects have been reported in #297
I use scour 0.38.2 with Python 3.10.4