Commit a41a7c1
authored
fix(convertPathData): introducing isSafeToRemove (#2164)
Removing useless commands: a tricky and inconsistent business. SVGO
currently uses two approaches:
- **!maybeHasStrokeAndLinecap** for the purpose of removing useless line
commands
This works decently. It allows for removing useless lines, while not
removing dots.
Flaw: Even in a path with linecaps, if there are "dot" commands after
the first move, they wouldn't render at all and should be removed. They
currently aren't.
- **isSafeToUseZ** for the purpose of removing useless `z` commands
isSafeToUseZ is defined as either having no stroke or having a all-round
stroke. When that's true, a line home and a z command render the same
way, and can be exchanged or removed.
Flaw: This works great when removing a redundant `z` that comes right
after another command, but what if the `z` is the first move (for the
purpose of creating a dot)? Then it's incorrectly removed. This is shown
in #2158 and #2163.
This PR introduces isSafeToRemove to help. It's worth reading through
the code, but the TLDR is that it uses a more sane method, categorizing
the path into non-stroked, stroked + first draw command, and stroked but
non-first command, and using fitting behavior in each case.
Fixes #2158 and fixes #2163.1 parent 38625dd commit a41a7c1
4 files changed
Lines changed: 52 additions & 11 deletions
File tree
- plugins
- test
- plugins
- regression/lists
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
158 | | - | |
159 | 158 | | |
160 | 159 | | |
161 | 160 | | |
162 | 161 | | |
163 | 162 | | |
164 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
165 | 177 | | |
166 | 178 | | |
167 | 179 | | |
| |||
174 | 186 | | |
175 | 187 | | |
176 | 188 | | |
177 | | - | |
| 189 | + | |
178 | 190 | | |
179 | 191 | | |
180 | 192 | | |
| |||
378 | 390 | | |
379 | 391 | | |
380 | 392 | | |
381 | | - | |
| 393 | + | |
382 | 394 | | |
383 | 395 | | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
| 396 | + | |
389 | 397 | | |
390 | 398 | | |
391 | 399 | | |
| |||
835 | 843 | | |
836 | 844 | | |
837 | 845 | | |
838 | | - | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
839 | 850 | | |
840 | 851 | | |
841 | 852 | | |
| |||
891 | 902 | | |
892 | 903 | | |
893 | 904 | | |
894 | | - | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
895 | 909 | | |
896 | 910 | | |
897 | 911 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
| |||
0 commit comments