From 48ab4607b957d737575d2b14543fadc0bba3c285 Mon Sep 17 00:00:00 2001 From: Arthaey Date: Tue, 5 Feb 2013 22:20:56 -0800 Subject: [PATCH] Add option to suppress XML preamble in toSVG method. --- dist/all.js | 21 +++++++++++++++------ src/static_canvas.class.js | 21 +++++++++++++++------ test/unit/canvas_static.js | 11 ++++++++++- 3 files changed, 40 insertions(+), 13 deletions(-) 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), '