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

Suboptimal output after upgrading to version 2.3 #1476

Closed
joseprio opened this issue May 19, 2021 · 4 comments
Closed

Suboptimal output after upgrading to version 2.3 #1476

joseprio opened this issue May 19, 2021 · 4 comments

Comments

@joseprio
Copy link
Contributor

Describe the bug
Seems to be a regression of #1403; after updating from version 1 to 2, I noticed an increase in file size. I applied the additional configuration from #1353, and while it improved the situation, the there's still some superfluous spaces added to the arc command.

To Reproduce
Original SVG optimized with version 1:

<svg viewBox="0 0 18 18"><path fill-rule="evenodd" d="M8.153 3.352h6.669c.65 0 1.178.526 1.178 1.174v8.3c0 .648-.528 1.174-1.178 1.174H3.177C2.527 14 2 13.474
2 12.825V4.68c.014-.248.109-.484.269-.674l1.61-1.719c.18-.17.414-.272.662-.286h1.891c.248.014.484.113.667.28l1.054 1.072zm.835 1.977v.004a3.344 3.344 0 00-3.35
3.337 3.344 3.344 0 003.351 3.336 3.344 3.344 0 003.347-3.34c0-1.843-1.5-3.337-3.348-3.337zm.01.977a2.36 2.36 0 012.18 1.452c.365.879.163 1.89-.512 2.563a2.364
2.364 0 01-2.572.51 2.352 2.352 0 01-1.456-2.174 2.355 2.355 0 012.36-2.347v-.004z"/></svg>

After applying 2.3:

<svg viewBox="0 0 18 18"><path fill-rule="evenodd" d="M8.153 3.352h6.669c.65 0 1.178.526 1.178 1.174v8.3c0 .648-.528 1.174-1.178 1.174H3.177C2.527 14 2 13.474
2 12.825V4.68c.014-.248.109-.484.269-.674l1.61-1.719c.18-.17.414-.272.662-.286h1.891c.248.014.484.113.667.28l1.054 1.072zm.835 1.977v.004a3.344 3.344 0 00-3.35
3.337 3.344 3.344 0 0 0 3.351 3.336 3.344 3.344 0 0 0 3.347-3.34c0-1.843-1.5-3.337-3.348-3.337zm.01.977a2.36 2.36 0 012.18 1.452c.365.879.163 1.89-.512 2.563a2.
364 2.364 0 01-2.572.51 2.352 2.352 0 0 1-1.456-2.174 2.355 2.355 0 0 1 2.36-2.347v-.004z"/></svg>

a3.344 3.344 0 00-3.35 3.337 3.344 3.344 0 003.351 3.336 3.344 3.344 0 003.347-3.34 got converted to a3.344 3.344 0 00-3.35 3.337 3.344 3.344 0 0 0 3.351 3.336 3.344 3.344 0 0 0 3.347-3.34; notice how spaces are removed only sometimes.
Expected behavior
When using the noSpaceAfterFlags, I expect that all unneeded spaces are removed like in previous versions.

@joseprio joseprio added the bug label May 19, 2021
@TrySound
Copy link
Member

Hi. Show your config and original svg please.

@joseprio
Copy link
Contributor Author

joseprio commented May 19, 2021

@TrySound sorry about that; I only keep the optimized SVG, so that's the "original", and the regression appears when running the new SVGO on it. Here's my configuration:

  const optimizedSvg = optimize(data, { path: file,
    // js2svg: {pretty: true, indent: 4},
  plugins: [
    'cleanupAttrs',
    'removeDoctype',
    'removeXMLProcInst',
    'removeComments',
    'removeMetadata',
    'removeTitle',
    'removeDesc',
    'removeUselessDefs',
    'removeEditorsNSData',
    'removeEmptyAttrs',
    'removeHiddenElems',
    'removeEmptyText',
    'removeEmptyContainers',
    'cleanupEnableBackground',
    'convertStyleToAttrs',
    'convertColors',
    {
      name: 'convertPathData',
      params: {
        noSpaceAfterFlags: true,
      }
    },
    'convertTransform',
    'removeNonInheritableGroupAttrs',
    'removeUselessStrokeAndFill',
    'removeUnusedNS',
    'cleanupIDs',
    'cleanupNumericValues',
    'moveElemsAttrsToGroup',
    'moveGroupAttrsToElems',
    'collapseGroups',
    {
      name: 'mergePaths',
      params: {
        noSpaceAfterFlags: true,
      }
    },      
    'convertShapeToPath',
    'sortAttrs',
    'removeDimensions',
    {
      name: 'removeAttrs',
      params: {
        attrs: '(class|stroke|fill-opacity|stroke-width|opacity)',
      },
    },
  ]
   });
  fs.writeFileSync(file, optimizedSvg.data, { encoding: 'utf8' });

noSpaceAfterFlags is definitely working because if I remove it, some spaces are added.

@joseprio
Copy link
Contributor Author

joseprio commented Jun 4, 2021

It seems that multiple, consecutive arc commands are merged in a single command call, and the changes in #1403 only applied to the first one. I did a quick PR with the solution; happy to add any changes as needed!

TrySound added a commit that referenced this issue Aug 12, 2021
Ref #1476

The issue is that a path command may have multiple arcs, and the space optimization was only applied to the first one. Modified a test to check it.


Co-authored-by: Josep del Río <[email protected]>
Co-authored-by: Bogdan Chadkin <[email protected]>
@TrySound
Copy link
Member

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

No branches or pull requests

2 participants