Skip to content

convertPathData does not apply transform="rotate()" even with forceAbsolutePath #2151

Open
@qubodup

Description

@qubodup

Describe the bug
convertPathData (turned on by default) does not apply transformations, even when forceAbsolutePath is true.

This is a bug because --help states "applies transformations", which implies all transformations. The rotate() transformation in the example below is not applied.

$ svgo --show-plugins | grep "applies transformations"
 [ convertPathData ] optimizes path data: writes in shorter form, applies transformations

If the function is not fixable, for now the --help entry could be updated to list supported transforms or to just state "some" or "most" transforms.

Clarification would also be useful at:
https://github.com/svg/svgo/blob/9e2029f9b101da81ef612ff7606669c71faf9085/docs/04-plugins/convertPathData.mdx?plain=1#L8C32-L8C42

To Reproduce

Prepare the files and run the command below.

svgo.config.js:

module.exports = {
  plugins: [
    {
      name: 'preset-default',
      params: {
        overrides: {
          convertPathData: {
            forceAbsolutePath: true,
          },
        },
      },
    },
  ],
};

transform.svg:

<svg xmlns="http://www.w3.org/2000/svg" width="181.019" height="181.019" viewBox="0 0 47.895 47.895"><path d="M-47.692 162.318h33.867v33.867h-33.867z" style="fill:#00a8ff" transform="rotate(-45 -190.875 35.563)"/></svg>

command:
svgo --config=svgo.config.js -i transform.svg -o plugintest.svg

plugintest.svg:

<svg xmlns="http://www.w3.org/2000/svg" width="181.019" height="181.019" viewBox="0 0 47.895 47.895"><path d="M-47.692 162.318H-13.825V196.185H-47.692z" style="fill:#00a8ff" transform="rotate(-45 -190.875 35.563)"/></svg>

Expected behavior
transform="rotate(-45 -190.875 35.563)" should be applied/baked.

I can get rid of it using path/intersection (bigger object must be below transformed object) and after svgo and manual style/size cleanup I get:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 47.895 47.895"><path d="M23.948-.001 0 23.947 23.948 47.894 47.895 23.947z" fill="#00a8ff"/></svg>

Screenshots
Image

Desktop (please complete the following information):

  • SVGO Version 3.3.2
  • Node.js Version 22.16.0
  • OS: Windows 10 Version 10.0.19045.5965

Additional context
Thank you for this great tool! Trying to optimize submissions for game-icons/icons as they recommend svgo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions