diff --git a/dist/all.js b/dist/all.js index 2695382d..15637014 100644 --- a/dist/all.js +++ b/dist/all.js @@ -6478,13 +6478,22 @@ fabric.Shadow = fabric.util.createClass(/** @scope fabric.Shadow.prototype */ { * Returns SVG representation of canvas * @function * @method toSVG + * @param {Object} [options] Options for SVG output ("suppressPreamble: true" + * will start the svg output directly at "', - '', + toSVG: function(options) { + options || (options = { }); + var markup = []; + + if (!options.suppressPreamble) { + markup.push( + '', + '' + ); + } + markup.push( '', 'Created with Fabric.js ', fabric.version, '', fabric.createSVGFontFacesMarkup(this.getObjects()) - ]; + ); if (this.backgroundImage) { markup.push( diff --git a/src/static_canvas.class.js b/src/static_canvas.class.js index a1e9ccfc..e43acd3e 100644 --- a/src/static_canvas.class.js +++ b/src/static_canvas.class.js @@ -929,13 +929,22 @@ * Returns SVG representation of canvas * @function * @method toSVG + * @param {Object} [options] Options for SVG output ("suppressPreamble: true" + * will start the svg output directly at "', - '', + toSVG: function(options) { + options || (options = { }); + var markup = []; + + if (!options.suppressPreamble) { + markup.push( + '', + '' + ); + } + markup.push( '', 'Created with Fabric.js ', fabric.version, '', fabric.createSVGFontFacesMarkup(this.getObjects()) - ]; + ); if (this.backgroundImage) { markup.push( diff --git a/test/unit/canvas_static.js b/test/unit/canvas_static.js index 3c190825..1c6611d4 100644 --- a/test/unit/canvas_static.js +++ b/test/unit/canvas_static.js @@ -193,6 +193,15 @@ equal(rect.getAngle(), 90, 'angle should be coerced to 90 (from 100)'); }); + test('toSVG without preamble', function() { + ok(typeof canvas.toSVG == 'function'); + var withPreamble = canvas.toSVG(); + var withoutPreamble = canvas.toSVG({suppressPreamble: true}); + ok(withPreamble != withoutPreamble); + equal(withoutPreamble.slice(0, 4), '