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

fix: mergePaths should not merge paths with styles that depend on bounding box #1964

Merged
merged 5 commits into from
Feb 25, 2024

Conversation

johnkenny54
Copy link
Contributor

This PR fixes the problem raised in issue #1267. The general issue is that merging paths into a single element changes the bounding box, so any style that depends on the bounding box of the element may change behavior. This PR disables merging for any paths that have:

  • A fill, filter, or stroke that references a URL.
  • A clip-path or mask.

It's possible that there are other scenarios where merging should be disabled, but those above are the only ones that I was able to construct a test case for so far.

With the current regression settings, there is no change in pixel mismatches in the regressions. With the Oxygen files, only one file seems to be affected - scalable/status/weather-few-clouds-night.svg. The clouds were rendered incorrectly in the optimized version before the fix.

Closes #1267

@johnkenny54 johnkenny54 marked this pull request as ready for review February 15, 2024 16:16
Copy link
Member

@SethFalco SethFalco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left one minor comment, but overall this looks good. Thanks for spotting the issue and submitting a patch.

plugins/mergePaths.js Outdated Show resolved Hide resolved
johnkenny54 and others added 2 commits February 24, 2024 16:41
Co-authored-by: Seth Falco <seth@falco.fun>
@SethFalco SethFalco merged commit a8d2df6 into svg:main Feb 25, 2024
8 checks passed
@KTibow
Copy link
Contributor

KTibow commented Feb 25, 2024

I'm a bit late here but this "is the path bounding box sensitive?" logic would be useful for #1951, and I'm going to move it to a function to reduce duplication. Which file would that function best fit in?

@SethFalco
Copy link
Member

@KTibow Nothing shouts out to me, so I'd default to lib/svgo/tools.js.

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

Successfully merging this pull request may close these issues.

Combining multiple shapes into a <path> breaks <linearGradient>
3 participants