Skip to content

Commit

Permalink
plugins/convertPathData: do not remove very first M from the path data (
Browse files Browse the repository at this point in the history
fix #24)
  • Loading branch information
deepsweet committed Oct 23, 2012
1 parent f73e05a commit 0d32aa9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions plugins/convertPathData.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,17 @@ function filters(path, params) {
point = [0, 0],
prev = {
point: [0, 0]
};
},
index = 0;

path = path.filter(function(item) {

instruction = item.instruction;
data = item.data;
point = item.point;

index++;

if (data) {

if (params.floatPrecision) {
Expand All @@ -308,19 +311,25 @@ function filters(path, params) {
}
}

// remove useless path segments
// remove useless non-first path segments
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
if (
'mlhvqtcs'.indexOf(instruction) > -1 &&
(
'lhvqtcs'.indexOf(instruction) > -1 ||
(instruction === 'm' && index > 1)
) &&
data.every(function(i) { return i === 0; })
) {
return false;
}

// 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,
every = data.every(function(d) {
return d - prev.point[++i % 2] === 0;
Expand Down
2 changes: 1 addition & 1 deletion test/plugins/convertPathData.07.should.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0d32aa9

Please sign in to comment.