Fixtransforms branch: Fixed issues 346 and 347, changed resetPathOrientation() to use transformPoint()
git-svn-id: http://svg-edit.googlecode.com/svn/branches/fixtransforms@999 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
789c977594
commit
fecc1da764
|
@ -197,16 +197,21 @@ function svg_edit_setup() {
|
|||
|
||||
// called when any element has changed
|
||||
var elementChanged = function(window,elems) {
|
||||
// selectedElement must be updated here in case it was changed
|
||||
selectedElement = (elems.length == 1 || elems[1] == null ? elems[0] : null);
|
||||
|
||||
for (var i = 0; i < elems.length; ++i) {
|
||||
var elem = elems[i];
|
||||
|
||||
// if the element changed was the svg, then it could be a resolution change
|
||||
if (elem && elem.tagName == "svg" && elem.getAttribute("viewBox")) {
|
||||
var vb = elem.getAttribute("viewBox").split(' ');
|
||||
changeResolution(parseInt(vb[2]),
|
||||
parseInt(vb[3]));
|
||||
}
|
||||
// Update selectedElement if element is no longer part of the image.
|
||||
// This occurs for the text elements in Firefox
|
||||
else if(elem && selectedElement && selectedElement.parentNode == null) {
|
||||
selectedElement = elem;
|
||||
}
|
||||
}
|
||||
|
||||
// we update the contextual panel with potentially new
|
||||
|
@ -340,8 +345,9 @@ function svg_edit_setup() {
|
|||
var updateContextPanel = function() {
|
||||
var elem = selectedElement;
|
||||
var currentLayer = svgCanvas.getCurrentLayer();
|
||||
var currentMode = svgCanvas.getMode();
|
||||
// No need to update anything else in rotate mode
|
||||
if (svgCanvas.getMode() == 'rotate' && elem != null) {
|
||||
if (currentMode == 'rotate' && elem != null) {
|
||||
$('#angle').val(svgCanvas.getRotationAngle(elem));
|
||||
return;
|
||||
} else if(svgCanvas.addedNew && elem != null && elname == 'image') {
|
||||
|
@ -356,7 +362,7 @@ function svg_edit_setup() {
|
|||
var angle = svgCanvas.getRotationAngle(elem);
|
||||
$('#angle').val(angle);
|
||||
|
||||
if(!is_node) {
|
||||
if(!is_node && currentMode != 'pathedit') {
|
||||
$('#selected_panel').show();
|
||||
// Elements in this array already have coord fields
|
||||
if($.inArray(elname, ['line', 'circle', 'ellipse']) != -1) {
|
||||
|
|
|
@ -1476,6 +1476,7 @@ function BatchCommand(text) {
|
|||
// TODO: find the transformed translation
|
||||
// Is this taken care of by recalculateDimensions?
|
||||
*/
|
||||
|
||||
}
|
||||
else {
|
||||
// update the transform list with translate,scale,translate
|
||||
|
@ -2188,6 +2189,7 @@ function BatchCommand(text) {
|
|||
// insert a dummy transform so if the element(s) are moved it will have
|
||||
// a transform to use for its translate
|
||||
for (var i = 0; i < selectedElements.length; ++i) {
|
||||
if(selectedElements[i] == null) continue;
|
||||
var slist = canvas.getTransformList(selectedElements[i]);
|
||||
slist.insertItemBefore(svgroot.createSVGTransform(), 0);
|
||||
}
|
||||
|
@ -2796,7 +2798,7 @@ function BatchCommand(text) {
|
|||
};
|
||||
batchCmd.addSubCommand(new ChangeElementCommand(elem, changes));
|
||||
canvas.clearSelection();
|
||||
resetPathOrientation(elem, angle);
|
||||
resetPathOrientation(elem);
|
||||
addCommandToHistory(batchCmd);
|
||||
current_path = elem;
|
||||
setPointContainerTransform(""); // Maybe this should be in resetPointGrips?
|
||||
|
@ -2808,20 +2810,12 @@ function BatchCommand(text) {
|
|||
}
|
||||
|
||||
// Rotate all points of a path and remove its transform value
|
||||
var resetPathOrientation = function(path, angle) {
|
||||
var resetPathOrientation = function(path) {
|
||||
if(path == null || path.nodeName != 'path') return false;
|
||||
var angle = angle * Math.PI / 180.0;
|
||||
if(!angle) return false;
|
||||
|
||||
var tlist = canvas.getTransformList(path);
|
||||
var m = transformListToTransform(tlist).matrix;
|
||||
path.removeAttribute("transform");
|
||||
var bb = path.getBBox();
|
||||
var cx = bb.x + bb.width/2,
|
||||
cy = bb.y + bb.height/2;
|
||||
var rotate = function(x,y) {
|
||||
x -= cx; y -= cy;
|
||||
var r = Math.sqrt(x*x + y*y);
|
||||
var theta = Math.atan2(y,x) + angle;
|
||||
return [r * Math.cos(theta) + cx, r * Math.sin(theta) + cy];
|
||||
}
|
||||
|
||||
var segList = path.pathSegList;
|
||||
var len = segList.numberOfItems;
|
||||
|
@ -2834,7 +2828,8 @@ function BatchCommand(text) {
|
|||
$.each(['',1,2], function(j, n) {
|
||||
var x = seg['x'+n], y = seg['y'+n];
|
||||
if(x && y) {
|
||||
$.merge(pts, rotate(x,y));
|
||||
var pt = transformPoint(x, y, m);
|
||||
pts.splice(pts.length, 0, pt.x, pt.y);
|
||||
}
|
||||
});
|
||||
replacePathSeg(type, i, pts, path);
|
||||
|
@ -2990,7 +2985,7 @@ function BatchCommand(text) {
|
|||
|
||||
} else {
|
||||
// Get the correct BBox of the new path, then discard it
|
||||
resetPathOrientation(path, angle);
|
||||
resetPathOrientation(path);
|
||||
var bb = false;
|
||||
try {
|
||||
bb = path.getBBox();
|
||||
|
|
Loading…
Reference in New Issue