Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to set output presision to 0 (no fractional part) #110

Closed
puzrin opened this issue May 2, 2013 · 1 comment
Closed

Impossible to set output presision to 0 (no fractional part) #110

puzrin opened this issue May 2, 2013 · 1 comment

Comments

@puzrin
Copy link

puzrin commented May 2, 2013

On big images (1000x1000) there are no needs to have fractional part in paths. But SVGO allow only 1 digit minimum after dot.

I did a quick test with regexp:

glyph.d = glyph.d.replace(
  /\d+\.\d+/g,
  function (match) { return Math.round(match) + ''; }
);

~20% profit.

@puzrin
Copy link
Author

puzrin commented May 2, 2013

hm... tested this super-optimizer on 300 glyphs, and found 2, where curves change direction. See attached originals (not passed svgo)

<svg height="1000" width="1000" xmlns="http://www.w3.org/2000/svg"><path d="M0 -32v512h512v-512h-512zM96 161q0 -100 112 -98h120q82 12 89 97v45q-2 30 -20 43.5t-43 14.5q5 18 1 48q-3 31 -24 51.5t-57 23.5h-98q-33 -5 -55 -24.5t-25 -50.5v-150zM145.5 146q-8.5 15 0 30t28.5 18h146q21 -3 29.5 -18t0.5 -30t-28 -18h-146q-22 3 -30.5 18z
M163.5 281.5q-7.5 13.5 0.5 27t28 16.5h80q21 -2 28.5 -15.5t-0.5 -27t-28 -17.5h-80q-21 3 -28.5 16.5z" transform="translate(0 500) scale(1 -1) translate(0 -500) scale(1.953125) translate(0 32)" /></svg>
<svg height="1000" width="1000" xmlns="http://www.w3.org/2000/svg"><path d="M0 -32v512h512v-512h-512zM77 266q-1 -21 3.5 -34t10 -17t14.5 -7l1 -134q0 -1 1 -8t1.5 -8.5t3 -6.5t5.5 -7t9.5 -4.5t15.5 -3.5l54 -1q29 -4 40 39q4 -36 32 -37h63q1 1 5 2t5.5 1.5t5 1.5t5 2.5t4 3.5t3.5 5t2 6.5t2 8.5l1 140l16 -1q14 2 22 6.5t15 19.5v42
q-1 6 -2.5 9.5t-3 4.5t-3.5 2.5t-3 2.5q9 2 13 3.5t9.5 9.5t7.5 22l-1 34q1 30 -41 42q-35 5 -48 5q-31 0 -56 -14q-41 15 -77 12q-98 -9 -105 -96q-14 -1 -22 -10t-8 -36zM113 283l31 -2l-1 12l1 9v9.5t1 10t2 11t3.5 9.5t5 10t7 8t10 7.5t13 5t16.5 3.5q4 0 10 0.5t8 0.5
q16 0 46 -9l1 -41q-27 10 -34 9q-13 0 -20.5 -4.5t-9 -9.5t-3.5 -14v-29l73 -1v19.5t0.5 21t3.5 18t8.5 17.5t16 11.5t26.5 7.5q40 6 72 -8l-1 -43q-12 10 -37 13q-12 1 -19 -1.5t-9 -8t-3.5 -13.5t-1 -16t0.5 -16h52v-38h-52v-173l-57 1v172l-75 -2v-170h-58l2 170h-28z
" transform="translate(0 500) scale(1 -1) translate(0 -500) scale(1.953125) translate(0 32)" /></svg>

changed algorythm, but result is less impressive (10%)

    glyph.d = glyph.d.replace(
      /\d+\.\d+/g,
      function (match) {
        if (+match > 100) {
          return Number(match).toFixed(0) + '';
        }
        return Number(match).toFixed(1) + '';
      }
    );

Seems, curves should be rounded more intelegently. Note, that original source was optimized by fonrtforge, and gives bette results, than SVGO now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant