RazrFalcon / svgcleaner

svgcleaner could help you to clean up your SVG files from the unnecessary data.
GNU General Public License v2.0
1.63k stars 94 forks source link

remove-invisible-elements removes <clipPath> with <g> #161

Closed JoKalliauer closed 6 years ago

JoKalliauer commented 6 years ago

Processing File:Oxygen15.04.1-application-x-bzip.svg with

svgcleaner input.svg output.svg --indent 1

accoring to Validators: Error: SVG element g not allowed as child of SVG element clipPath in this context. (Suppressing further errors from this subtree.) or with DTD: document type does not allow element "g" here

so the problem is:

 <clipPath id="ai">
  <g transform="matrix(.8051 0 0 .8051 12.58 14.2)">
   <path d="m23.156 54.281c-.554-.002-1.08.0166-1.5625.0313-2.57.0782-4.06.375-4.0625.375v68.594c.141.68.751 1.19 1.4688 1.1875l55 .0313c.0531 0 .998-.008 1.6875 0 10.1-4 25.4-22.5 34.344-31.469 1.48-1.66 1.13-1.14 1.4688-2.875v-35.469c-.174-.0174-29.5-2.92-49.062 16.656-14.8-14.8-31-17-39.281-17.062z" fill="#cebfa5" opacity=".4"/>
  </g>
 </clipPath>

But librsvg and inksape render it still correctly.

I would keep such elements, but as I said the file is invalid, therefore you might want to close this issue.


input.svg.txt

 <clipPath id="ai">
  <g transform="matrix(.8051 0 0 .8051 12.58 14.2)">
   <path d="m23.156 54.281c-.554-.002-1.08.0166-1.5625.0313-2.57.0782-4.06.375-4.0625.375v68.594c.141.68.751 1.19 1.4688 1.1875l55 .0313c.0531 0 .998-.008 1.6875 0 10.1-4 25.4-22.5 34.344-31.469 1.48-1.66 1.13-1.14 1.4688-2.875v-35.469c-.174-.0174-29.5-2.92-49.062 16.656-14.8-14.8-31-17-39.281-17.062z" fill="#cebfa5" opacity=".4"/>
  </g>
 </clipPath>

[...]

 <g display="none" transform="translate(1042 -279.83)">
  <image height="571" opacity=".75" width="571" xlink:href="data:image/png;base64,"/>
  <circle cx="279.52" cy="278.93" r="275.91"/>
  <path d="m555.424 278.934c0 152.3803-123.5287 275.909-275.909 275.909s-275.909-123.5287-275.909-275.909 123.5287-275.909 275.909-275.909 275.909 123.5287 275.909 275.909z"/>
 </g>
 <g display="none" fill="#fff" transform="translate(1042 -279.83)">
  <circle cx="279.52" cy="278.93" display="inline" r="275.91"/>
  <path d="m555.424 278.934c0 152.3803-123.5287 275.909-275.909 275.909s-275.909-123.5287-275.909-275.909 123.5287-275.909 275.909-275.909 275.909 123.5287 275.909 275.909z" display="inline"/>
 </g>
 <rect fill="#fff" height="0" opacity=".58" width=".64" x="563.78" y="130.76"/>

[...]

 <g clip-path="url(#ai)" transform="matrix(1.2421 0 0 1.2421 -15.89 -21.98)">
  <path d="m23.156 54.281c-.554-.002-1.08.0166-1.5625.0313-2.57.0782-4.06.375-4.0625.375v68.594c.141.68.751 1.19 1.4688 1.1875l55 .0313c.0531 0 .998-.008 1.6875 0 10.1-4 25.4-22.5 34.344-31.469 1.48-1.66 1.13-1.14 1.4688-2.875v-35.469c-.174-.0174-29.5-2.92-49.062 16.656-14.8-14.8-31-17-39.281-17.062z" fill="#adb9c6" opacity=".4"/>
  <path d="m25.877 54.281c-.364.0059-.735.0212-1.0625.0313-2.57.0782-4.06.375-4.0625.375v5.0938l62.406 62.406c1.91-1.26 3.93-2.83 6-4.625zm83.844.25c-2.32.0234-5.32.157-8.75.5938l13.75 13.781v-10.625l-3.75-3.75c-.403-.0037-.791-.0046-1.25 0zm-71.875 1.125 56.812 56.812c1.77-1.73 3.52-3.54 5.25-5.3438l-43.219-43.219c-6.64-4.52-13.2-6.95-18.844-8.25zm54.188 1.1562c-2.6.666-5.28 1.54-8 2.625l30.687 30.656v-10.594zm-15.156 6.0625c-2.16 1.22-4.31 2.62-6.375 4.2188l34.562 34.562c1.81-1.95 3.55-3.74 5.1562-5.4375zm-56.125 7.5312v10.562l43.5 43.531h10.625zm0 21.188v10.625l22.281 22.25 10.625.0313-32.906-32.906zm0 21.219v10.469c.0166.0801.0647.144.0938.2188l.8438.8438c.0134.005.0177.0263.0313.0313.16.0582.32.0936.5.0937h10.188z" opacity=".1"/>
 </g>

input


output.svg.txt output

RazrFalcon commented 6 years ago

This is a correct behavior. clipPath does not support g children. They have no effect. It's a known Inkscape bug (not sure for librsvg).

JoKalliauer commented 6 years ago

svgo using collapseGroups can repair such files with:

svgo -i input.svg.txt -o output.svg.txt --disable=removeUnknownsAndDefaults --enable=collapseGroups --disable=convertPathData


min.svg.txt output.svg.txt