diff --git a/src/mixins/itext.svg_export.js b/src/mixins/itext.svg_export.js index 5be8ec34586..5d8f7a63c25 100644 --- a/src/mixins/itext.svg_export.js +++ b/src/mixins/itext.svg_export.js @@ -10,12 +10,22 @@ * @param {Function} [reviver] Method for further parsing of svg representation. * @return {String} svg representation of an instance */ - toSVG: function(reviver) { + _toSVG: function() { var offsets = this._getSVGLeftTopOffsets(), - textAndBg = this._getSVGTextAndBg(offsets.textTop, offsets.textLeft), - internalMarkup = this._wrapSVGTextAndBg(textAndBg); + textAndBg = this._getSVGTextAndBg(offsets.textTop, offsets.textLeft); + return this._wrapSVGTextAndBg(textAndBg); + }, + + /** + * Returns svg representation of an instance + * @param {Function} [reviver] Method for further parsing of svg representation. + * @return {String} svg representation of an instance + */ + toSVG: function(reviver) { return this._createBaseSVGMarkup( - internalMarkup, { reviver: reviver, noStyle: true, withShadow: true }); + this._toSVG(), + { reviver: reviver, noStyle: true, withShadow: true } + ); }, /** diff --git a/src/shapes/group.class.js b/src/shapes/group.class.js index 4d91dbb6acf..5eae245d77f 100644 --- a/src/shapes/group.class.js +++ b/src/shapes/group.class.js @@ -526,10 +526,25 @@ } return this._createBaseSVGMarkup( - svgString, + this._toSVG(), { reviver: reviver, noStyle: true, withShadow: true }); }, + /** + * Returns svg representation of an instance + * @param {Function} [reviver] Method for further parsing of svg representation. + * @return {String} svg representation of an instance + */ + _toSVG: function(reviver) { + var svgString = []; + + for (var i = 0, len = this._objects.length; i < len; i++) { + svgString.push('\t', this._objects[i].toSVG(reviver)); + } + + return svgString; + }, + /** * Returns svg clipPath representation of an instance * @param {Function} [reviver] Method for further parsing of svg representation. diff --git a/test/unit/text_to_svg.js b/test/unit/text_to_svg.js index 2ca9a269ef4..4f4300f48ef 100644 --- a/test/unit/text_to_svg.js +++ b/test/unit/text_to_svg.js @@ -53,7 +53,16 @@ 5: {fontFamily: 'Times New Roman'} }} }); - assert.equal(removeTranslate(text.toSVG()), removeTranslate(TEXT_SVG_WITH_FONT)); }); + QUnit.test('toSVG with text as a clipPath', function(assert) { + fabric.Object.NUM_FRACTION_DIGITS = 0; + fabric.Object.__uid = 0; + var EXPECTED = '\n\n\t\t\ttext as clipPath\n\n\n\n'; + var clipPath = new fabric.Text('text as clipPath'); + var rect = new fabric.Rect({ width: 200, height: 100 }); + rect.clipPath = clipPath; + assert.equal(removeTranslate(rect.toSVG()), removeTranslate(EXPECTED)); + fabric.Object.NUM_FRACTION_DIGITS = 2; + }); })();