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 an option to always keep/add Z
in convertPathData
#1940
Comments
If the cursor is already at the home point and if it's safe. How do you determine if it's safe? // This is how.
const isSafeToUseZ = maybeHasStroke
? computedStyle["stroke-linecap"]?.type === "static" &&
computedStyle["stroke-linecap"].value === "round" &&
computedStyle["stroke-linejoin"]?.type === "static" &&
computedStyle["stroke-linejoin"].value === "round"
: true; If you're looking for help with implementation, consider that |
Is Also, as you can see with the triangle examples above, the stroke is not continuous despite the cursor arriving at the home point. So there must be some limit to the acuteness of the resulting corner, since the square does get auto-closed 🤔 These screenshots are from Firefox, just in case. |
You can look through the code, isSafeToUseZ === isSafeToSkipZ for all of SVGO's purposes. We define "safe" as not having a non-round stroke. It's really that simple.
You're correct, when you have a non-round stroke sometimes you can still skip z. However SVGO never skips z with a non-round stroke - I was initially planning to do so but the logic that converts lines to z if the following command is z is good enough. |
Okay, I see, SVGO can be more aggressive if it's assumed that the image is used as-is. In our case, we later programmatically manipulate it and add/remove stroking, and change its style, the miter limit, etc. Would it make sense to have an option for this? Something like "don't remove |
Is your feature request related to a problem? Please describe.
I understand that
Z
can be skipped under certain conditions (though what are they precisely?), but we'd like for it to be explicit, as we have algorithms that operate on path data, and we don't want to add any logic for handling this.Describe alternatives you've considered
We could adjust our code so that it can handle geometrically closed paths, but I'm unable to even find the spec. Currently using
removeUseless: false
to work around this, but I assume it disables more than just the removal ofZ
.Additional context
M 50,50 80,50 80,80 50,80 50,51
(not closed, just for demo of self-closing below)M 50,50 80,50 80,80 50,80 50,50
M 50,50 80,50 80,80 50,80 z
M 50,50 80,50 80,80 50,50
M 50,50 80,50 80,80 z
The text was updated successfully, but these errors were encountered: