mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -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) {
|
function importGroup(node, type, isRoot, options) {
|
||||||
var nodes = node.childNodes,
|
var nodes = node.childNodes,
|
||||||
isClip = type === 'clippath',
|
isClip = type === 'clippath',
|
||||||
isDocument = type === '#document',
|
|
||||||
item = new Group(),
|
item = new Group(),
|
||||||
project = item._project,
|
project = item._project,
|
||||||
currentStyle = project._currentStyle,
|
currentStyle = project._currentStyle,
|
||||||
children = [];
|
children = [];
|
||||||
if (!isClip && !isDocument) {
|
if (!isClip) {
|
||||||
// Have the group not pass on all transformations to its children,
|
// Have the group not pass on all transformations to its children,
|
||||||
// as this is how SVG works too.
|
// as this is how SVG works too.
|
||||||
item._transformContent = false;
|
item._transformContent = false;
|
||||||
|
@ -103,16 +102,10 @@ new function() {
|
||||||
item.addChildren(children);
|
item.addChildren(children);
|
||||||
// Clip paths are reduced (unboxed) and their attributes applied at the
|
// Clip paths are reduced (unboxed) and their attributes applied at the
|
||||||
// end.
|
// end.
|
||||||
if (isClip || isDocument) {
|
if (isClip)
|
||||||
// If a document or a clip item only contain one child, remove the
|
item = applyAttributes(item.reduce(), node, isRoot);
|
||||||
// group.
|
// Restore currentStyle
|
||||||
item = item.reduce();
|
project._currentStyle = currentStyle;
|
||||||
if (isClip)
|
|
||||||
item = applyAttributes(item, node, isRoot);
|
|
||||||
} else {
|
|
||||||
// Restore currentStyle
|
|
||||||
project._currentStyle = currentStyle;
|
|
||||||
}
|
|
||||||
if (isClip || type === 'defs') {
|
if (isClip || type === 'defs') {
|
||||||
// We don't want the defs in the DOM. But we might want to use
|
// We don't want the defs in the DOM. But we might want to use
|
||||||
// Symbols for them to save memory?
|
// Symbols for them to save memory?
|
||||||
|
@ -173,7 +166,26 @@ new function() {
|
||||||
// NOTE: All importers are lowercase, since jsdom is using uppercase
|
// NOTE: All importers are lowercase, since jsdom is using uppercase
|
||||||
// nodeNames still.
|
// nodeNames still.
|
||||||
var importers = {
|
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
|
// http://www.w3.org/TR/SVG/struct.html#Groups
|
||||||
g: importGroup,
|
g: importGroup,
|
||||||
// http://www.w3.org/TR/SVG/struct.html#NewDocument
|
// http://www.w3.org/TR/SVG/struct.html#NewDocument
|
||||||
|
|
Loading…
Reference in a new issue