added missing semicolons. Suspecting several leaking global vars, I'll investigate later
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2387 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
edcc7edec6
commit
6afcd9da2b
|
@ -217,14 +217,14 @@ svgedit.history.RemoveElementCommand.prototype.apply = function(handler) {
|
||||||
|
|
||||||
// Function: RemoveElementCommand.unapply
|
// Function: RemoveElementCommand.unapply
|
||||||
// Re-adds the new element
|
// Re-adds the new element
|
||||||
svgedit.history.RemoveElementCommand.prototype.unapply = function(handler) {
|
svgedit.history.RemoveElementCommand.prototype.unapply = function(handler) {
|
||||||
if (handler) {
|
if (handler) {
|
||||||
handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.BEFORE_UNAPPLY, this);
|
handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.BEFORE_UNAPPLY, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
svgedit.transformlist.removeElementFromListMap(this.elem);
|
svgedit.transformlist.removeElementFromListMap(this.elem);
|
||||||
if(this.nextSibling == null) {
|
if (this.nextSibling == null) {
|
||||||
if(window.console) console.log('Error: reference element was lost');
|
if (window.console) console.log('Error: reference element was lost');
|
||||||
}
|
}
|
||||||
this.parent.insertBefore(this.elem, this.nextSibling);
|
this.parent.insertBefore(this.elem, this.nextSibling);
|
||||||
|
|
||||||
|
@ -243,7 +243,7 @@ svgedit.history.RemoveElementCommand.prototype.elements = function() {
|
||||||
|
|
||||||
// Class: svgedit.history.ChangeElementCommand
|
// Class: svgedit.history.ChangeElementCommand
|
||||||
// implements svgedit.history.HistoryCommand
|
// implements svgedit.history.HistoryCommand
|
||||||
// History command to make a change to an element.
|
// History command to make a change to an element.
|
||||||
// Usually an attribute change, but can also be textcontent.
|
// Usually an attribute change, but can also be textcontent.
|
||||||
//
|
//
|
||||||
// Parameters:
|
// Parameters:
|
||||||
|
@ -277,7 +277,7 @@ svgedit.history.ChangeElementCommand.prototype.apply = function(handler) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var bChangedTransform = false;
|
var bChangedTransform = false;
|
||||||
for(var attr in this.newValues ) {
|
for (var attr in this.newValues ) {
|
||||||
if (this.newValues[attr]) {
|
if (this.newValues[attr]) {
|
||||||
if (attr == "#text") this.elem.textContent = this.newValues[attr];
|
if (attr == "#text") this.elem.textContent = this.newValues[attr];
|
||||||
else if (attr == "#href") svgedit.utilities.setHref(this.elem, this.newValues[attr]);
|
else if (attr == "#href") svgedit.utilities.setHref(this.elem, this.newValues[attr]);
|
||||||
|
@ -297,7 +297,7 @@ svgedit.history.ChangeElementCommand.prototype.apply = function(handler) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// relocate rotational transform, if necessary
|
// relocate rotational transform, if necessary
|
||||||
if(!bChangedTransform) {
|
if (!bChangedTransform) {
|
||||||
var angle = svgedit.utilities.getRotationAngle(this.elem);
|
var angle = svgedit.utilities.getRotationAngle(this.elem);
|
||||||
if (angle) {
|
if (angle) {
|
||||||
var bbox = elem.getBBox();
|
var bbox = elem.getBBox();
|
||||||
|
@ -325,7 +325,7 @@ svgedit.history.ChangeElementCommand.prototype.unapply = function(handler) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var bChangedTransform = false;
|
var bChangedTransform = false;
|
||||||
for(var attr in this.oldValues ) {
|
for (var attr in this.oldValues ) {
|
||||||
if (this.oldValues[attr]) {
|
if (this.oldValues[attr]) {
|
||||||
if (attr == "#text") this.elem.textContent = this.oldValues[attr];
|
if (attr == "#text") this.elem.textContent = this.oldValues[attr];
|
||||||
else if (attr == "#href") svgedit.utilities.setHref(this.elem, this.oldValues[attr]);
|
else if (attr == "#href") svgedit.utilities.setHref(this.elem, this.oldValues[attr]);
|
||||||
|
@ -340,7 +340,7 @@ svgedit.history.ChangeElementCommand.prototype.unapply = function(handler) {
|
||||||
if (attr == "transform") { bChangedTransform = true; }
|
if (attr == "transform") { bChangedTransform = true; }
|
||||||
}
|
}
|
||||||
// relocate rotational transform, if necessary
|
// relocate rotational transform, if necessary
|
||||||
if(!bChangedTransform) {
|
if (!bChangedTransform) {
|
||||||
var angle = svgedit.utilities.getRotationAngle(this.elem);
|
var angle = svgedit.utilities.getRotationAngle(this.elem);
|
||||||
if (angle) {
|
if (angle) {
|
||||||
var bbox = elem.getBBox();
|
var bbox = elem.getBBox();
|
||||||
|
@ -453,7 +453,7 @@ svgedit.history.BatchCommand.prototype.addSubCommand = function(cmd) {
|
||||||
// Function: svgedit.history.BatchCommand.isEmpty
|
// Function: svgedit.history.BatchCommand.isEmpty
|
||||||
// Returns a boolean indicating whether or not the batch command is empty
|
// Returns a boolean indicating whether or not the batch command is empty
|
||||||
svgedit.history.BatchCommand.prototype.isEmpty = function() {
|
svgedit.history.BatchCommand.prototype.isEmpty = function() {
|
||||||
return this.stack.length == 0;
|
return this.stack.length === 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -471,7 +471,7 @@ svgedit.history.UndoManager = function(historyEventHandler) {
|
||||||
this.undoChangeStackPointer = -1;
|
this.undoChangeStackPointer = -1;
|
||||||
this.undoableChangeStack = [];
|
this.undoableChangeStack = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function: svgedit.history.UndoManager.resetUndoStack
|
// Function: svgedit.history.UndoManager.resetUndoStack
|
||||||
// Resets the undo stack, effectively clearing the undo/redo history
|
// Resets the undo stack, effectively clearing the undo/redo history
|
||||||
svgedit.history.UndoManager.prototype.resetUndoStack = function() {
|
svgedit.history.UndoManager.prototype.resetUndoStack = function() {
|
||||||
|
@ -480,30 +480,30 @@ svgedit.history.UndoManager.prototype.resetUndoStack = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function: svgedit.history.UndoManager.getUndoStackSize
|
// Function: svgedit.history.UndoManager.getUndoStackSize
|
||||||
// Returns:
|
// Returns:
|
||||||
// Integer with the current size of the undo history stack
|
// Integer with the current size of the undo history stack
|
||||||
svgedit.history.UndoManager.prototype.getUndoStackSize = function() {
|
svgedit.history.UndoManager.prototype.getUndoStackSize = function() {
|
||||||
return this.undoStackPointer;
|
return this.undoStackPointer;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function: svgedit.history.UndoManager.getRedoStackSize
|
// Function: svgedit.history.UndoManager.getRedoStackSize
|
||||||
// Returns:
|
// Returns:
|
||||||
// Integer with the current size of the redo history stack
|
// Integer with the current size of the redo history stack
|
||||||
svgedit.history.UndoManager.prototype.getRedoStackSize = function() {
|
svgedit.history.UndoManager.prototype.getRedoStackSize = function() {
|
||||||
return this.undoStack.length - this.undoStackPointer;
|
return this.undoStack.length - this.undoStackPointer;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function: svgedit.history.UndoManager.getNextUndoCommandText
|
// Function: svgedit.history.UndoManager.getNextUndoCommandText
|
||||||
// Returns:
|
// Returns:
|
||||||
// String associated with the next undo command
|
// String associated with the next undo command
|
||||||
svgedit.history.UndoManager.prototype.getNextUndoCommandText = function() {
|
svgedit.history.UndoManager.prototype.getNextUndoCommandText = function() {
|
||||||
return this.undoStackPointer > 0 ? this.undoStack[this.undoStackPointer-1].getText() : "";
|
return this.undoStackPointer > 0 ? this.undoStack[this.undoStackPointer-1].getText() : "";
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function: svgedit.history.UndoManager.getNextRedoCommandText
|
// Function: svgedit.history.UndoManager.getNextRedoCommandText
|
||||||
// Returns:
|
// Returns:
|
||||||
// String associated with the next redo command
|
// String associated with the next redo command
|
||||||
svgedit.history.UndoManager.prototype.getNextRedoCommandText = function() {
|
svgedit.history.UndoManager.prototype.getNextRedoCommandText = function() {
|
||||||
return this.undoStackPointer < this.undoStack.length ? this.undoStack[this.undoStackPointer].getText() : "";
|
return this.undoStackPointer < this.undoStack.length ? this.undoStack[this.undoStackPointer].getText() : "";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -516,7 +516,7 @@ svgedit.history.UndoManager.prototype.undo = function() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function: svgedit.history.UndoManager.redo
|
// Function: svgedit.history.UndoManager.redo
|
||||||
// Performs a redo step
|
// Performs a redo step
|
||||||
svgedit.history.UndoManager.prototype.redo = function() {
|
svgedit.history.UndoManager.prototype.redo = function() {
|
||||||
if (this.undoStackPointer < this.undoStack.length && this.undoStack.length > 0) {
|
if (this.undoStackPointer < this.undoStack.length && this.undoStack.length > 0) {
|
||||||
|
@ -524,18 +524,18 @@ svgedit.history.UndoManager.prototype.redo = function() {
|
||||||
cmd.apply(this.handler_);
|
cmd.apply(this.handler_);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function: svgedit.history.UndoManager.addCommandToHistory
|
// Function: svgedit.history.UndoManager.addCommandToHistory
|
||||||
// Adds a command object to the undo history stack
|
// Adds a command object to the undo history stack
|
||||||
//
|
//
|
||||||
// Parameters:
|
// Parameters:
|
||||||
// cmd - The command object to add
|
// cmd - The command object to add
|
||||||
svgedit.history.UndoManager.prototype.addCommandToHistory = function(cmd) {
|
svgedit.history.UndoManager.prototype.addCommandToHistory = function(cmd) {
|
||||||
// FIXME: we MUST compress consecutive text changes to the same element
|
// FIXME: we MUST compress consecutive text changes to the same element
|
||||||
// (right now each keystroke is saved as a separate command that includes the
|
// (right now each keystroke is saved as a separate command that includes the
|
||||||
// entire text contents of the text element)
|
// entire text contents of the text element)
|
||||||
// TODO: consider limiting the history that we store here (need to do some slicing)
|
// TODO: consider limiting the history that we store here (need to do some slicing)
|
||||||
|
|
||||||
// if our stack pointer is not at the end, then we have to remove
|
// if our stack pointer is not at the end, then we have to remove
|
||||||
// all commands after the pointer and insert the new command
|
// all commands after the pointer and insert the new command
|
||||||
if (this.undoStackPointer < this.undoStack.length && this.undoStack.length > 0) {
|
if (this.undoStackPointer < this.undoStack.length && this.undoStack.length > 0) {
|
||||||
|
@ -553,7 +553,7 @@ svgedit.history.UndoManager.prototype.addCommandToHistory = function(cmd) {
|
||||||
// pop the elements and old values off the stack, gets the current values
|
// pop the elements and old values off the stack, gets the current values
|
||||||
// from the DOM and uses all of these to construct the undo-able command.
|
// from the DOM and uses all of these to construct the undo-able command.
|
||||||
//
|
//
|
||||||
// Parameters:
|
// Parameters:
|
||||||
// attrName - The name of the attribute being changed
|
// attrName - The name of the attribute being changed
|
||||||
// elems - Array of DOM elements being changed
|
// elems - Array of DOM elements being changed
|
||||||
svgedit.history.UndoManager.prototype.beginUndoableChange = function(attrName, elems) {
|
svgedit.history.UndoManager.prototype.beginUndoableChange = function(attrName, elems) {
|
||||||
|
@ -578,7 +578,7 @@ svgedit.history.UndoManager.prototype.beginUndoableChange = function(attrName, e
|
||||||
// change since beginUndoableChange was called. The command can then
|
// change since beginUndoableChange was called. The command can then
|
||||||
// be added to the command history
|
// be added to the command history
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// Batch command object with resulting changes
|
// Batch command object with resulting changes
|
||||||
svgedit.history.UndoManager.prototype.finishUndoableChange = function() {
|
svgedit.history.UndoManager.prototype.finishUndoableChange = function() {
|
||||||
var p = this.undoChangeStackPointer--;
|
var p = this.undoChangeStackPointer--;
|
||||||
|
|
240
editor/path.js
240
editor/path.js
|
@ -58,7 +58,7 @@ var editorContext_ = null;
|
||||||
|
|
||||||
svgedit.path.init = function(editorContext) {
|
svgedit.path.init = function(editorContext) {
|
||||||
editorContext_ = editorContext;
|
editorContext_ = editorContext;
|
||||||
|
|
||||||
pathFuncs = [0,'ClosePath'];
|
pathFuncs = [0,'ClosePath'];
|
||||||
var pathFuncsStrs = ['Moveto', 'Lineto', 'CurvetoCubic', 'CurvetoQuadratic', 'Arc',
|
var pathFuncsStrs = ['Moveto', 'Lineto', 'CurvetoCubic', 'CurvetoQuadratic', 'Arc',
|
||||||
'LinetoHorizontal', 'LinetoVertical','CurvetoCubicSmooth','CurvetoQuadraticSmooth'];
|
'LinetoHorizontal', 'LinetoVertical','CurvetoCubicSmooth','CurvetoQuadraticSmooth'];
|
||||||
|
@ -72,19 +72,19 @@ svgedit.path.insertItemBefore = function(elem, newseg, index) {
|
||||||
// Support insertItemBefore on paths for FF2
|
// Support insertItemBefore on paths for FF2
|
||||||
var list = elem.pathSegList;
|
var list = elem.pathSegList;
|
||||||
|
|
||||||
if(svgedit.browser.supportsPathInsertItemBefore()) {
|
if (svgedit.browser.supportsPathInsertItemBefore()) {
|
||||||
list.insertItemBefore(newseg, index);
|
list.insertItemBefore(newseg, index);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var len = list.numberOfItems;
|
var len = list.numberOfItems;
|
||||||
var arr = [];
|
var arr = [];
|
||||||
for(var i=0; i<len; i++) {
|
for (var i=0; i<len; i++) {
|
||||||
var cur_seg = list.getItem(i);
|
var cur_seg = list.getItem(i);
|
||||||
arr.push(cur_seg)
|
arr.push(cur_seg);
|
||||||
}
|
}
|
||||||
list.clear();
|
list.clear();
|
||||||
for(var i=0; i<len; i++) {
|
for (var i=0; i<len; i++) {
|
||||||
if(i == index) { //index+1
|
if (i == index) { //index+1
|
||||||
list.appendItem(newseg);
|
list.appendItem(newseg);
|
||||||
}
|
}
|
||||||
list.appendItem(arr[i]);
|
list.appendItem(arr[i]);
|
||||||
|
@ -95,7 +95,7 @@ svgedit.path.insertItemBefore = function(elem, newseg, index) {
|
||||||
svgedit.path.ptObjToArr = function(type, seg_item) {
|
svgedit.path.ptObjToArr = function(type, seg_item) {
|
||||||
var arr = segData[type], len = arr.length;
|
var arr = segData[type], len = arr.length;
|
||||||
var out = Array(len);
|
var out = Array(len);
|
||||||
for(var i=0; i<len; i++) {
|
for (var i=0; i<len; i++) {
|
||||||
out[i] = seg_item[arr[i]];
|
out[i] = seg_item[arr[i]];
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
|
@ -107,7 +107,7 @@ svgedit.path.getGripPt = function(seg, alt_pt) {
|
||||||
y: alt_pt? alt_pt.y : seg.item.y
|
y: alt_pt? alt_pt.y : seg.item.y
|
||||||
}, path = seg.path;
|
}, path = seg.path;
|
||||||
|
|
||||||
if(path.matrix) {
|
if (path.matrix) {
|
||||||
var pt = svgedit.math.transformPoint(out.x, out.y, path.matrix);
|
var pt = svgedit.math.transformPoint(out.x, out.y, path.matrix);
|
||||||
out = pt;
|
out = pt;
|
||||||
}
|
}
|
||||||
|
@ -122,9 +122,9 @@ svgedit.path.getPointFromGrip = function(pt, path) {
|
||||||
var out = {
|
var out = {
|
||||||
x: pt.x,
|
x: pt.x,
|
||||||
y: pt.y
|
y: pt.y
|
||||||
}
|
};
|
||||||
|
|
||||||
if(path.matrix) {
|
if (path.matrix) {
|
||||||
var pt = svgedit.math.transformPoint(out.x, out.y, path.imatrix);
|
var pt = svgedit.math.transformPoint(out.x, out.y, path.imatrix);
|
||||||
out.x = pt.x;
|
out.x = pt.x;
|
||||||
out.y = pt.y;
|
out.y = pt.y;
|
||||||
|
@ -159,10 +159,10 @@ svgedit.path.addPointGrip = function(index, x, y) {
|
||||||
|
|
||||||
var grip = $('#pathpointgrip_'+index);
|
var grip = $('#pathpointgrip_'+index);
|
||||||
grip.dblclick(function() {
|
grip.dblclick(function() {
|
||||||
if(svgedit.path.path) svgedit.path.path.setSegType();
|
if (svgedit.path.path) svgedit.path.path.setSegType();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if(x && y) {
|
if (x && y) {
|
||||||
// set up the point grip element and display it
|
// set up the point grip element and display it
|
||||||
svgedit.utilities.assignAttributes(pointGrip, {
|
svgedit.utilities.assignAttributes(pointGrip, {
|
||||||
'cx': x,
|
'cx': x,
|
||||||
|
@ -185,8 +185,8 @@ svgedit.path.getGripContainer = function() {
|
||||||
|
|
||||||
svgedit.path.addCtrlGrip = function(id) {
|
svgedit.path.addCtrlGrip = function(id) {
|
||||||
var pointGrip = svgedit.utilities.getElem("ctrlpointgrip_"+id);
|
var pointGrip = svgedit.utilities.getElem("ctrlpointgrip_"+id);
|
||||||
if(pointGrip) return pointGrip;
|
if (pointGrip) return pointGrip;
|
||||||
|
|
||||||
pointGrip = document.createElementNS(svgns, "circle");
|
pointGrip = document.createElementNS(svgns, "circle");
|
||||||
svgedit.utilities.assignAttributes(pointGrip, {
|
svgedit.utilities.assignAttributes(pointGrip, {
|
||||||
'id': "ctrlpointgrip_" + id,
|
'id': "ctrlpointgrip_" + id,
|
||||||
|
@ -205,7 +205,7 @@ svgedit.path.addCtrlGrip = function(id) {
|
||||||
|
|
||||||
svgedit.path.getCtrlLine = function(id) {
|
svgedit.path.getCtrlLine = function(id) {
|
||||||
var ctrlLine = svgedit.utilities.getElem("ctrlLine_"+id);
|
var ctrlLine = svgedit.utilities.getElem("ctrlLine_"+id);
|
||||||
if(ctrlLine) return ctrlLine;
|
if (ctrlLine) return ctrlLine;
|
||||||
|
|
||||||
ctrlLine = document.createElementNS(svgns, "line");
|
ctrlLine = document.createElementNS(svgns, "line");
|
||||||
svgedit.utilities.assignAttributes(ctrlLine, {
|
svgedit.utilities.assignAttributes(ctrlLine, {
|
||||||
|
@ -222,7 +222,7 @@ svgedit.path.getPointGrip = function(seg, update) {
|
||||||
var index = seg.index;
|
var index = seg.index;
|
||||||
var pointGrip = svgedit.path.addPointGrip(index);
|
var pointGrip = svgedit.path.addPointGrip(index);
|
||||||
|
|
||||||
if(update) {
|
if (update) {
|
||||||
var pt = svgedit.path.getGripPt(seg);
|
var pt = svgedit.path.getGripPt(seg);
|
||||||
svgedit.utilities.assignAttributes(pointGrip, {
|
svgedit.utilities.assignAttributes(pointGrip, {
|
||||||
'cx': pt.x,
|
'cx': pt.x,
|
||||||
|
@ -237,8 +237,8 @@ svgedit.path.getPointGrip = function(seg, update) {
|
||||||
svgedit.path.getControlPoints = function(seg) {
|
svgedit.path.getControlPoints = function(seg) {
|
||||||
var item = seg.item;
|
var item = seg.item;
|
||||||
var index = seg.index;
|
var index = seg.index;
|
||||||
if(!("x1" in item) || !("x2" in item)) return null;
|
if (!("x1" in item) || !("x2" in item)) return null;
|
||||||
var cpt = {};
|
var cpt = {};
|
||||||
var pointGripContainer = svgedit.path.getGripContainer();
|
var pointGripContainer = svgedit.path.getGripContainer();
|
||||||
|
|
||||||
// Note that this is intentionally not seg.prev.item
|
// Note that this is intentionally not seg.prev.item
|
||||||
|
@ -246,7 +246,7 @@ svgedit.path.getControlPoints = function(seg) {
|
||||||
|
|
||||||
var seg_items = [prev, item];
|
var seg_items = [prev, item];
|
||||||
|
|
||||||
for(var i=1; i<3; i++) {
|
for (var i=1; i<3; i++) {
|
||||||
var id = index + 'c' + i;
|
var id = index + 'c' + i;
|
||||||
|
|
||||||
var ctrlLine = cpt['c' + i + '_line'] = svgedit.path.getCtrlLine(id);
|
var ctrlLine = cpt['c' + i + '_line'] = svgedit.path.getCtrlLine(id);
|
||||||
|
@ -283,19 +283,19 @@ svgedit.path.replacePathSeg = function(type, index, pts, elem) {
|
||||||
var func = 'createSVGPathSeg' + pathFuncs[type];
|
var func = 'createSVGPathSeg' + pathFuncs[type];
|
||||||
var seg = path[func].apply(path, pts);
|
var seg = path[func].apply(path, pts);
|
||||||
|
|
||||||
if(svgedit.browser.supportsPathReplaceItem()) {
|
if (svgedit.browser.supportsPathReplaceItem()) {
|
||||||
path.pathSegList.replaceItem(seg, index);
|
path.pathSegList.replaceItem(seg, index);
|
||||||
} else {
|
} else {
|
||||||
var segList = path.pathSegList;
|
var segList = path.pathSegList;
|
||||||
var len = segList.numberOfItems;
|
var len = segList.numberOfItems;
|
||||||
var arr = [];
|
var arr = [];
|
||||||
for(var i=0; i<len; i++) {
|
for (var i=0; i<len; i++) {
|
||||||
var cur_seg = segList.getItem(i);
|
var cur_seg = segList.getItem(i);
|
||||||
arr.push(cur_seg)
|
arr.push(cur_seg);
|
||||||
}
|
}
|
||||||
segList.clear();
|
segList.clear();
|
||||||
for(var i=0; i<len; i++) {
|
for (var i=0; i<len; i++) {
|
||||||
if(i == index) {
|
if (i == index) {
|
||||||
segList.appendItem(seg);
|
segList.appendItem(seg);
|
||||||
} else {
|
} else {
|
||||||
segList.appendItem(arr[i]);
|
segList.appendItem(arr[i]);
|
||||||
|
@ -307,7 +307,7 @@ svgedit.path.replacePathSeg = function(type, index, pts, elem) {
|
||||||
svgedit.path.getSegSelector = function(seg, update) {
|
svgedit.path.getSegSelector = function(seg, update) {
|
||||||
var index = seg.index;
|
var index = seg.index;
|
||||||
var segLine = svgedit.utilities.getElem("segline_" + index);
|
var segLine = svgedit.utilities.getElem("segline_" + index);
|
||||||
if(!segLine) {
|
if (!segLine) {
|
||||||
var pointGripContainer = svgedit.path.getGripContainer();
|
var pointGripContainer = svgedit.path.getGripContainer();
|
||||||
// create segline
|
// create segline
|
||||||
segLine = document.createElementNS(svgns, "path");
|
segLine = document.createElementNS(svgns, "path");
|
||||||
|
@ -321,11 +321,11 @@ svgedit.path.getSegSelector = function(seg, update) {
|
||||||
'd': 'M0,0 0,0'
|
'd': 'M0,0 0,0'
|
||||||
});
|
});
|
||||||
pointGripContainer.appendChild(segLine);
|
pointGripContainer.appendChild(segLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(update) {
|
if (update) {
|
||||||
var prev = seg.prev;
|
var prev = seg.prev;
|
||||||
if(!prev) {
|
if (!prev) {
|
||||||
segLine.setAttribute("display", "none");
|
segLine.setAttribute("display", "none");
|
||||||
return segLine;
|
return segLine;
|
||||||
}
|
}
|
||||||
|
@ -335,7 +335,7 @@ svgedit.path.getSegSelector = function(seg, update) {
|
||||||
svgedit.path.replacePathSeg(2, 0, [pt.x, pt.y], segLine);
|
svgedit.path.replacePathSeg(2, 0, [pt.x, pt.y], segLine);
|
||||||
|
|
||||||
var pts = svgedit.path.ptObjToArr(seg.type, seg.item, true);
|
var pts = svgedit.path.ptObjToArr(seg.type, seg.item, true);
|
||||||
for(var i=0; i < pts.length; i+=2) {
|
for (var i=0; i < pts.length; i+=2) {
|
||||||
var pt = svgedit.path.getGripPt(seg, {x:pts[i], y:pts[i+1]});
|
var pt = svgedit.path.getGripPt(seg, {x:pts[i], y:pts[i+1]});
|
||||||
pts[i] = pt.x;
|
pts[i] = pt.x;
|
||||||
pts[i+1] = pt.y;
|
pts[i+1] = pt.y;
|
||||||
|
@ -362,20 +362,20 @@ svgedit.path.smoothControlPoints = this.smoothControlPoints = function(ct1, ct2,
|
||||||
y1 = ct1.y - pt.y,
|
y1 = ct1.y - pt.y,
|
||||||
x2 = ct2.x - pt.x,
|
x2 = ct2.x - pt.x,
|
||||||
y2 = ct2.y - pt.y;
|
y2 = ct2.y - pt.y;
|
||||||
|
|
||||||
if ( (x1 != 0 || y1 != 0) && (x2 != 0 || y2 != 0) ) {
|
if ( (x1 != 0 || y1 != 0) && (x2 != 0 || y2 != 0) ) {
|
||||||
var anglea = Math.atan2(y1,x1),
|
var anglea = Math.atan2(y1,x1),
|
||||||
angleb = Math.atan2(y2,x2),
|
angleb = Math.atan2(y2,x2),
|
||||||
r1 = Math.sqrt(x1*x1+y1*y1),
|
r1 = Math.sqrt(x1*x1+y1*y1),
|
||||||
r2 = Math.sqrt(x2*x2+y2*y2),
|
r2 = Math.sqrt(x2*x2+y2*y2),
|
||||||
nct1 = editorContext_.getSVGRoot().createSVGPoint(),
|
nct1 = editorContext_.getSVGRoot().createSVGPoint(),
|
||||||
nct2 = editorContext_.getSVGRoot().createSVGPoint();
|
nct2 = editorContext_.getSVGRoot().createSVGPoint();
|
||||||
if (anglea < 0) { anglea += 2*Math.PI; }
|
if (anglea < 0) { anglea += 2*Math.PI; }
|
||||||
if (angleb < 0) { angleb += 2*Math.PI; }
|
if (angleb < 0) { angleb += 2*Math.PI; }
|
||||||
|
|
||||||
var angleBetween = Math.abs(anglea - angleb),
|
var angleBetween = Math.abs(anglea - angleb),
|
||||||
angleDiff = Math.abs(Math.PI - angleBetween)/2;
|
angleDiff = Math.abs(Math.PI - angleBetween)/2;
|
||||||
|
|
||||||
var new_anglea, new_angleb;
|
var new_anglea, new_angleb;
|
||||||
if (anglea - angleb > 0) {
|
if (anglea - angleb > 0) {
|
||||||
new_anglea = angleBetween < Math.PI ? (anglea + angleDiff) : (anglea - angleDiff);
|
new_anglea = angleBetween < Math.PI ? (anglea + angleDiff) : (anglea - angleDiff);
|
||||||
|
@ -385,13 +385,13 @@ svgedit.path.smoothControlPoints = this.smoothControlPoints = function(ct1, ct2,
|
||||||
new_anglea = angleBetween < Math.PI ? (anglea - angleDiff) : (anglea + angleDiff);
|
new_anglea = angleBetween < Math.PI ? (anglea - angleDiff) : (anglea + angleDiff);
|
||||||
new_angleb = angleBetween < Math.PI ? (angleb + angleDiff) : (angleb - angleDiff);
|
new_angleb = angleBetween < Math.PI ? (angleb + angleDiff) : (angleb - angleDiff);
|
||||||
}
|
}
|
||||||
|
|
||||||
// rotate the points
|
// rotate the points
|
||||||
nct1.x = r1 * Math.cos(new_anglea) + pt.x;
|
nct1.x = r1 * Math.cos(new_anglea) + pt.x;
|
||||||
nct1.y = r1 * Math.sin(new_anglea) + pt.y;
|
nct1.y = r1 * Math.sin(new_anglea) + pt.y;
|
||||||
nct2.x = r2 * Math.cos(new_angleb) + pt.x;
|
nct2.x = r2 * Math.cos(new_angleb) + pt.x;
|
||||||
nct2.y = r2 * Math.sin(new_angleb) + pt.y;
|
nct2.y = r2 * Math.sin(new_angleb) + pt.y;
|
||||||
|
|
||||||
return [nct1, nct2];
|
return [nct1, nct2];
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
|
@ -402,7 +402,7 @@ svgedit.path.Segment = function(index, item) {
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.item = item;
|
this.item = item;
|
||||||
this.type = item.pathSegType;
|
this.type = item.pathSegType;
|
||||||
|
|
||||||
this.ctrlpts = [];
|
this.ctrlpts = [];
|
||||||
this.ptgrip = null;
|
this.ptgrip = null;
|
||||||
this.segsel = null;
|
this.segsel = null;
|
||||||
|
@ -420,7 +420,7 @@ svgedit.path.Segment.prototype.selectCtrls = function(y) {
|
||||||
};
|
};
|
||||||
|
|
||||||
svgedit.path.Segment.prototype.show = function(y) {
|
svgedit.path.Segment.prototype.show = function(y) {
|
||||||
if(this.ptgrip) {
|
if (this.ptgrip) {
|
||||||
this.ptgrip.setAttribute("display", y ? "inline" : "none");
|
this.ptgrip.setAttribute("display", y ? "inline" : "none");
|
||||||
this.segsel.setAttribute("display", y ? "inline" : "none");
|
this.segsel.setAttribute("display", y ? "inline" : "none");
|
||||||
// Show/hide all control points if available
|
// Show/hide all control points if available
|
||||||
|
@ -429,10 +429,10 @@ svgedit.path.Segment.prototype.show = function(y) {
|
||||||
};
|
};
|
||||||
|
|
||||||
svgedit.path.Segment.prototype.select = function(y) {
|
svgedit.path.Segment.prototype.select = function(y) {
|
||||||
if(this.ptgrip) {
|
if (this.ptgrip) {
|
||||||
this.ptgrip.setAttribute("stroke", y ? "#0FF" : "#00F");
|
this.ptgrip.setAttribute("stroke", y ? "#0FF" : "#00F");
|
||||||
this.segsel.setAttribute("display", y ? "inline" : "none");
|
this.segsel.setAttribute("display", y ? "inline" : "none");
|
||||||
if(this.ctrlpts) {
|
if (this.ctrlpts) {
|
||||||
this.selectCtrls(y);
|
this.selectCtrls(y);
|
||||||
}
|
}
|
||||||
this.selected = y;
|
this.selected = y;
|
||||||
|
@ -446,7 +446,7 @@ svgedit.path.Segment.prototype.addGrip = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
svgedit.path.Segment.prototype.update = function(full) {
|
svgedit.path.Segment.prototype.update = function(full) {
|
||||||
if(this.ptgrip) {
|
if (this.ptgrip) {
|
||||||
var pt = svgedit.path.getGripPt(this);
|
var pt = svgedit.path.getGripPt(this);
|
||||||
svgedit.utilities.assignAttributes(this.ptgrip, {
|
svgedit.utilities.assignAttributes(this.ptgrip, {
|
||||||
'cx': pt.x,
|
'cx': pt.x,
|
||||||
|
@ -455,13 +455,13 @@ svgedit.path.Segment.prototype.update = function(full) {
|
||||||
|
|
||||||
svgedit.path.getSegSelector(this, true);
|
svgedit.path.getSegSelector(this, true);
|
||||||
|
|
||||||
if(this.ctrlpts) {
|
if (this.ctrlpts) {
|
||||||
if(full) {
|
if (full) {
|
||||||
this.item = svgedit.path.path.elem.pathSegList.getItem(this.index);
|
this.item = svgedit.path.path.elem.pathSegList.getItem(this.index);
|
||||||
this.type = this.item.pathSegType;
|
this.type = this.item.pathSegType;
|
||||||
}
|
}
|
||||||
svgedit.path.getControlPoints(this);
|
svgedit.path.getControlPoints(this);
|
||||||
}
|
}
|
||||||
// this.segsel.setAttribute("display", y?"inline":"none");
|
// this.segsel.setAttribute("display", y?"inline":"none");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -469,7 +469,7 @@ svgedit.path.Segment.prototype.update = function(full) {
|
||||||
svgedit.path.Segment.prototype.move = function(dx, dy) {
|
svgedit.path.Segment.prototype.move = function(dx, dy) {
|
||||||
var item = this.item;
|
var item = this.item;
|
||||||
|
|
||||||
if(this.ctrlpts) {
|
if (this.ctrlpts) {
|
||||||
var cur_pts = [item.x += dx, item.y += dy,
|
var cur_pts = [item.x += dx, item.y += dy,
|
||||||
item.x1, item.y1, item.x2 += dx, item.y2 += dy];
|
item.x1, item.y1, item.x2 += dx, item.y2 += dy];
|
||||||
} else {
|
} else {
|
||||||
|
@ -477,14 +477,14 @@ svgedit.path.Segment.prototype.move = function(dx, dy) {
|
||||||
}
|
}
|
||||||
svgedit.path.replacePathSeg(this.type, this.index, cur_pts);
|
svgedit.path.replacePathSeg(this.type, this.index, cur_pts);
|
||||||
|
|
||||||
if(this.next && this.next.ctrlpts) {
|
if (this.next && this.next.ctrlpts) {
|
||||||
var next = this.next.item;
|
var next = this.next.item;
|
||||||
var next_pts = [next.x, next.y,
|
var next_pts = [next.x, next.y,
|
||||||
next.x1 += dx, next.y1 += dy, next.x2, next.y2];
|
next.x1 += dx, next.y1 += dy, next.x2, next.y2];
|
||||||
svgedit.path.replacePathSeg(this.next.type, this.next.index, next_pts);
|
svgedit.path.replacePathSeg(this.next.type, this.next.index, next_pts);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.mate) {
|
if (this.mate) {
|
||||||
// The last point of a closed subpath has a "mate",
|
// The last point of a closed subpath has a "mate",
|
||||||
// which is the "M" segment of the subpath
|
// which is the "M" segment of the subpath
|
||||||
var item = this.mate.item;
|
var item = this.mate.item;
|
||||||
|
@ -494,7 +494,7 @@ svgedit.path.Segment.prototype.move = function(dx, dy) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.update(true);
|
this.update(true);
|
||||||
if(this.next) this.next.update(true);
|
if (this.next) this.next.update(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
svgedit.path.Segment.prototype.setLinked = function(num) {
|
svgedit.path.Segment.prototype.setLinked = function(num) {
|
||||||
|
@ -502,12 +502,12 @@ svgedit.path.Segment.prototype.setLinked = function(num) {
|
||||||
if (num == 2) {
|
if (num == 2) {
|
||||||
anum = 1;
|
anum = 1;
|
||||||
seg = this.next;
|
seg = this.next;
|
||||||
if(!seg) return;
|
if (!seg) return;
|
||||||
pt = this.item;
|
pt = this.item;
|
||||||
} else {
|
} else {
|
||||||
anum = 2;
|
anum = 2;
|
||||||
seg = this.prev;
|
seg = this.prev;
|
||||||
if(!seg) return;
|
if (!seg) return;
|
||||||
pt = seg.item;
|
pt = seg.item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -547,7 +547,7 @@ svgedit.path.Segment.prototype.setType = function(new_type, pts) {
|
||||||
};
|
};
|
||||||
|
|
||||||
svgedit.path.Path = function(elem) {
|
svgedit.path.Path = function(elem) {
|
||||||
if(!elem || elem.tagName !== "path") {
|
if (!elem || elem.tagName !== "path") {
|
||||||
throw "svgedit.path.Path constructed without a <path> element";
|
throw "svgedit.path.Path constructed without a <path> element";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -568,25 +568,25 @@ svgedit.path.Path.prototype.init = function() {
|
||||||
this.segs = [];
|
this.segs = [];
|
||||||
this.selected_pts = [];
|
this.selected_pts = [];
|
||||||
this.first_seg = null;
|
this.first_seg = null;
|
||||||
|
|
||||||
// Set up segs array
|
// Set up segs array
|
||||||
for(var i=0; i < len; i++) {
|
for (var i=0; i < len; i++) {
|
||||||
var item = segList.getItem(i);
|
var item = segList.getItem(i);
|
||||||
var segment = new svgedit.path.Segment(i, item);
|
var segment = new svgedit.path.Segment(i, item);
|
||||||
segment.path = this;
|
segment.path = this;
|
||||||
this.segs.push(segment);
|
this.segs.push(segment);
|
||||||
}
|
}
|
||||||
|
|
||||||
var segs = this.segs;
|
var segs = this.segs;
|
||||||
var start_i = null;
|
var start_i = null;
|
||||||
|
|
||||||
for(var i=0; i < len; i++) {
|
for (var i=0; i < len; i++) {
|
||||||
var seg = segs[i];
|
var seg = segs[i];
|
||||||
var next_seg = (i+1) >= len ? null : segs[i+1];
|
var next_seg = (i+1) >= len ? null : segs[i+1];
|
||||||
var prev_seg = (i-1) < 0 ? null : segs[i-1];
|
var prev_seg = (i-1) < 0 ? null : segs[i-1];
|
||||||
|
|
||||||
if(seg.type === 2) {
|
if (seg.type === 2) {
|
||||||
if(prev_seg && prev_seg.type !== 1) {
|
if (prev_seg && prev_seg.type !== 1) {
|
||||||
// New sub-path, last one is open,
|
// New sub-path, last one is open,
|
||||||
// so add a grip to last sub-path's first point
|
// so add a grip to last sub-path's first point
|
||||||
var start_seg = segs[start_i];
|
var start_seg = segs[start_i];
|
||||||
|
@ -596,20 +596,20 @@ svgedit.path.Path.prototype.init = function() {
|
||||||
}
|
}
|
||||||
// Remember that this is a starter seg
|
// Remember that this is a starter seg
|
||||||
start_i = i;
|
start_i = i;
|
||||||
} else if(next_seg && next_seg.type === 1) {
|
} else if (next_seg && next_seg.type === 1) {
|
||||||
// This is the last real segment of a closed sub-path
|
// This is the last real segment of a closed sub-path
|
||||||
// Next is first seg after "M"
|
// Next is first seg after "M"
|
||||||
seg.next = segs[start_i+1];
|
seg.next = segs[start_i+1];
|
||||||
|
|
||||||
// First seg after "M"'s prev is this
|
// First seg after "M"'s prev is this
|
||||||
seg.next.prev = seg;
|
seg.next.prev = seg;
|
||||||
seg.mate = segs[start_i];
|
seg.mate = segs[start_i];
|
||||||
seg.addGrip();
|
seg.addGrip();
|
||||||
if(this.first_seg == null) {
|
if (this.first_seg == null) {
|
||||||
this.first_seg = seg;
|
this.first_seg = seg;
|
||||||
}
|
}
|
||||||
} else if(!next_seg) {
|
} else if (!next_seg) {
|
||||||
if(seg.type !== 1) {
|
if (seg.type !== 1) {
|
||||||
// Last seg, doesn't close so add a grip
|
// Last seg, doesn't close so add a grip
|
||||||
// to last sub-path's first point
|
// to last sub-path's first point
|
||||||
var start_seg = segs[start_i];
|
var start_seg = segs[start_i];
|
||||||
|
@ -618,17 +618,17 @@ svgedit.path.Path.prototype.init = function() {
|
||||||
start_seg.addGrip();
|
start_seg.addGrip();
|
||||||
seg.addGrip();
|
seg.addGrip();
|
||||||
|
|
||||||
if(!this.first_seg) {
|
if (!this.first_seg) {
|
||||||
// Open path, so set first as real first and add grip
|
// Open path, so set first as real first and add grip
|
||||||
this.first_seg = segs[start_i];
|
this.first_seg = segs[start_i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if(seg.type !== 1){
|
} else if (seg.type !== 1){
|
||||||
// Regular segment, so add grip and its "next"
|
// Regular segment, so add grip and its "next"
|
||||||
seg.addGrip();
|
seg.addGrip();
|
||||||
|
|
||||||
// Don't set its "next" if it's an "M"
|
// Don't set its "next" if it's an "M"
|
||||||
if(next_seg && next_seg.type !== 2) {
|
if (next_seg && next_seg.type !== 2) {
|
||||||
seg.next = next_seg;
|
seg.next = next_seg;
|
||||||
seg.next.prev = seg;
|
seg.next.prev = seg;
|
||||||
}
|
}
|
||||||
|
@ -638,17 +638,17 @@ svgedit.path.Path.prototype.init = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
svgedit.path.Path.prototype.eachSeg = function(fn) {
|
svgedit.path.Path.prototype.eachSeg = function(fn) {
|
||||||
var len = this.segs.length
|
var len = this.segs.length;
|
||||||
for(var i=0; i < len; i++) {
|
for (var i=0; i < len; i++) {
|
||||||
var ret = fn.call(this.segs[i], i);
|
var ret = fn.call(this.segs[i], i);
|
||||||
if(ret === false) break;
|
if (ret === false) break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
svgedit.path.Path.prototype.addSeg = function(index) {
|
svgedit.path.Path.prototype.addSeg = function(index) {
|
||||||
// Adds a new segment
|
// Adds a new segment
|
||||||
var seg = this.segs[index];
|
var seg = this.segs[index];
|
||||||
if(!seg.prev) return;
|
if (!seg.prev) return;
|
||||||
|
|
||||||
var prev = seg.prev;
|
var prev = seg.prev;
|
||||||
var newseg;
|
var newseg;
|
||||||
|
@ -684,25 +684,24 @@ svgedit.path.Path.prototype.addSeg = function(index) {
|
||||||
svgedit.path.Path.prototype.deleteSeg = function(index) {
|
svgedit.path.Path.prototype.deleteSeg = function(index) {
|
||||||
var seg = this.segs[index];
|
var seg = this.segs[index];
|
||||||
var list = this.elem.pathSegList;
|
var list = this.elem.pathSegList;
|
||||||
|
|
||||||
seg.show(false);
|
seg.show(false);
|
||||||
var next = seg.next;
|
var next = seg.next;
|
||||||
if(seg.mate) {
|
if (seg.mate) {
|
||||||
// Make the next point be the "M" point
|
// Make the next point be the "M" point
|
||||||
var pt = [next.item.x, next.item.y];
|
var pt = [next.item.x, next.item.y];
|
||||||
svgedit.path.replacePathSeg(2, next.index, pt);
|
svgedit.path.replacePathSeg(2, next.index, pt);
|
||||||
|
|
||||||
// Reposition last node
|
// Reposition last node
|
||||||
svgedit.path.replacePathSeg(4, seg.index, pt);
|
svgedit.path.replacePathSeg(4, seg.index, pt);
|
||||||
|
|
||||||
list.removeItem(seg.mate.index);
|
list.removeItem(seg.mate.index);
|
||||||
} else if(!seg.prev) {
|
} else if (!seg.prev) {
|
||||||
// First node of open path, make next point the M
|
// First node of open path, make next point the M
|
||||||
var item = seg.item;
|
var item = seg.item;
|
||||||
var pt = [next.item.x, next.item.y];
|
var pt = [next.item.x, next.item.y];
|
||||||
svgedit.path.replacePathSeg(2, seg.next.index, pt);
|
svgedit.path.replacePathSeg(2, seg.next.index, pt);
|
||||||
list.removeItem(index);
|
list.removeItem(index);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
list.removeItem(index);
|
list.removeItem(index);
|
||||||
}
|
}
|
||||||
|
@ -712,31 +711,32 @@ svgedit.path.Path.prototype.subpathIsClosed = function(index) {
|
||||||
var closed = false;
|
var closed = false;
|
||||||
// Check if subpath is already open
|
// Check if subpath is already open
|
||||||
svgedit.path.path.eachSeg(function(i) {
|
svgedit.path.path.eachSeg(function(i) {
|
||||||
if(i <= index) return true;
|
if (i <= index) return true;
|
||||||
if(this.type === 2) {
|
if (this.type === 2) {
|
||||||
// Found M first, so open
|
// Found M first, so open
|
||||||
return false;
|
return false;
|
||||||
} else if(this.type === 1) {
|
}
|
||||||
|
if (this.type === 1) {
|
||||||
// Found Z first, so closed
|
// Found Z first, so closed
|
||||||
closed = true;
|
closed = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return closed;
|
return closed;
|
||||||
};
|
};
|
||||||
|
|
||||||
svgedit.path.Path.prototype.removePtFromSelection = function(index) {
|
svgedit.path.Path.prototype.removePtFromSelection = function(index) {
|
||||||
var pos = this.selected_pts.indexOf(index);
|
var pos = this.selected_pts.indexOf(index);
|
||||||
if(pos == -1) {
|
if (pos == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.segs[index].select(false);
|
this.segs[index].select(false);
|
||||||
this.selected_pts.splice(pos, 1);
|
this.selected_pts.splice(pos, 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
svgedit.path.Path.prototype.clearSelection = function() {
|
svgedit.path.Path.prototype.clearSelection = function() {
|
||||||
this.eachSeg(function(i) {
|
this.eachSeg(function() {
|
||||||
// 'this' is the segment here
|
// 'this' is the segment here
|
||||||
this.select(false);
|
this.select(false);
|
||||||
});
|
});
|
||||||
|
@ -753,13 +753,13 @@ svgedit.path.Path.prototype.show = function(y) {
|
||||||
// 'this' is the segment here
|
// 'this' is the segment here
|
||||||
this.show(y);
|
this.show(y);
|
||||||
});
|
});
|
||||||
if(y) {
|
if (y) {
|
||||||
this.selectPt(this.first_seg.index);
|
this.selectPt(this.first_seg.index);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Move selected points
|
// Move selected points
|
||||||
svgedit.path.Path.prototype.movePts = function(d_x, d_y) {
|
svgedit.path.Path.prototype.movePts = function(d_x, d_y) {
|
||||||
var i = this.selected_pts.length;
|
var i = this.selected_pts.length;
|
||||||
while(i--) {
|
while(i--) {
|
||||||
|
@ -771,7 +771,7 @@ svgedit.path.Path.prototype.movePts = function(d_x, d_y) {
|
||||||
svgedit.path.Path.prototype.moveCtrl = function(d_x, d_y) {
|
svgedit.path.Path.prototype.moveCtrl = function(d_x, d_y) {
|
||||||
var seg = this.segs[this.selected_pts[0]];
|
var seg = this.segs[this.selected_pts[0]];
|
||||||
seg.moveCtrl(this.dragctrl, d_x, d_y);
|
seg.moveCtrl(this.dragctrl, d_x, d_y);
|
||||||
if(link_control_pts) {
|
if (link_control_pts) {
|
||||||
seg.setLinked(this.dragctrl);
|
seg.setLinked(this.dragctrl);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -782,23 +782,23 @@ svgedit.path.Path.prototype.setSegType = function(new_type) {
|
||||||
var text;
|
var text;
|
||||||
while(i--) {
|
while(i--) {
|
||||||
var sel_pt = this.selected_pts[i];
|
var sel_pt = this.selected_pts[i];
|
||||||
|
|
||||||
// Selected seg
|
// Selected seg
|
||||||
var cur = this.segs[sel_pt];
|
var cur = this.segs[sel_pt];
|
||||||
var prev = cur.prev;
|
var prev = cur.prev;
|
||||||
if(!prev) continue;
|
if (!prev) continue;
|
||||||
|
|
||||||
if(!new_type) { // double-click, so just toggle
|
if (!new_type) { // double-click, so just toggle
|
||||||
text = "Toggle Path Segment Type";
|
text = "Toggle Path Segment Type";
|
||||||
|
|
||||||
// Toggle segment to curve/straight line
|
// Toggle segment to curve/straight line
|
||||||
var old_type = cur.type;
|
var old_type = cur.type;
|
||||||
|
|
||||||
new_type = (old_type == 6) ? 4 : 6;
|
new_type = (old_type == 6) ? 4 : 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_type = new_type-0;
|
new_type = new_type-0;
|
||||||
|
|
||||||
var cur_x = cur.item.x;
|
var cur_x = cur.item.x;
|
||||||
var cur_y = cur.item.y;
|
var cur_y = cur.item.y;
|
||||||
var prev_x = prev.item.x;
|
var prev_x = prev.item.x;
|
||||||
|
@ -806,7 +806,7 @@ svgedit.path.Path.prototype.setSegType = function(new_type) {
|
||||||
var points;
|
var points;
|
||||||
switch ( new_type ) {
|
switch ( new_type ) {
|
||||||
case 6:
|
case 6:
|
||||||
if(cur.olditem) {
|
if (cur.olditem) {
|
||||||
var old = cur.olditem;
|
var old = cur.olditem;
|
||||||
points = [cur_x,cur_y, old.x1,old.y1, old.x2,old.y2];
|
points = [cur_x,cur_y, old.x1,old.y1, old.x2,old.y2];
|
||||||
} else {
|
} else {
|
||||||
|
@ -829,12 +829,12 @@ svgedit.path.Path.prototype.setSegType = function(new_type) {
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
points = [cur_x,cur_y];
|
points = [cur_x,cur_y];
|
||||||
|
|
||||||
// Store original prevve segment nums
|
// Store original prevve segment nums
|
||||||
cur.olditem = cur.item;
|
cur.olditem = cur.item;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
cur.setType(new_type, points);
|
cur.setType(new_type, points);
|
||||||
}
|
}
|
||||||
svgedit.path.path.endChanges(text);
|
svgedit.path.path.endChanges(text);
|
||||||
|
@ -842,19 +842,19 @@ svgedit.path.Path.prototype.setSegType = function(new_type) {
|
||||||
|
|
||||||
svgedit.path.Path.prototype.selectPt = function(pt, ctrl_num) {
|
svgedit.path.Path.prototype.selectPt = function(pt, ctrl_num) {
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
if(pt == null) {
|
if (pt == null) {
|
||||||
this.eachSeg(function(i) {
|
this.eachSeg(function(i) {
|
||||||
// 'this' is the segment here.
|
// 'this' is the segment here.
|
||||||
if(this.prev) {
|
if (this.prev) {
|
||||||
pt = i;
|
pt = i;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.addPtsToSelection(pt);
|
this.addPtsToSelection(pt);
|
||||||
if(ctrl_num) {
|
if (ctrl_num) {
|
||||||
this.dragctrl = ctrl_num;
|
this.dragctrl = ctrl_num;
|
||||||
|
|
||||||
if(link_control_pts) {
|
if (link_control_pts) {
|
||||||
this.segs[pt].setLinked(ctrl_num);
|
this.segs[pt].setLinked(ctrl_num);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -863,7 +863,7 @@ svgedit.path.Path.prototype.selectPt = function(pt, ctrl_num) {
|
||||||
// Update position of all points
|
// Update position of all points
|
||||||
svgedit.path.Path.prototype.update = function() {
|
svgedit.path.Path.prototype.update = function() {
|
||||||
var elem = this.elem;
|
var elem = this.elem;
|
||||||
if(svgedit.utilities.getRotationAngle(elem)) {
|
if (svgedit.utilities.getRotationAngle(elem)) {
|
||||||
this.matrix = svgedit.math.getMatrix(elem);
|
this.matrix = svgedit.math.getMatrix(elem);
|
||||||
this.imatrix = this.matrix.inverse();
|
this.imatrix = this.matrix.inverse();
|
||||||
} else {
|
} else {
|
||||||
|
@ -881,34 +881,34 @@ svgedit.path.Path.prototype.update = function() {
|
||||||
|
|
||||||
svgedit.path.getPath_ = function(elem) {
|
svgedit.path.getPath_ = function(elem) {
|
||||||
var p = pathData[elem.id];
|
var p = pathData[elem.id];
|
||||||
if(!p) p = pathData[elem.id] = new svgedit.path.Path(elem);
|
if (!p) p = pathData[elem.id] = new svgedit.path.Path(elem);
|
||||||
return p;
|
return p;
|
||||||
};
|
};
|
||||||
|
|
||||||
svgedit.path.removePath_ = function(id) {
|
svgedit.path.removePath_ = function(id) {
|
||||||
if(id in pathData) delete pathData[id];
|
if (id in pathData) delete pathData[id];
|
||||||
};
|
};
|
||||||
|
|
||||||
var getRotVals = function(x, y) {
|
var getRotVals = function(x, y) {
|
||||||
dx = x - oldcx;
|
dx = x - oldcx;
|
||||||
dy = y - oldcy;
|
dy = y - oldcy;
|
||||||
|
|
||||||
// rotate the point around the old center
|
// rotate the point around the old center
|
||||||
r = Math.sqrt(dx*dx + dy*dy);
|
r = Math.sqrt(dx*dx + dy*dy);
|
||||||
theta = Math.atan2(dy,dx) + angle;
|
theta = Math.atan2(dy,dx) + angle;
|
||||||
dx = r * Math.cos(theta) + oldcx;
|
dx = r * Math.cos(theta) + oldcx;
|
||||||
dy = r * Math.sin(theta) + oldcy;
|
dy = r * Math.sin(theta) + oldcy;
|
||||||
|
|
||||||
// dx,dy should now hold the actual coordinates of each
|
// dx,dy should now hold the actual coordinates of each
|
||||||
// point after being rotated
|
// point after being rotated
|
||||||
|
|
||||||
// now we want to rotate them around the new center in the reverse direction
|
// now we want to rotate them around the new center in the reverse direction
|
||||||
dx -= newcx;
|
dx -= newcx;
|
||||||
dy -= newcy;
|
dy -= newcy;
|
||||||
|
|
||||||
r = Math.sqrt(dx*dx + dy*dy);
|
r = Math.sqrt(dx*dx + dy*dy);
|
||||||
theta = Math.atan2(dy,dx) - angle;
|
theta = Math.atan2(dy,dx) - angle;
|
||||||
|
|
||||||
return {'x':(r * Math.cos(theta) + newcx)/1,
|
return {'x':(r * Math.cos(theta) + newcx)/1,
|
||||||
'y':(r * Math.sin(theta) + newcy)/1};
|
'y':(r * Math.sin(theta) + newcy)/1};
|
||||||
};
|
};
|
||||||
|
@ -923,7 +923,7 @@ var getRotVals = function(x, y) {
|
||||||
svgedit.path.recalcRotatedPath = function() {
|
svgedit.path.recalcRotatedPath = function() {
|
||||||
var current_path = svgedit.path.path.elem;
|
var current_path = svgedit.path.path.elem;
|
||||||
var angle = svgedit.utilities.getRotationAngle(current_path, true);
|
var angle = svgedit.utilities.getRotationAngle(current_path, true);
|
||||||
if(!angle) return;
|
if (!angle) return;
|
||||||
// selectedBBoxes[0] = svgedit.path.path.oldbbox;
|
// selectedBBoxes[0] = svgedit.path.path.oldbbox;
|
||||||
var box = svgedit.utilities.getBBox(current_path),
|
var box = svgedit.utilities.getBBox(current_path),
|
||||||
oldbox = svgedit.path.path.oldbbox,//selectedBBoxes[0],
|
oldbox = svgedit.path.path.oldbbox,//selectedBBoxes[0],
|
||||||
|
@ -931,27 +931,27 @@ svgedit.path.recalcRotatedPath = function() {
|
||||||
oldcy = oldbox.y + oldbox.height/2,
|
oldcy = oldbox.y + oldbox.height/2,
|
||||||
newcx = box.x + box.width/2,
|
newcx = box.x + box.width/2,
|
||||||
newcy = box.y + box.height/2,
|
newcy = box.y + box.height/2,
|
||||||
|
|
||||||
// un-rotate the new center to the proper position
|
// un-rotate the new center to the proper position
|
||||||
dx = newcx - oldcx,
|
dx = newcx - oldcx,
|
||||||
dy = newcy - oldcy,
|
dy = newcy - oldcy,
|
||||||
r = Math.sqrt(dx*dx + dy*dy),
|
r = Math.sqrt(dx*dx + dy*dy),
|
||||||
theta = Math.atan2(dy,dx) + angle;
|
theta = Math.atan2(dy,dx) + angle;
|
||||||
|
|
||||||
newcx = r * Math.cos(theta) + oldcx;
|
newcx = r * Math.cos(theta) + oldcx;
|
||||||
newcy = r * Math.sin(theta) + oldcy;
|
newcy = r * Math.sin(theta) + oldcy;
|
||||||
|
|
||||||
var list = current_path.pathSegList,
|
var list = current_path.pathSegList,
|
||||||
i = list.numberOfItems;
|
i = list.numberOfItems;
|
||||||
while (i) {
|
while (i) {
|
||||||
i -= 1;
|
i -= 1;
|
||||||
var seg = list.getItem(i),
|
var seg = list.getItem(i),
|
||||||
type = seg.pathSegType;
|
type = seg.pathSegType;
|
||||||
if(type == 1) continue;
|
if (type == 1) continue;
|
||||||
|
|
||||||
var rvals = getRotVals(seg.x,seg.y),
|
var rvals = getRotVals(seg.x,seg.y),
|
||||||
points = [rvals.x, rvals.y];
|
points = [rvals.x, rvals.y];
|
||||||
if(seg.x1 != null && seg.x2 != null) {
|
if (seg.x1 != null && seg.x2 != null) {
|
||||||
c_vals1 = getRotVals(seg.x1, seg.y1);
|
c_vals1 = getRotVals(seg.x1, seg.y1);
|
||||||
c_vals2 = getRotVals(seg.x2, seg.y2);
|
c_vals2 = getRotVals(seg.x2, seg.y2);
|
||||||
points.splice(points.length, 0, c_vals1.x , c_vals1.y, c_vals2.x, c_vals2.y);
|
points.splice(points.length, 0, c_vals1.x , c_vals1.y, c_vals2.x, c_vals2.y);
|
||||||
|
@ -959,10 +959,10 @@ svgedit.path.recalcRotatedPath = function() {
|
||||||
svgedit.path.replacePathSeg(type, i, points);
|
svgedit.path.replacePathSeg(type, i, points);
|
||||||
} // loop for each point
|
} // loop for each point
|
||||||
|
|
||||||
box = svgedit.utilities.getBBox(current_path);
|
box = svgedit.utilities.getBBox(current_path);
|
||||||
// selectedBBoxes[0].x = box.x; selectedBBoxes[0].y = box.y;
|
// selectedBBoxes[0].x = box.x; selectedBBoxes[0].y = box.y;
|
||||||
// selectedBBoxes[0].width = box.width; selectedBBoxes[0].height = box.height;
|
// selectedBBoxes[0].width = box.width; selectedBBoxes[0].height = box.height;
|
||||||
|
|
||||||
// now we must set the new transform to be rotated around the new center
|
// now we must set the new transform to be rotated around the new center
|
||||||
var R_nc = svgroot.createSVGTransform(),
|
var R_nc = svgroot.createSVGTransform(),
|
||||||
tlist = svgedit.transformlist.getTransformList(current_path);
|
tlist = svgedit.transformlist.getTransformList(current_path);
|
||||||
|
|
Loading…
Reference in New Issue