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

Improve coordinates rounding #198

Open lexeii opened 5 years ago

lexeii commented 5 years ago

Now I am compressing the whole icon theme with the help of the svgcleaner (and Inkscape and Sublime Text). I believe that precision of 1/10 pixel is enough. Svgcleaner provides good results in the most cases, but sometimes error accumulates and resulting in the distorted shapes.

I use these options to round coordinates to 0.1 (and to satisfy my other needs):

--remove-unresolved-classes no
--multipass
--apply-transform-to-paths yes
--coordinates-precision 1
--path-coordinates-precision 1

Version of svgcleaner is 0.9.1.

Generic example follows. We can define the same path using absolute coordinates:

M 1,1 L 1.25,1.25 L 1.25,2.25 L 2.5,2.5 L 2.5,3.5 L 3.75,3.75

or relative paths:

m 1,1 l .25,.25 l 0,1 l 1.25,.25 l 0,1 l 1.25,.25

In the case with absolute coordinates svgcleaner makes it's best resulting in:

m1 1 .3.3v1l1.2.2v1l1.3.3

In the case with relative paths rounding error (0.25→0.3) accumulated resulting in:

m1 1 .3.3v1l1.3.3v1l1.3.3

Possible solution:

  1. convert original paths to absolute (new action);
  2. round coordinates (how is it done now);
  3. convert rounded paths to relative paths (how is it done now with default --paths-to-relative yes).