Fix Issue 177: rotation point should always be an integer (should avoid Opera 10 bug on non-English systems)

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@565 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Jeff Schiller 2009-09-04 16:48:20 +00:00
parent b995f1663a
commit 26f1b5bb0c
1 changed files with 29 additions and 27 deletions

View File

@ -56,8 +56,8 @@ function ChangeElementCommand(elem, attrs, text) {
var angle = canvas.getRotationAngle(elem); var angle = canvas.getRotationAngle(elem);
if (angle) { if (angle) {
var bbox = elem.getBBox(); var bbox = elem.getBBox();
var cx = bbox.x + bbox.width/2, var cx = parseInt(bbox.x + bbox.width/2),
cy = bbox.y + bbox.height/2; cy = parseInt(bbox.y + bbox.height/2);
var rotate = ["rotate(", angle, " ", cx, ",", cy, ")"].join(''); var rotate = ["rotate(", angle, " ", cx, ",", cy, ")"].join('');
if (rotate != elem.getAttribute("transform")) { if (rotate != elem.getAttribute("transform")) {
elem.setAttribute("transform", rotate); elem.setAttribute("transform", rotate);
@ -83,8 +83,8 @@ function ChangeElementCommand(elem, attrs, text) {
var angle = canvas.getRotationAngle(elem); var angle = canvas.getRotationAngle(elem);
if (angle) { if (angle) {
var bbox = elem.getBBox(); var bbox = elem.getBBox();
var cx = bbox.x + bbox.width/2, var cx = parseInt(bbox.x + bbox.width/2),
cy = bbox.y + bbox.height/2; cy = parseInt(bbox.y + bbox.height/2);
var rotate = ["rotate(", angle, " ", cx, ",", cy, ")"].join(''); var rotate = ["rotate(", angle, " ", cx, ",", cy, ")"].join('');
if (rotate != elem.getAttribute("transform")) { if (rotate != elem.getAttribute("transform")) {
elem.setAttribute("transform", rotate); elem.setAttribute("transform", rotate);
@ -372,8 +372,8 @@ function BatchCommand(text) {
var transform = elem.getAttribute("transform"); var transform = elem.getAttribute("transform");
var angle = canvas.getRotationAngle(elem); var angle = canvas.getRotationAngle(elem);
if (angle) { if (angle) {
var cx = oldbox.x + oldbox.width/2 var cx = parseInt(oldbox.x + oldbox.width/2)
cy = oldbox.y + oldbox.height/2; cy = parseInt(oldbox.y + oldbox.height/2);
this.selectorGroup.setAttribute("transform", "rotate("+angle+" " + cx + "," + cy + ")"); this.selectorGroup.setAttribute("transform", "rotate("+angle+" " + cx + "," + cy + ")");
} }
svgroot.unsuspendRedraw(sr_handle); svgroot.unsuspendRedraw(sr_handle);
@ -894,8 +894,8 @@ function BatchCommand(text) {
var pointGripContainer = document.getElementById("polypointgrip_container"); var pointGripContainer = document.getElementById("polypointgrip_container");
if (angle) { if (angle) {
// this is our old center upon which we have rotated the shape // this is our old center upon which we have rotated the shape
var tr_x = box.x + box.width/2, var tr_x = parseInt(box.x + box.width/2),
tr_y = box.y + box.height/2; tr_y = parseInt(box.y + box.height/2);
var cx = null, cy = null; var cx = null, cy = null;
var bFoundScale = false; var bFoundScale = false;
@ -1088,7 +1088,7 @@ function BatchCommand(text) {
'cy': pt.y, 'cy': pt.y,
// take the minimum of the new selected box's dimensions for the new circle radius // take the minimum of the new selected box's dimensions for the new circle radius
'r': Math.min(selectedBBox.width/2,selectedBBox.height/2) 'r': parseInt(Math.min(selectedBBox.width/2,selectedBBox.height/2))
}, 1000); }, 1000);
break; break;
case "ellipse": case "ellipse":
@ -1465,8 +1465,8 @@ function BatchCommand(text) {
selectedBBoxes[i].y = box.y + dy; selectedBBoxes[i].y = box.y + dy;
var angle = canvas.getRotationAngle(selected); var angle = canvas.getRotationAngle(selected);
if (angle) { if (angle) {
var cx = box.x + box.width/2, var cx = parseInt(box.x + box.width/2),
cy = box.y + box.height/2; cy = parseInt(box.y + box.height/2);
var xform = ts + [" rotate(", angle, " ", cx, ",", cy, ")"].join(''); var xform = ts + [" rotate(", angle, " ", cx, ",", cy, ")"].join('');
var r = Math.sqrt( dx*dx + dy*dy ); var r = Math.sqrt( dx*dx + dy*dy );
var theta = Math.atan2(dy,dx) - angle * Math.PI / 180.0; var theta = Math.atan2(dy,dx) - angle * Math.PI / 180.0;
@ -1568,8 +1568,8 @@ function BatchCommand(text) {
var ts = [" translate(", (left+tx), ",", (top+ty), ") scale(", sx, ",", sy, var ts = [" translate(", (left+tx), ",", (top+ty), ") scale(", sx, ",", sy,
") translate(", -(left+tx), ",", -(top+ty), ")"].join(''); ") translate(", -(left+tx), ",", -(top+ty), ")"].join('');
if (angle) { if (angle) {
var cx = left+width/2, var cx = parseInt(left+width/2),
cy = top+height/2; cy = parseInt(top+height/2);
ts = ["rotate(", angle, " ", cx, ",", cy, ")", ts].join('') ts = ["rotate(", angle, " ", cx, ",", cy, ")", ts].join('')
} }
selected.setAttribute("transform", ts); selected.setAttribute("transform", ts);
@ -1692,8 +1692,8 @@ function BatchCommand(text) {
if (angle) { if (angle) {
// calculate the shape's old center that was used for rotation // calculate the shape's old center that was used for rotation
var box = selectedBBoxes[0]; var box = selectedBBoxes[0];
var cx = box.x + box.width/2, var cx = paresInt(box.x + box.width/2),
cy = box.y + box.height/2; cy = parseInt(box.y + box.height/2);
var dx = x - cx, dy = y - cy; var dx = x - cx, dy = y - cy;
var r = Math.sqrt( dx*dx + dy*dy ); var r = Math.sqrt( dx*dx + dy*dy );
var theta = Math.atan2(dy,dx) - angle; var theta = Math.atan2(dy,dx) - angle;
@ -1733,7 +1733,9 @@ function BatchCommand(text) {
} }
break; break;
case "rotate": case "rotate":
var box = canvas.getBBox(selected),cx = box.x + box.width/2, cy = box.y + box.height/2; var box = canvas.getBBox(selected),
cx = parseInt(box.x + box.width/2),
cy = parseInt(box.y + box.height/2);
var angle = parseInt(((Math.atan2(cy-y,cx-x) * (180/Math.PI))-90) % 360); var angle = parseInt(((Math.atan2(cy-y,cx-x) * (180/Math.PI))-90) % 360);
canvas.setRotationAngle(angle<-180?(360+angle):angle, true); canvas.setRotationAngle(angle<-180?(360+angle):angle, true);
break; break;
@ -2108,18 +2110,18 @@ function BatchCommand(text) {
if (angle) { if (angle) {
var box = canvas.getBBox(current_poly); var box = canvas.getBBox(current_poly);
var oldbox = selectedBBoxes[0]; var oldbox = selectedBBoxes[0];
var oldcx = oldbox.x + oldbox.width/2, var oldcx = parseInt(oldbox.x + oldbox.width/2),
oldcy = oldbox.y + oldbox.height/2, oldcy = parseInt(oldbox.y + oldbox.height/2),
newcx = box.x + box.width/2, newcx = parseInt(box.x + box.width/2),
newcy = box.y + box.height/2; newcy = parseInt(box.y + box.height/2);
// un-rotate the new center to the proper position // un-rotate the new center to the proper position
var dx = newcx - oldcx, var dx = newcx - oldcx,
dy = newcy - oldcy; dy = newcy - oldcy;
var r = Math.sqrt(dx*dx + dy*dy); var r = Math.sqrt(dx*dx + dy*dy);
var theta = Math.atan2(dy,dx) + angle; var theta = Math.atan2(dy,dx) + angle;
newcx = r * Math.cos(theta) + oldcx; newcx = parseInt(r * Math.cos(theta) + oldcx);
newcy = r * Math.sin(theta) + oldcy; newcy = parseInt(r * Math.sin(theta) + oldcy);
var i = current_poly_pts.length; var i = current_poly_pts.length;
while (i) { while (i) {
@ -2610,7 +2612,7 @@ function BatchCommand(text) {
// we use the actual element's bbox (not the calculated one) since the // we use the actual element's bbox (not the calculated one) since the
// calculated bbox's center can change depending on the angle // calculated bbox's center can change depending on the angle
var bbox = elem.getBBox(); var bbox = elem.getBBox();
var cx = (bbox.x+bbox.width/2), cy = (bbox.y+bbox.height/2); var cx = parseInt(bbox.x+bbox.width/2), cy = parseInt(bbox.y+bbox.height/2);
var rotate = "rotate(" + val + " " + cx + "," + cy + ")"; var rotate = "rotate(" + val + " " + cx + "," + cy + ")";
if (preventUndo) { if (preventUndo) {
this.changeSelectedAttributeNoUndo("transform", rotate, selectedElements); this.changeSelectedAttributeNoUndo("transform", rotate, selectedElements);
@ -2790,8 +2792,8 @@ function BatchCommand(text) {
// we need to update the rotational transform attribute // we need to update the rotational transform attribute
var angle = canvas.getRotationAngle(elem); var angle = canvas.getRotationAngle(elem);
if (angle && attr != "transform") { if (angle && attr != "transform") {
var cx = selectedBBoxes[i].x + selectedBBoxes[i].width/2, var cx = parseInt(selectedBBoxes[i].x + selectedBBoxes[i].width/2),
cy = selectedBBoxes[i].y + selectedBBoxes[i].height/2; cy = parseInt(selectedBBoxes[i].y + selectedBBoxes[i].height/2);
var rotate = ["rotate(", angle, " ", cx, ",", cy, ")"].join(''); var rotate = ["rotate(", angle, " ", cx, ",", cy, ")"].join('');
if (rotate != elem.getAttribute("transform")) { if (rotate != elem.getAttribute("transform")) {
elem.setAttribute("transform", rotate); elem.setAttribute("transform", rotate);
@ -3063,8 +3065,8 @@ function BatchCommand(text) {
if (angles[i]) { if (angles[i]) {
var rminx = Number.MAX_VALUE, rminy = Number.MAX_VALUE, var rminx = Number.MAX_VALUE, rminy = Number.MAX_VALUE,
rmaxx = Number.MIN_VALUE, rmaxy = Number.MIN_VALUE; rmaxx = Number.MIN_VALUE, rmaxy = Number.MIN_VALUE;
var cx = bboxes[i].x + bboxes[i].width/2, var cx = parseInt(bboxes[i].x + bboxes[i].width/2),
cy = bboxes[i].y + bboxes[i].height/2; cy = parseInt(bboxes[i].y + bboxes[i].height/2);
var pts = [ [bboxes[i].x - cx, bboxes[i].y - cy], var pts = [ [bboxes[i].x - cx, bboxes[i].y - cy],
[bboxes[i].x + bboxes[i].width - cx, bboxes[i].y - cy], [bboxes[i].x + bboxes[i].width - cx, bboxes[i].y - cy],
[bboxes[i].x + bboxes[i].width - cx, bboxes[i].y + bboxes[i].height - cy], [bboxes[i].x + bboxes[i].width - cx, bboxes[i].y + bboxes[i].height - cy],