Fix issue with Z in the middle of SVG path data, not followed by a M command.

Closes #413.
This commit is contained in:
Jürg Lehni 2014-03-12 23:24:09 +01:00
parent 86c5894822
commit afcabea1a7
2 changed files with 15 additions and 14 deletions

View file

@ -192,7 +192,8 @@ var PathItem = Item.extend(/** @lends PathItem# */{
relative = false,
previous,
control,
current = new Point();
current = new Point(),
start = new Point();
function getCoord(index, coord) {
var val = +coords[index];
@ -219,6 +220,8 @@ var PathItem = Item.extend(/** @lends PathItem# */{
coords = part.match(/[+-]?(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g);
var length = coords && coords.length;
relative = command === lower;
if (previous === 'z' && lower !== 'z')
this.moveTo(start);
switch (lower) {
case 'm':
case 'l':
@ -226,6 +229,8 @@ var PathItem = Item.extend(/** @lends PathItem# */{
this[j === 0 && lower === 'm' ? 'moveTo' : 'lineTo'](
current = getPoint(j));
control = current;
if(lower == 'm')
start = current;
break;
case 'h':
case 'v':
@ -248,12 +253,12 @@ var PathItem = Item.extend(/** @lends PathItem# */{
// Smooth cubicCurveTo
for (var j = 0; j < length; j += 4) {
this.cubicCurveTo(
/[cs]/i.test(previous)
/[cs]/.test(previous)
? current.multiply(2).subtract(control)
: current,
control = getPoint(j),
current = getPoint(j + 2));
previous = command;
previous = lower;
}
break;
case 'q':
@ -267,11 +272,11 @@ var PathItem = Item.extend(/** @lends PathItem# */{
// Smooth quadraticCurveTo
for (var j = 0; j < length; j += 2) {
this.quadraticCurveTo(
control = (/[qt]/i.test(previous)
control = (/[qt]/.test(previous)
? current.multiply(2).subtract(control)
: current),
current = getPoint(j));
previous = command;
previous = lower;
}
break;
case 'a':
@ -285,7 +290,7 @@ var PathItem = Item.extend(/** @lends PathItem# */{
this.closePath();
break;
}
previous = command;
previous = lower;
}
},

View file

@ -130,14 +130,10 @@ new function() {
}
function importPath(node) {
// Get the path data, and determine whether it is a compound path or a
// normal path based on the amount of moveTo commands inside it.
var data = node.getAttribute('d'),
path = data.match(/m/gi).length > 1
? new CompoundPath()
: new Path();
path.setPathData(data);
return path;
return new CompoundPath({
pathData: node.getAttribute('d'),
insert: false
}).reduce();
}
function importGradient(node, type) {