Introduce isRoot argument in SVGExport code as well, to make sure that top-most node holds all the style information.

Relates to #509
This commit is contained in:
Jürg Lehni 2014-08-16 17:32:24 +02:00
parent 4e9fc558ac
commit 15d79bbefb

View file

@ -278,9 +278,9 @@ new function() {
PointText: exportText PointText: exportText
}; };
function applyStyle(item, node) { function applyStyle(item, node, isRoot) {
var attrs = {}, var attrs = {},
parent = item.getParent(); parent = !isRoot && item.getParent();
if (item._name != null) if (item._name != null)
attrs.id = item._name; attrs.id = item._name;
@ -377,7 +377,7 @@ new function() {
: svg; : svg;
} }
function exportSVG(item, options) { function exportSVG(item, options, isRoot) {
var exporter = exporters[item._class], var exporter = exporters[item._class],
node = exporter && exporter(item, options); node = exporter && exporter(item, options);
if (node) { if (node) {
@ -390,7 +390,7 @@ new function() {
if (data && data !== '{}') if (data && data !== '{}')
node.setAttribute('data-paper-data', data); node.setAttribute('data-paper-data', data);
} }
return node && applyStyle(item, node); return node && applyStyle(item, node, isRoot);
} }
function setOptions(options) { function setOptions(options) {
@ -403,7 +403,7 @@ new function() {
Item.inject({ Item.inject({
exportSVG: function(options) { exportSVG: function(options) {
options = setOptions(options); options = setOptions(options);
return exportDefinitions(exportSVG(this, options), options); return exportDefinitions(exportSVG(this, options, true), options);
} }
}); });
@ -430,7 +430,7 @@ new function() {
parent = node.appendChild( parent = node.appendChild(
createElement('g', getTransform(matrix))); createElement('g', getTransform(matrix)));
for (var i = 0, l = layers.length; i < l; i++) for (var i = 0, l = layers.length; i < l; i++)
parent.appendChild(exportSVG(layers[i], options)); parent.appendChild(exportSVG(layers[i], options, true));
return exportDefinitions(node, options); return exportDefinitions(node, options);
} }
}); });