From 6f8444c86ab66f68309a5dcacfe0b758b08a4c56 Mon Sep 17 00:00:00 2001 From: Jim Rodovich Date: Fri, 30 May 2014 10:08:03 -0500 Subject: [PATCH] Convert extra "moveto" coordinates to "lineto" commands. Per the [SVG spec](http://www.w3.org/TR/SVG11/paths.html#PathDataMovetoCommands): > If a moveto is followed by multiple pairs of coordinates, the > subsequent pairs are treated as implicit lineto commands. Hence, > implicit lineto commands will be relative if the moveto is relative, > and absolute if the moveto is absolute." --- src/shapes/path.class.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/shapes/path.class.js b/src/shapes/path.class.js index 823a80e6..a0feb0de 100644 --- a/src/shapes/path.class.js +++ b/src/shapes/path.class.js @@ -18,6 +18,10 @@ q: 4, t: 2, a: 7 + }, + repeatedCommands = { + m: 'l', + M: 'L' }; if (fabric.Path) { @@ -586,12 +590,14 @@ } } - var command = coordsParsed[0].toLowerCase(), - commandLength = commandLengths[command]; + var command = coordsParsed[0], + commandLength = commandLengths[command.toLowerCase()], + repeatedCommand = repeatedCommands[command] || command; if (coordsParsed.length - 1 > commandLength) { for (var k = 1, klen = coordsParsed.length; k < klen; k += commandLength) { - result.push([ coordsParsed[0] ].concat(coordsParsed.slice(k, k + commandLength))); + result.push([ command ].concat(coordsParsed.slice(k, k + commandLength))); + command = repeatedCommand; } } else {