mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Fix issues with importing full SVG documents where default styles would not be detected.
This commit is contained in:
parent
1301aea47d
commit
893f8fb2cc
1 changed files with 25 additions and 13 deletions
|
@ -74,12 +74,11 @@ new function() {
|
|||
function importGroup(node, type, isRoot, options) {
|
||||
var nodes = node.childNodes,
|
||||
isClip = type === 'clippath',
|
||||
isDocument = type === '#document',
|
||||
item = new Group(),
|
||||
project = item._project,
|
||||
currentStyle = project._currentStyle,
|
||||
children = [];
|
||||
if (!isClip && !isDocument) {
|
||||
if (!isClip) {
|
||||
// Have the group not pass on all transformations to its children,
|
||||
// as this is how SVG works too.
|
||||
item._transformContent = false;
|
||||
|
@ -103,16 +102,10 @@ new function() {
|
|||
item.addChildren(children);
|
||||
// Clip paths are reduced (unboxed) and their attributes applied at the
|
||||
// end.
|
||||
if (isClip || isDocument) {
|
||||
// If a document or a clip item only contain one child, remove the
|
||||
// group.
|
||||
item = item.reduce();
|
||||
if (isClip)
|
||||
item = applyAttributes(item, node, isRoot);
|
||||
} else {
|
||||
// Restore currentStyle
|
||||
project._currentStyle = currentStyle;
|
||||
}
|
||||
if (isClip)
|
||||
item = applyAttributes(item.reduce(), node, isRoot);
|
||||
// Restore currentStyle
|
||||
project._currentStyle = currentStyle;
|
||||
if (isClip || type === 'defs') {
|
||||
// We don't want the defs in the DOM. But we might want to use
|
||||
// Symbols for them to save memory?
|
||||
|
@ -173,7 +166,26 @@ new function() {
|
|||
// NOTE: All importers are lowercase, since jsdom is using uppercase
|
||||
// nodeNames still.
|
||||
var importers = {
|
||||
'#document': importGroup,
|
||||
'#document': function (node, type, isRoot, options) {
|
||||
var nodes = node.childNodes;
|
||||
for (var i = 0, l = nodes.length; i < l; i++) {
|
||||
var child = nodes[i];
|
||||
if (child.nodeType === 1) {
|
||||
// NOTE: We need to move the svg node into our current
|
||||
// document, so default styles apply!
|
||||
var next = child.nextSibling;
|
||||
document.body.appendChild(child);
|
||||
var item = importSVG(child, isRoot, options);
|
||||
// After import, we move it back to where it was:
|
||||
if (next) {
|
||||
node.insertBefore(child, next);
|
||||
} else {
|
||||
node.appendChild(child);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
},
|
||||
// http://www.w3.org/TR/SVG/struct.html#Groups
|
||||
g: importGroup,
|
||||
// http://www.w3.org/TR/SVG/struct.html#NewDocument
|
||||
|
|
Loading…
Reference in a new issue