Define #_type property for both Symbol and Gradient and use it in SvgExport.

This commit is contained in:
Jürg Lehni 2013-02-11 18:23:41 -08:00
parent 224563d5f7
commit 629e16144a
3 changed files with 9 additions and 4 deletions

View file

@ -16,6 +16,8 @@
* @class The Gradient object. * @class The Gradient object.
*/ */
var Gradient = this.Gradient = Base.extend(/** @lends Gradient# */{ var Gradient = this.Gradient = Base.extend(/** @lends Gradient# */{
_type: 'gradient',
// TODO: Should type here be called 'radial' and have it receive a // TODO: Should type here be called 'radial' and have it receive a
// boolean value? // boolean value?
/** /**

View file

@ -20,6 +20,8 @@
* to be updated with every transformation. * to be updated with every transformation.
*/ */
var Symbol = this.Symbol = Base.extend(/** @lends Symbol# */{ var Symbol = this.Symbol = Base.extend(/** @lends Symbol# */{
_type: 'symbol',
/** /**
* Creates a Symbol item. * Creates a Symbol item.
* *

View file

@ -364,7 +364,7 @@ new function() {
viewBox: formatRectangle(bounds) viewBox: formatRectangle(bounds)
}); });
symbolNode.appendChild(exportSvg(definition)); symbolNode.appendChild(exportSvg(definition));
setDefinition(symbol, symbolNode, 'symbol'); setDefinition(symbol, symbolNode);
} }
attrs.href = '#' + symbolNode.id; attrs.href = '#' + symbolNode.id;
attrs.x += bounds.x; attrs.x += bounds.x;
@ -421,7 +421,7 @@ new function() {
attrs['stop-opacity'] = color._alpha; attrs['stop-opacity'] = color._alpha;
gradientNode.appendChild(createElement('stop', attrs)); gradientNode.appendChild(createElement('stop', attrs));
} }
setDefinition(gradient, gradientNode, 'gradient'); setDefinition(gradient, gradientNode);
} }
return 'url(#' + gradientNode.id + ')'; return 'url(#' + gradientNode.id + ')';
} }
@ -485,8 +485,9 @@ new function() {
return definitions.svgs[item._id]; return definitions.svgs[item._id];
} }
function setDefinition(item, node, type) { function setDefinition(item, node) {
var id = definitions.ids[type] = (definitions.ids[type] || 0) + 1; var type = item._type,
id = definitions.ids[type] = (definitions.ids[type] || 0) + 1;
node.id = type + '-' + id; node.id = type + '-' + id;
definitions.svgs[item._id] = node; definitions.svgs[item._id] = node;
} }