mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-10 23:03:10 +00:00
Add option to suppress XML preamble in toSVG method.
This commit is contained in:
parent
18e6e4f353
commit
48ab4607b9
3 changed files with 40 additions and 13 deletions
21
dist/all.js
vendored
21
dist/all.js
vendored
|
|
@ -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 "<svg...")
|
||||
* @return {String}
|
||||
*/
|
||||
toSVG: function() {
|
||||
var markup = [
|
||||
'<?xml version="1.0" standalone="no" ?>',
|
||||
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" ',
|
||||
'"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">',
|
||||
toSVG: function(options) {
|
||||
options || (options = { });
|
||||
var markup = [];
|
||||
|
||||
if (!options.suppressPreamble) {
|
||||
markup.push(
|
||||
'<?xml version="1.0" standalone="no" ?>',
|
||||
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" ',
|
||||
'"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">'
|
||||
);
|
||||
}
|
||||
markup.push(
|
||||
'<svg ',
|
||||
'xmlns="http://www.w3.org/2000/svg" ',
|
||||
'xmlns:xlink="http://www.w3.org/1999/xlink" ',
|
||||
|
|
@ -6494,7 +6503,7 @@ fabric.Shadow = fabric.util.createClass(/** @scope fabric.Shadow.prototype */ {
|
|||
'xml:space="preserve">',
|
||||
'<desc>Created with Fabric.js ', fabric.version, '</desc>',
|
||||
fabric.createSVGFontFacesMarkup(this.getObjects())
|
||||
];
|
||||
);
|
||||
|
||||
if (this.backgroundImage) {
|
||||
markup.push(
|
||||
|
|
|
|||
|
|
@ -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 "<svg...")
|
||||
* @return {String}
|
||||
*/
|
||||
toSVG: function() {
|
||||
var markup = [
|
||||
'<?xml version="1.0" standalone="no" ?>',
|
||||
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" ',
|
||||
'"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">',
|
||||
toSVG: function(options) {
|
||||
options || (options = { });
|
||||
var markup = [];
|
||||
|
||||
if (!options.suppressPreamble) {
|
||||
markup.push(
|
||||
'<?xml version="1.0" standalone="no" ?>',
|
||||
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" ',
|
||||
'"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">'
|
||||
);
|
||||
}
|
||||
markup.push(
|
||||
'<svg ',
|
||||
'xmlns="http://www.w3.org/2000/svg" ',
|
||||
'xmlns:xlink="http://www.w3.org/1999/xlink" ',
|
||||
|
|
@ -945,7 +954,7 @@
|
|||
'xml:space="preserve">',
|
||||
'<desc>Created with Fabric.js ', fabric.version, '</desc>',
|
||||
fabric.createSVGFontFacesMarkup(this.getObjects())
|
||||
];
|
||||
);
|
||||
|
||||
if (this.backgroundImage) {
|
||||
markup.push(
|
||||
|
|
|
|||
|
|
@ -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), '<svg', 'svg should start with root node when premable is suppressed');
|
||||
});
|
||||
|
||||
|
||||
test('toJSON', function() {
|
||||
ok(typeof canvas.toJSON == 'function');
|
||||
equal(JSON.stringify(canvas.toJSON()), '{"objects":[],"background":""}');
|
||||
|
|
@ -682,4 +691,4 @@
|
|||
});
|
||||
});
|
||||
|
||||
})();
|
||||
})();
|
||||
|
|
|
|||
Loading…
Reference in a new issue