Fix issues with SVG Import and matrices on groups.

This commit is contained in:
Jürg Lehni 2013-06-18 15:46:49 -07:00
parent f433423789
commit 691b2f8094
2 changed files with 9 additions and 6 deletions

View file

@ -14,7 +14,7 @@
<g transform="scale(5) translate(15, 15) rotate(20) skewX(20) skewY(5)" > <g transform="scale(5) translate(15, 15) rotate(20) skewX(20) skewY(5)" >
<rect x="10" y="10" width="5" height="5" fill="firebrick" /> <rect x="10" y="10" width="5" height="5" fill="firebrick" />
<circle r="10" fill="seagreen" stroke="blue"/> <circle r="10" fill="seagreen" stroke="blue"/>
<rect x="5" y="5" width="12" height="2" fill="gray" stroke="silver"/> <rect x="5" y="5" width="12" height="2" fill="grey" stroke="silver"/>
</g> </g>
</svg> </svg>
<canvas id="canvas" width="500" height="500"></canvas> <canvas id="canvas" width="500" height="500"></canvas>

View file

@ -71,9 +71,10 @@ new function() {
function importGroup(node, type) { function importGroup(node, type) {
var nodes = node.childNodes, var nodes = node.childNodes,
clip = type === 'clippath', clip = type === 'clippath',
item = clip ? new CompoundPath() : new Group(), item = clip ? new CompoundPath() : new Clip(),
project = item._project, project = item._project,
currentStyle = project._currentStyle; currentStyle = project._currentStyle,
children = [];
// Style on items needs to be handled differently than all other items: // Style on items needs to be handled differently than all other items:
// We first apply the style to the item, then use it as the project's // We first apply the style to the item, then use it as the project's
// currentStyle, so it is used as a default for the creation of all // currentStyle, so it is used as a default for the creation of all
@ -85,6 +86,7 @@ new function() {
item = applyAttributes(item, node); item = applyAttributes(item, node);
project._currentStyle = item._style.clone(); project._currentStyle = item._style.clone();
} }
// Collect the children in an array and apply them all at once.
for (var i = 0, l = nodes.length; i < l; i++) { for (var i = 0, l = nodes.length; i < l; i++) {
var childNode = nodes[i], var childNode = nodes[i],
child; child;
@ -92,13 +94,14 @@ new function() {
// If adding CompoundPaths to other CompoundPaths, // If adding CompoundPaths to other CompoundPaths,
// we need to "unbox" them first: // we need to "unbox" them first:
if (clip && child._type === 'compound-path') { if (clip && child._type === 'compound-path') {
item.addChildren(child.removeChildren()); children.push.apply(children, child.removeChildren());
child.remove(); child.remove();
} else if (!(child instanceof Symbol)) { } else if (!(child instanceof Symbol)) {
item.addChild(child); children.push(child);
} }
} }
} }
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 (clip) if (clip)
@ -502,7 +505,7 @@ new function() {
item = importer && importer(node, type), item = importer && importer(node, type),
data = node.getAttribute('data-paper-data'); data = node.getAttribute('data-paper-data');
// See importGroup() for an explanation of this filtering: // See importGroup() for an explanation of this filtering:
if (item && item._type !== 'group') if (item && !(item instanceof Group))
item = applyAttributes(item, node); item = applyAttributes(item, node);
if (item && data) if (item && data)
item._data = JSON.parse(data); item._data = JSON.parse(data);