diff --git a/src/mixins/object.svg_export.js b/src/mixins/object.svg_export.js index 3689021b..bfea0eb0 100644 --- a/src/mixins/object.svg_export.js +++ b/src/mixins/object.svg_export.js @@ -63,6 +63,14 @@ return this.shadow ? 'filter: url(#SVGID_' + this.shadow.id + ');' : ''; }, + /** + * Returns id attribute for svg output + * @return {String} + */ + getSvgId: function() { + return this.id ? 'id="' + this.id + '" ' : ''; + }, + /** * Returns transform-string for svg-export * @return {String} diff --git a/src/shapes/circle.class.js b/src/shapes/circle.class.js index e3b386b3..3363cc03 100644 --- a/src/shapes/circle.class.js +++ b/src/shapes/circle.class.js @@ -107,7 +107,7 @@ y = this.top + this.radius; } markup.push( - '\n', - '\n' diff --git a/src/shapes/polygon.class.js b/src/shapes/polygon.class.js index 518d043e..a1a001bd 100644 --- a/src/shapes/polygon.class.js +++ b/src/shapes/polygon.class.js @@ -118,7 +118,7 @@ addTransform = ' translate(' + (-this.pathOffset.x) + ', ' + (-this.pathOffset.y) + ') '; } markup.push( - '<', this.type, ' ', + '<', this.type, ' ', this.getSvgId(), 'points="', points.join(''), '" style="', this.getSvgStyles(), '" transform="', this.getSvgTransform(), addTransform, diff --git a/src/shapes/rect.class.js b/src/shapes/rect.class.js index 92b7a6f1..d6efd282 100644 --- a/src/shapes/rect.class.js +++ b/src/shapes/rect.class.js @@ -172,7 +172,7 @@ y = -this.height / 2; } markup.push( - '\n', textAndBg.textBgRects.join(''), '\t\t\n'); }); + test('toSVG with id', function() { + var rect = new fabric.Rect({id: 'myRect', width: 100, height: 100, strokeWidth: 0, fill: 'rgba(255, 0, 0, 0.5)' }); + var svg = rect.toSVG(); + equal(svg, '\n'); + }); + test('toSVG with alpha colors stroke', function() { var rect = new fabric.Rect({ width: 100, height: 100, strokeWidth: 0, fill: '', stroke: 'rgba(255, 0, 0, 0.5)' }); var svg = rect.toSVG();