1
0
mirror of https://github.com/svg/svgo.git synced 2025-07-04 16:42:27 +03:00

plugins/convertPathData: do not remove very first M from the path data (fix #24)

This commit is contained in:
deepsweet
2012-10-23 21:43:10 +03:00
parent f73e05a0e6
commit 0d32aa9f6f
2 changed files with 14 additions and 5 deletions

View File

@ -276,7 +276,8 @@ function filters(path, params) {
point = [0, 0], point = [0, 0],
prev = { prev = {
point: [0, 0] point: [0, 0]
}; },
index = 0;
path = path.filter(function(item) { path = path.filter(function(item) {
@ -284,6 +285,8 @@ function filters(path, params) {
data = item.data; data = item.data;
point = item.point; point = item.point;
index++;
if (data) { if (data) {
if (params.floatPrecision) { if (params.floatPrecision) {
@ -308,19 +311,25 @@ function filters(path, params) {
} }
} }
// remove useless path segments // remove useless non-first path segments
if (params.removeUseless) { if (params.removeUseless) {
// m 0,0 / l 0,0 / h 0 / v 0 / q 0,0 0,0 / t 0,0 / c 0,0 0,0 0,0 / s 0,0 0,0 // m 0,0 / l 0,0 / h 0 / v 0 / q 0,0 0,0 / t 0,0 / c 0,0 0,0 0,0 / s 0,0 0,0
if ( if (
'mlhvqtcs'.indexOf(instruction) > -1 && (
'lhvqtcs'.indexOf(instruction) > -1 ||
(instruction === 'm' && index > 1)
) &&
data.every(function(i) { return i === 0; }) data.every(function(i) { return i === 0; })
) { ) {
return false; return false;
} }
// M25,25 L25,25 C 25,25 25,25 25,25 // M25,25 L25,25 C 25,25 25,25 25,25
if ('MLHVQTCS'.indexOf(instruction) > -1) { if (
'LHVQTCS'.indexOf(instruction) > -1 ||
(instruction === 'M' && index > 1)
) {
var i = -1, var i = -1,
every = data.every(function(d) { every = data.every(function(d) {
return d - prev.point[++i % 2] === 0; return d - prev.point[++i % 2] === 0;

View File

@ -1,5 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg"> <svg xmlns="http://www.w3.org/2000/svg">
<path d=""/> <path d="m0 0"/>
<path d=""/> <path d=""/>
<path d=""/> <path d=""/>
<path d=""/> <path d=""/>

Before

Width:  |  Height:  |  Size: 167 B

After

Width:  |  Height:  |  Size: 171 B