From 4c66ccbabe3bc6a79a4fcb13bc503ef77740d9b2 Mon Sep 17 00:00:00 2001 From: Alexis Deveria Date: Fri, 4 Dec 2009 17:53:05 +0000 Subject: [PATCH] Made un-rotated child elements properly resize when resizing non-rotated groups git-svn-id: http://svg-edit.googlecode.com/svn/branches/fixtransforms@997 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svgcanvas.js | 62 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 66fb76e9..a660eba3 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -1437,15 +1437,50 @@ function BatchCommand(text) { tx = m.e; ty = m.f; tlist.removeItem(0); - } + } // if we have a translate/scale/translate transform, push down to children + else if(tlist.numberOfItems >= 3 && tlist.getItem(1).type == 3) { + var trans_m = tlist.getItem(0).matrix; + var scale_m = tlist.getItem(1).matrix; - // if we have any other transforms, collapse them all down to a matrix - var m = transformListToTransform(tlist).matrix; - if (tlist.numberOfItems > 0) { - var newxform = svgroot.createSVGTransform(); - newxform.setMatrix(m); - tlist.clear(); - tlist.appendItem(newxform); + var children = selected.childNodes; + var c = children.length; + while (c--) { + var child = children.item(c); + if (child.nodeType == 1) { + + var angle = canvas.getRotationAngle(child); + if(angle) { + // TODO: Deal with rotated childen... + } + + // update the transform list with translate,scale,translate + var childTlist = canvas.getTransformList(child); + var translateOrigin = svgroot.createSVGTransform(), + scale = svgroot.createSVGTransform(), + translateBack = svgroot.createSVGTransform(); + translateOrigin.setTranslate(trans_m.e*-1, trans_m.f*-1); + scale.setScale(scale_m.a, scale_m.d); + translateBack.setTranslate(trans_m.e, trans_m.f); + childTlist.appendItem(translateBack); + childTlist.appendItem(scale); + childTlist.appendItem(translateOrigin); + batchCmd.addSubCommand( recalculateDimensions(child) ); + } + } + // Remove these transforms from group + var N = tlist.numberOfItems; + tlist.removeItem(N-1); + tlist.removeItem(N-2); + tlist.removeItem(N-3); + } // if we have any other transforms, collapse them all down to a matrix + else if(tlist.numberOfItems > 0) { + var m = transformListToTransform(tlist).matrix; + if (tlist.numberOfItems > 0) { + var newxform = svgroot.createSVGTransform(); + newxform.setMatrix(m); + tlist.clear(); + tlist.appendItem(newxform); + } } if (tx != 0 || ty != 0) { @@ -1954,6 +1989,17 @@ function BatchCommand(text) { } return svgroot.createSVGTransformFromMatrix(m); }; + +// // Easy way to loop through transform list, but may not be worthwhile +// var eachXform = function(elem, callback) { +// var tlist = canvas.getTransformList(elem); +// var num = tlist.numberOfItems; +// if(num == 0) return; +// while(num--) { +// var xform = tlist.getItem(num); +// callback(xform, tlist); +// } +// } // FIXME: this should not have anything to do with zoom here - update the one place it is used this way // converts a tiny object equivalent of a SVGTransform