Fix rest of Issue 471: upon loading/setting the SVG, do a depth-first recalculateDimensions() on all nodes

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1380 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Jeff Schiller 2010-02-12 03:54:49 +00:00
parent 9915407382
commit 8d4861d546
1 changed files with 53 additions and 36 deletions

View File

@ -1369,7 +1369,7 @@ function BatchCommand(text) {
}
}
});
// recurse to children
i = node.childNodes.length;
while (i--) { sanitizeSvg(node.childNodes.item(i)); }
@ -1923,7 +1923,7 @@ function BatchCommand(text) {
}
// if this element had no transforms, we are done
if (tlist.numberOfItems == 0) {
if (!tlist || tlist.numberOfItems == 0) {
selected.removeAttribute("transform");
return null;
}
@ -2001,25 +2001,27 @@ function BatchCommand(text) {
m = svgroot.createSVGMatrix();
// temporarily strip off the rotate and save the old center
var a = gangle * Math.PI / 180;
if ( Math.abs(a) > (1.0e-10) ) {
var s = Math.sin(a)/(1 - Math.cos(a));
} else {
// FIXME: This blows up if the angle is exactly 0!
var s = 2/a;
}
for (var i = 0; i < tlist.numberOfItems; ++i) {
var xform = tlist.getItem(i);
if (xform.type == 4) {
// extract old center through mystical arts
var rm = xform.matrix;
oldcenter.y = (s*rm.e + rm.f)/2;
oldcenter.x = (rm.e - s*rm.f)/2;
tlist.removeItem(i);
break;
var gangle = canvas.getRotationAngle(selected);
if (gangle) {
var a = gangle * Math.PI / 180;
if ( Math.abs(a) > (1.0e-10) ) {
var s = Math.sin(a)/(1 - Math.cos(a));
} else {
// FIXME: This blows up if the angle is exactly 0!
var s = 2/a;
}
for (var i = 0; i < tlist.numberOfItems; ++i) {
var xform = tlist.getItem(i);
if (xform.type == 4) {
// extract old center through mystical arts
var rm = xform.matrix;
oldcenter.y = (s*rm.e + rm.f)/2;
oldcenter.x = (rm.e - s*rm.f)/2;
tlist.removeItem(i);
break;
}
}
}
var tx = 0, ty = 0,
operation = 0,
N = tlist.numberOfItems;
@ -2234,23 +2236,24 @@ function BatchCommand(text) {
m = svgroot.createSVGMatrix(),
// temporarily strip off the rotate and save the old center
angle = canvas.getRotationAngle(selected);
var a = angle * Math.PI / 180;
if ( Math.abs(a) > (1.0e-10) ) {
var s = Math.sin(a)/(1 - Math.cos(a));
} else {
// FIXME: This blows up if the angle is exactly 0!
var s = 2/a;
}
for (var i = 0; i < tlist.numberOfItems; ++i) {
var xform = tlist.getItem(i);
if (xform.type == 4) {
// extract old center through mystical arts
var rm = xform.matrix;
oldcenter.y = (s*rm.e + rm.f)/2;
oldcenter.x = (rm.e - s*rm.f)/2;
tlist.removeItem(i);
break;
if (angle) {
var a = angle * Math.PI / 180;
if ( Math.abs(a) > (1.0e-10) ) {
var s = Math.sin(a)/(1 - Math.cos(a));
} else {
// FIXME: This blows up if the angle is exactly 0!
var s = 2/a;
}
for (var i = 0; i < tlist.numberOfItems; ++i) {
var xform = tlist.getItem(i);
if (xform.type == 4) {
// extract old center through mystical arts
var rm = xform.matrix;
oldcenter.y = (s*rm.e + rm.f)/2;
oldcenter.x = (rm.e - s*rm.f)/2;
tlist.removeItem(i);
break;
}
}
}
@ -5555,6 +5558,20 @@ function BatchCommand(text) {
canvas.fixOperaXML(svgcontent, newDoc.documentElement);
}
// recalculate dimensions on the top-level children so that unnecessary transforms
// are removed
var deepdive = function(node) {
if (node.nodeType == 1) {
var children = node.children;
var i = children.length;
while (i--) { deepdive(children.item(i)); }
try {
recalculateDimensions(node);
} catch(e) { console.log(e); }
}
}
deepdive(svgcontent);
var content = $(svgcontent);
// determine proper size