Define Group#transformContent as a boolean to control #applyMatrix() behavior.

And use it for SVG Import.
This commit is contained in:
Jürg Lehni 2013-06-18 15:57:30 -07:00
parent f758fb306b
commit 177229f99f
2 changed files with 28 additions and 7 deletions

View file

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

View file

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