Implement clipPath support in SVGExporter.

This commit is contained in:
Jürg Lehni 2013-06-11 14:50:13 -07:00
parent 35f17979df
commit 875a766d19

View file

@ -168,9 +168,20 @@ new function() {
children = item._children; children = item._children;
var node = createElement('g', attrs); var node = createElement('g', attrs);
for (var i = 0, l = children.length; i < l; i++) { for (var i = 0, l = children.length; i < l; i++) {
var child = exportSVG(children[i]); var child = children[i];
if (child) var childNode = exportSVG(child);
node.appendChild(child); if (childNode) {
if (child.isClipMask()) {
var clip = createElement('clipPath');
clip.appendChild(childNode);
setDefinition(child, clip, 'clip');
setAttributes(node, {
'clip-path': 'url(#' + clip.id + ')'
});
} else {
node.appendChild(childNode);
}
}
} }
return node; return node;
} }
@ -444,13 +455,15 @@ new function() {
function getDefinition(item) { function getDefinition(item) {
if (!definitions) if (!definitions)
definitions = { ids: {}, svgs: {} }; definitions = { ids: {}, svgs: {} };
return definitions.svgs[item._id]; return item && definitions.svgs[item._id];
} }
function setDefinition(item, node) { function setDefinition(item, node, type) {
if (!definitions)
getDefinition();
// Have different id ranges per type // Have different id ranges per type
var type = item._type, type = type || item._type;
id = definitions.ids[type] = (definitions.ids[type] || 0) + 1; var id = definitions.ids[type] = (definitions.ids[type] || 0) + 1;
// Give the svg node an ide, and link to it from the item id. // Give the svg node an ide, and link to it from the item id.
node.id = type + '-' + id; node.id = type + '-' + id;
definitions.svgs[item._id] = node; definitions.svgs[item._id] = node;