From 177229f99f407a3c35320f3e5b29783136928cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 18 Jun 2013 15:57:30 -0700 Subject: [PATCH] Define Group#transformContent as a boolean to control #applyMatrix() behavior. And use it for SVG Import. --- src/item/Group.js | 18 ++++++++++++++++++ src/svg/SVGImport.js | 17 ++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/item/Group.js b/src/item/Group.js index d0fafac6..71d0a3de 100644 --- a/src/item/Group.js +++ b/src/item/Group.js @@ -124,6 +124,24 @@ var Group = Item.extend(/** @lends Group# */{ return this._clipItem = null; }, + /** + * Specifies whether the group applies transformations directly to its + * children, or wether they are to be stored in its {@link Item#matrix} + * + * @type Boolean + * @default true + * @bean + */ + getTransformContent: function() { + return this._transformContent; + }, + + setTransformContent: function(transform) { + this._transformContent = transform; + if (transform) + this.applyMatrix(); + }, + /** * Specifies whether the group item is to be clipped. * When setting to {@code true}, the first child in the group is diff --git a/src/svg/SVGImport.js b/src/svg/SVGImport.js index 78f02402..1132d3c2 100644 --- a/src/svg/SVGImport.js +++ b/src/svg/SVGImport.js @@ -71,19 +71,22 @@ new function() { function importGroup(node, type) { var nodes = node.childNodes, clip = type === 'clippath', - item = clip ? new CompoundPath() : new Clip(), + item = clip ? new CompoundPath() : new Group(), project = item._project, currentStyle = project._currentStyle, children = []; - // 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 - // currentStyle, so it is used as a default for the creation of all - // nested items. importSVG then needs to check for items and avoid - // calling applyAttributes() again. // Set the default color to black, since that's how SVG handles fills. item.setFillColor('black'); if (!clip) { + // Have the group not pass on all transformations to its children, + // as this is how SVG works too. + item._transformContent = false; item = applyAttributes(item, node); + // 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 currentStyle, so it is used as a default for the + // creation of all nested items. importSVG then needs to check for + // items and avoid calling applyAttributes() again. project._currentStyle = item._style.clone(); } // Collect the children in an array and apply them all at once. @@ -93,7 +96,7 @@ new function() { if (childNode.nodeType == 1 && (child = importSVG(childNode))) { // If adding CompoundPaths to other CompoundPaths, // we need to "unbox" them first: - if (clip && child._type === 'compound-path') { + if (clip && child instanceof CompoundPath) { children.push.apply(children, child.removeChildren()); child.remove(); } else if (!(child instanceof Symbol)) {