Comments (4)
Z can be skipped under certain conditions (though what are they precisely?)
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
a. you can already split paths into chunks by checking for move instructions
b. if you're trying to see if it's closed, just 1. keep track of the "home" point 2. keep track of the current cursor 3. see if the cursor is basically at the home point at the last command before the end or another move
from svgo.
Is isSafeToUseZ === !isSafeToSkipZ
though? I feel like it isn't, no?
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.
from svgo.
Is isSafeToUseZ === !isSafeToSkipZ though? I feel like it isn't, no?
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.
Also, as you can see with the triangle examples above, the stroke is not continuous despite the cursor arriving at the home point.
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.
from svgo.
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 Z
if it could affect the behavior of any stroke cap/join style".
from svgo.
Related Issues (20)
- Problem with setup HOT 4
- removeUselessDefs removes <symbol> which contains children with IDs
- removeHiddenElems removes <symbol> which contains children with IDs
- v3.2.0 'Cannot read properties of undefined' error in reflectPoint HOT 1
- collapseGroups does not move attributes atomically HOT 2
- Fail to install with npm HOT 2
- prefixIds fails to prefix when classes and comments are on the same line HOT 2
- Stringifies path data with extra 0s HOT 1
- Error: EMFILE: too many open files HOT 1
- Misoptimised svg: File becomes empty after applying svgo 3.2.0 with default settings HOT 1
- Remove trailing M
- Multiple plugins make unsafe transformations in the presence of a style element.
- some URL references not detected properly HOT 1
- bug: removeScriptElement throws away xml:space=preserve for children elements HOT 2
- Optimize SVG Sprites HOT 3
- cleanupAttrs in 'preset-default' overrides is not respected
- Improve node.children handling HOT 9
- `nxp svgo@latest a.svg -o b.svg` doesn't work HOT 3
- Option to change props to React Pattern HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svgo.