Skip to content
This repository was archived by the owner on Jul 24, 2022. It is now read-only.

Commit 969d0da

Browse files
jeromewkaosat-dev
authored andcommitted
fix(svg-deserializer): m/M commands can have implicit lineTo (#20)
1 parent 6e37a1a commit 969d0da

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

packages/svg-deserializer/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,12 @@ sax.SAXParser.prototype.codify = function (group) {
947947
code += indent + 'var ' + pn + ' = new CSG.Path2D([[' + this.svg2cagX(cx) + ',' + this.svg2cagY(cy) + ']],false);\n'
948948
sx = cx; sy = cy
949949
}
950-
break
950+
// optional implicit relative lineTo (cf SVG spec 8.3.2)
951+
while (pts.length >= 2) {
952+
cx = cx + parseFloat(pts.shift())
953+
cy = cy + parseFloat(pts.shift())
954+
code += indent + pn + ' = ' + pn + '.appendPoint([' + this.svg2cagX(cx) + ',' + this.svg2cagY(cy) + ']);\n'
955+
}
951956
break
952957
case 'M': // absolute move to X,Y
953958
// close the previous path
@@ -964,6 +969,12 @@ sax.SAXParser.prototype.codify = function (group) {
964969
code += indent + 'var ' + pn + ' = new CSG.Path2D([[' + this.svg2cagX(cx) + ',' + this.svg2cagY(cy) + ']],false);\n'
965970
sx = cx; sy = cy
966971
}
972+
// optional implicit absolute lineTo (cf SVG spec 8.3.2)
973+
while (pts.length >= 2) {
974+
cx = parseFloat(pts.shift())
975+
cy = parseFloat(pts.shift())
976+
code += indent + pn + ' = ' + pn + '.appendPoint([' + this.svg2cagX(cx) + ',' + this.svg2cagY(cy) + ']);\n'
977+
}
967978
break
968979
case 'a': // relative elliptical arc
969980
while (pts.length >= 7) {

0 commit comments

Comments
 (0)