-
Notifications
You must be signed in to change notification settings - Fork 226
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
Add support for the transform-origin
attribute.
#679
Conversation
How
There is no concept of z-axis in SVG 1 and therefore in resvg. We can ignore it for now. Not sure if we would ever need it. Also, you have missed Otherwise looks good. But I'm not sure if we handled all possible transform occurrences? Technically, What about
|
Isn't that what most of the tests already do? Or do you mean if there is an additional transform on the parent?
Ah yeah sorry, I keep forgetting to update it. 😅
Yes, I searched for all occurrences. Initially, I had the check for the
True, I didn't consider those. 😅 I guess it's not as straight-forward as I thought. Will try to look into what should happen here and add tests.
Seems like it, but I'll check again why it works.
Will do that. |
Oh, I see. I haven't looked into the files itself. What if we have
SVG tricked you again. It likes to do it. |
The reason it works for texts (and images) as well is that transforms are resolved in the |
Regarding pattern and gradient transforms, I mean it isn't mentioned anywhere explicitly how this should be handled, but given that here it mentions:
It does feel like pattern and gradient transforms should be treated equivalently with normal transforms, so I will add support for those as well. |
So... I'm having a bit of trouble testing the <svg id="svg1" viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
<radialGradient id="rg1" spreadMethod="pad" gradientTransform="translate(0.5 0.5)">
<stop offset="0" stop-color="black"/>
<stop offset="0.3" stop-color="green"/>
</radialGradient>
<rect id="rect1" x="20" y="20" width="160" height="160" fill="url(#rg1)"/>
<!-- image frame -->
<rect id="frame" x="1" y="1" width="198" height="198" fill="none" stroke="black"/>
</svg>
<svg id="svg1" viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"> As I would expect, the center of the gradient appears in the bottom right corner, because we translate it by <svg id="svg1" viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
<pattern id="patt1" patternUnits="objectBoundingBox" patternContentUnits="objectBoundingBox" patternTransform="translate(0.5 0.5)" width="1" height="1">
<rect id="rect1" x="0" y="0" width="0.5" height="0.5" fill="grey"/>
<rect id="rect2" x="0.5" y="0.5" width="0.5" height="0.5" fill="green"/>
</pattern>
<rect id="rect3" x="20" y="20" width="160" height="160"
fill="url(#patt1)" stroke="darkblue"/>
<!-- image frame -->
<rect id="frame" x="1" y="1" width="198" height="198" fill="none" stroke="black"/>
</svg> It barely gets shifted at all, i.e. it seems that the transform is applied in user space units. What am I missing here? From what I can tell they should behave exactly the same: |
I implemented the changes you proposed, but I'm still confused about the gradient/pattern thing, and depending on what you think I might have to make some more changes to it. |
Honestly, no idea what's wrong with patterns. Looks at <svg id="svg1" viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
<pattern id="patt1" width="80" height="80" patternUnits="userSpaceOnUse"
patternContentUnits="userSpaceOnUse" patternTransform="translate(20)">
<rect id="rect1" x="0" y="0" width="40" height="40" fill="grey"/>
<rect id="rect2" x="40" y="40" width="40" height="40" fill="green"/>
</pattern>
<rect id="rect3" x="20" y="20" width="160" height="160"
fill="url(#patt1)" stroke="darkblue"/>
<!-- image frame -->
<rect id="frame" x="1" y="1" width="198" height="198" fill="none" stroke="black"/>
</svg>
|
As for Based on my experiments, And we do not need dedicated Also, I cannot find it in the spec, but MDN says that:
https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/transform-origin Are you using 50% 50% right now or 0 0? Once again, the hardest part about SVG is to actually figure out what you're suppose to do. Not the implementation itself. |
Oh boy...
I see now. I was testing only translations and was confused that it had no effect.
Yes, treat Chrome as a reference implementation unless you're 100% sure it's wrong, which is rare.
My bad again. I thought
No need to. If
The root element is special. It affects browsers, but not resvg. This is because browsers embed SVG into the page content, but resvg renders SVG as a stand-alone image. So it's hard to tell what is the correct output here. Overall, while I'm still a bit confused, I would suggest having as many tests as possible and try to match Chrome output. Except the root element. This case can be ignored for now and/or implemented as a separate patch later. As for how The spec does kinda mention this:
Therefore we're technically correct. But it also mentions:
Which is not always the image size, but we do handle it already via It feels like No more ideas for now. PS: Not gonna lie, I've spend an absurd amount of time figuring out even the current transforms code. It's really really hard. So do no blame yourself. It suppose to be that confusing. PSS: No need for |
Okay, I'll keep that then.
If by fix you mean that it matches the output of Chrome, then yes. So I guess it's best to go back to that behaviour. |
Alright, I changed the gradient ObjectBoundingBox from "center" to "0.5 0.5", so that you can still see it. I double-checked, all tests match the output of Google Chrome now. |
Done. I also applied two clippy lints which I forgot in the PR for text-decoration (first one is using |
Thanks! |
See here.
Fixes #429.
Blocked by linebender/svgtypes#18.
I think it should be correct since it's a relatively simple feature, and I also added a bunch of tests. The only thing I didn't consider was the
z position
, since I've never even seen something like that in this library. Is this something we just don't support yet?