Fix issues with importing full SVG documents where default styles would not be detected.

This commit is contained in:
Jürg Lehni 2013-11-03 13:20:51 +01:00
parent 1301aea47d
commit 893f8fb2cc

View file

@ -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