transformlist branch: collapse adjacent group scales to one translate-scale-translate
git-svn-id: http://svg-edit.googlecode.com/svn/branches/transformlist@918 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
29551a877a
commit
0d61f80f93
|
@ -1376,18 +1376,18 @@ function BatchCommand(text) {
|
|||
var origcenter = {x: (box.x+box.width/2), y: (box.y+box.height/2)};
|
||||
var newcenter = {x: origcenter.x, y: origcenter.y};
|
||||
var currentMatrix = {a:1, b:0, c:0, d:1, e:0, f:0};
|
||||
var tx = 0, ty = 0, sx = 1, sy = 1, r = 0.0;
|
||||
var tx = 0.0, ty = 0.0, sx = 1.0, sy = 1.0, r = 0.0;
|
||||
|
||||
// if it's a group, we have special reduction loops
|
||||
// if it's a group, we have special reduction loops to flatten transforms
|
||||
if (selected.tagName == "g") {
|
||||
// always remove translates by transferring them down to the children
|
||||
// otherwise just reduce adjacent scales
|
||||
|
||||
// The first pass is to remove all translates unless it is immediately
|
||||
// after or before a scale
|
||||
// The first pass is to flatten all translates into one
|
||||
var n = tlist.numberOfItems;
|
||||
while (n--) {
|
||||
var xform = tlist.getItem(n);
|
||||
// only flatten the translate if it is not before or after a scale
|
||||
if (xform.type != 2 || (n < (tlist.numberOfItems-1) && tlist.getItem(n+1).type == 3) ||
|
||||
(n > 0 && tlist.getItem(n-1).type == 3))
|
||||
{
|
||||
|
@ -1402,7 +1402,7 @@ function BatchCommand(text) {
|
|||
}
|
||||
// now restore just the one translate
|
||||
if (tx != 0 || ty != 0) {
|
||||
var newxlate = svgroot.createSVGTransform(0);
|
||||
var newxlate = svgroot.createSVGTransform();
|
||||
newxlate.setTranslate(tx,ty);
|
||||
tlist.insertItemBefore(newxlate, 0);
|
||||
}
|
||||
|
@ -1410,15 +1410,48 @@ function BatchCommand(text) {
|
|||
// TODO: The second pass is to find all adjacent transform sets of the form:
|
||||
// translate(tx,ty) scale(sx,sy) translate(-tx,-ty) and reduce them
|
||||
// to one set (multiply sx and sy)
|
||||
tx = 0;
|
||||
ty = 0;
|
||||
var bGotOffset = false;
|
||||
n = tlist.numberOfItems;
|
||||
while (n--) {
|
||||
var xform = tlist.getItem(n);
|
||||
if (!xform || xform.type != 3) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return batchCmd;
|
||||
var sobj = transformToObj(xform);
|
||||
sx *= sobj.sx;
|
||||
sy *= sobj.sy;
|
||||
console.log([sx,sy]);
|
||||
if (!bGotOffset) {
|
||||
var tobj = transformToObj(tlist.getItem(n-1));
|
||||
tx = tobj.tx;
|
||||
ty = tobj.ty;
|
||||
bGotOffset = true;
|
||||
}
|
||||
// remove the scale and translates from the group
|
||||
tlist.removeItem(n+1);
|
||||
tlist.removeItem(n);
|
||||
tlist.removeItem(n-1);
|
||||
n--;
|
||||
}
|
||||
// now restore just the one scale and its offset translates
|
||||
console.log('final scales: ' + sx + ',' + sy);
|
||||
if (sx != 1 || sy != 1) {
|
||||
var newscale = svgroot.createSVGTransform(),
|
||||
offset_p = svgroot.createSVGTransform(),
|
||||
offset_n = svgroot.createSVGTransform();
|
||||
offset_n.setTranslate(-tx,-ty);
|
||||
offset_p.setTranslate(tx,ty);
|
||||
newscale.setScale(sx,sy);
|
||||
tlist.appendItem(offset_p);
|
||||
tlist.appendItem(newscale);
|
||||
tlist.appendItem(offset_n);
|
||||
}
|
||||
}
|
||||
|
||||
// else, it's a non-group
|
||||
|
||||
else {
|
||||
// This pass loop in reverse order and removes any translates or scales.
|
||||
// Once we hit our first rotate(), we will only remove translates.
|
||||
var bRemoveTransform = true;
|
||||
|
@ -1588,6 +1621,7 @@ function BatchCommand(text) {
|
|||
}
|
||||
}
|
||||
} // looping for each transform
|
||||
} // a non-group
|
||||
|
||||
// now we have a set of changes and an applied reduced transform list
|
||||
// we apply the changes directly to the DOM
|
||||
|
@ -1661,7 +1695,6 @@ function BatchCommand(text) {
|
|||
|
||||
// remove any stray identity transforms
|
||||
if (tlist && tlist.numberOfItems > 0) {
|
||||
var removeItems = [];
|
||||
var k = tlist.numberOfItems;
|
||||
while (k--) {
|
||||
var xform = tlist.getItem(k);
|
||||
|
@ -3492,9 +3525,10 @@ function BatchCommand(text) {
|
|||
|
||||
selectorManager.requestSelector(selected).showGrips(true);
|
||||
}
|
||||
// always recalculate dimensions to strip off stray identity transforms
|
||||
recalculateAllSelectedDimensions();
|
||||
// if it was being dragged/resized
|
||||
if (x != start_x || y != start_y) {
|
||||
recalculateAllSelectedDimensions();
|
||||
var len = selectedElements.length;
|
||||
for (var i = 0; i < len; ++i) {
|
||||
if (selectedElements[i] == null) break;
|
||||
|
|
Loading…
Reference in New Issue