Fixed issue 339...for Firefox

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@975 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Alexis Deveria 2009-11-24 15:43:57 +00:00
parent da09855230
commit da6fb0a3cc
1 changed files with 41 additions and 28 deletions

View File

@ -5469,34 +5469,47 @@ function BatchCommand(text) {
var bb = elem.getBBox(); var bb = elem.getBBox();
var angle = canvas.getRotationAngle(elem) * Math.PI / 180.0; var angle = canvas.getRotationAngle(elem) * Math.PI / 180.0;
if (angle) { if (angle) {
var rminx = Number.MAX_VALUE, rminy = Number.MAX_VALUE, // Accurate way to get BBox of rotated element in Firefox:
rmaxx = Number.MIN_VALUE, rmaxy = Number.MIN_VALUE; // Put element in group and get its BBox
var cx = round(bb.x + bb.width/2), var g = document.createElementNS(svgns, "g");
cy = round(bb.y + bb.height/2); var parent = elem.parentNode;
var pts = [ [bb.x - cx, bb.y - cy], parent.replaceChild(g, elem);
[bb.x + bb.width - cx, bb.y - cy], g.appendChild(elem);
[bb.x + bb.width - cx, bb.y + bb.height - cy], bb = g.getBBox();
[bb.x - cx, bb.y + bb.height - cy] ]; parent.insertBefore(elem,g);
var j = 4; parent.removeChild(g);
while (j--) {
var x = pts[j][0], // Old method: Works by giving the rotated BBox,
y = pts[j][1], // this is (unfortunately) what Opera and Safari do
r = Math.sqrt( x*x + y*y ); // natively when getting the BBox of the parent group
var theta = Math.atan2(y,x) + angle; // var rminx = Number.MAX_VALUE, rminy = Number.MAX_VALUE,
x = round(r * Math.cos(theta) + cx); // rmaxx = Number.MIN_VALUE, rmaxy = Number.MIN_VALUE;
y = round(r * Math.sin(theta) + cy); // var cx = round(bb.x + bb.width/2),
// cy = round(bb.y + bb.height/2);
// now set the bbox for the shape after it's been rotated // var pts = [ [bb.x - cx, bb.y - cy],
if (x < rminx) rminx = x; // [bb.x + bb.width - cx, bb.y - cy],
if (y < rminy) rminy = y; // [bb.x + bb.width - cx, bb.y + bb.height - cy],
if (x > rmaxx) rmaxx = x; // [bb.x - cx, bb.y + bb.height - cy] ];
if (y > rmaxy) rmaxy = y; // var j = 4;
} // while (j--) {
// var x = pts[j][0],
bb.x = rminx; // y = pts[j][1],
bb.y = rminy; // r = Math.sqrt( x*x + y*y );
bb.width = rmaxx - rminx; // var theta = Math.atan2(y,x) + angle;
bb.height = rmaxy - rminy; // x = round(r * Math.cos(theta) + cx);
// y = round(r * Math.sin(theta) + cy);
//
// // now set the bbox for the shape after it's been rotated
// if (x < rminx) rminx = x;
// if (y < rminy) rminy = y;
// if (x > rmaxx) rmaxx = x;
// if (y > rmaxy) rmaxy = y;
// }
//
// bb.x = rminx;
// bb.y = rminy;
// bb.width = rmaxx - rminx;
// bb.height = rmaxy - rminy;
} }
return bb; return bb;