-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat(applyTransformsShapes): new plugin #1854
base: main
Are you sure you want to change the base?
Conversation
f5bb766
to
6305213
Compare
Work fine for me, but why |
I haven't considered applying transforms to text. Would you mind providing a couple examples of places where I can apply the transform and a couple places where I can't? |
<svg xmlns="http://www.w3.org/2000/svg">
<text y="7" transform="translate(1270 167)">abcdefg</text>
<!-- ↓ could be -->
<text x="1270" y="174">abcdefg</text>
</svg> |
I know that there's a |
I don't know the details of Maybe adding |
This comes up a lot in Inkscape - it includes a bunch of redundant and seemingly useless attributes/elements. If you create 2 text elements and resize the canvas, you get something like:
The x/y on the text don't seem to do anything, it's only the tspan coordinates that matter. |
It looks complicated, Maybe you guys can merge this PR first, leave The / problem to next round ? |
is this feature implemented? I see that the svg transformations get flattened when I try to use I noticed this file in the repo, is this the plugin? |
SVGO already flattens transforms for paths. This PR adds a new plugin that does it for shapes, like circles or images. SVGO won't have it until this is merged. |
@SethFalco any blockers on this? |
No blockers, I was just prioritizing issues that fix regression tests. Sorry to keep you waiting though, in fact, I'll review this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please rebase and review the failed tests from KDE Oxygen Icons?
This breaks quite a lot of the icons, so before giving it a proper review, it'd be worth resolving those locally.
I've only manually reviewed/confirmed that battery-charging-080.svg
broke, but overall it introduced 600+ failures.
40c1275
to
87f00da
Compare
So looks like the mismatches are because gradients can get messed up by changing the orientation. This would be solved by checking for gradients, but I don't want to duplicate code, and now I'm seeing that we have many places where we might want to check for references in SVGO:
I would normally want to simply extract it all out to a function, but the behavior is different for different cases (in fact, we don't run |
We do already have the There's also If we don't need to check for all references props, happy for us to pass a third parameter with an array of
Just checking, when you note that the behavior is different for different cases, are you referring to in theory we need to handle this differently in certain plugins, or just that how we approach this now is inconsistent? Immediately, as you say, it'd be good to extract some of the logic (or at least the common parts of it) into a function like
Agreed, but best for a separate issue/PR. Once this is finalized, we can refactor |
After a bit of thinking, I've concluded that these should be the same for the most part. If we were to have a basis, it would be Here's how we handle it now in computedStyle['marker-start'] ||
computedStyle['marker-mid'] ||
computedStyle['marker-end'] ||
computedStyle['clip-path'] ||
computedStyle['mask'] ||
computedStyle['mask-image'] ||
['fill', 'filter', 'stroke'].some((attName) =>
elementHasUrl(computedStyle, attName),
) I believe in almost all of the cases where this is tripped, applyTransforms shouldn't run, and if it isn't tripped a path is likely safe. The only possible change we might make when using it in |
But more deliberation can be saved for later. Which way would you recommend moving forward with this PR?
|
For the most part, just whatever you're comfortable with, tbh. 👍🏽 In terms of reviewing, I think the easiest would be:
Makes sense to refactor |
01f2a58
to
5645768
Compare
Right now transforms can only be applied to paths. This plugin applies them to circle, ellipse, rect, and image. These transforms often come from graphical editors.
Has 99% line test coverage
Closes #989
Closes #594
Results
While this plugin doesn't help with any of the common test cases, it does help with some other real situations.
-82b compared to current SVGO
While I didn't do a full size comparison, I tested it on a number of SVGs, and it successfully applied the transformations. For example, this SVG