mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -05:00
Implement clipPath support in SVGExporter.
This commit is contained in:
parent
35f17979df
commit
875a766d19
1 changed files with 20 additions and 7 deletions
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue