fixing closing path code issue #17

master
Mark MacKay 2015-12-28 23:34:21 -06:00
parent 11c9f22521
commit a4c597b434
4 changed files with 18 additions and 10 deletions

View File

@ -356,8 +356,8 @@ svgedit.path.is_linked=true}else{svgedit.path.setLinkControlPoints(false);svgedi
u.setAttribute("cy",F);u.setAttribute("display","inline");D=m[0];u=m[1];n.getItem(q);var O=z/v,W=F/v;H=h?D+(D-O):H;h=h?u+(u-W):J;E.setAttribute("cx",H*v);E.setAttribute("cy",h*v);E.setAttribute("display","inline");E=svgedit.path.getCtrlLine(1);J=svgedit.path.getCtrlLine(2);ma(E,{x1:z,y1:F,x2:D*v,y2:u*v,display:"inline"});ma(J,{x1:H*v,y1:h*v,x2:D*v,y2:u*v,display:"inline"});if(q===0)C=[z,F];else{n=n.getItem(q-1);z=n.x;F=n.y;if(n.pathSegType===6){z+=z-n.x2;F+=F-n.y2}else if(C){z=C[0]/v;F=C[1]/v}svgedit.path.replacePathSeg(6,
q,[D,u,this.lastCtrlPoint[0]/v,this.lastCtrlPoint[1]/v,H,h],A)}}else if(h=this.stretchy){q=n.getItem(q);n=z;u=F;if(D.target.id==="pathpointgrip_0"&&svgedit.path.first_grip){n=svgedit.path.first_grip[0];u=svgedit.path.first_grip[1]}if(q.pathSegType===6)svgedit.path.replacePathSeg(6,1,[z,F,(this.lastCtrlPoint[0]/v||q.x+(q.x-q.x2))*v,(this.lastCtrlPoint[1]/v||q.y+(q.y-q.y2))*v,n,u],h);else C?svgedit.path.replacePathSeg(6,1,[z,F,C[0],C[1],z,F],h):svgedit.path.replacePathSeg(4,1,[z,F],h)}}}else if(svgedit.path.path.dragging){n=
svgedit.path.getPointFromGrip({x:svgedit.path.path.dragging[0],y:svgedit.path.path.dragging[1]},svgedit.path.path);D=svgedit.path.getPointFromGrip({x:z,y:F},svgedit.path.path);q=D.x-n.x;n=D.y-n.y;svgedit.path.path.dragging=[z,F];!h||!svgedit.path.is_linked?svgedit.path.setLinkControlPoints(false):svgedit.path.setLinkControlPoints(true);svgedit.path.path.dragctrl?svgedit.path.path.moveCtrl(q,n):svgedit.path.path.movePts(q,n)}else{svgedit.path.path.selected_pts=[];svgedit.path.path.eachSeg(function(){if(this.next||
this.prev){var ca=sa.getBBox(),T=svgedit.path.getGripPt(this);ca=svgedit.math.rectsIntersect(ca,{x:T.x,y:T.y,width:0,height:0});this.select(ca);ca&&svgedit.path.path.selected_pts.push(this.index)}})}},mouseUp:function(D,z,F,h){var n=oa("ctrlpointgrip_1c1"),q=oa("ctrlpointgrip_0c2");this.lastCtrlPoint=n?[n.getAttribute("cx"),n.getAttribute("cy")]:[F,h];if(!svgedit.path.first_grip&&q)svgedit.path.first_grip=[q.getAttribute("cx"),q.getAttribute("cy")];if(Ha==="path"){m=null;if(!A){z=oa(ba());Ka=false;
C=null}return{keep:true,element:z}}if(svgedit.path.path.dragging){z=svgedit.path.path.cur_pt;svgedit.path.path.dragging=false;svgedit.path.path.dragctrl=false;svgedit.path.path.update();G&&svgedit.path.path.endChanges("Move path point(s)");!D.shiftKey&&!G&&svgedit.path.path.selectPt(z)}else if(sa&&sa.getAttribute("display")!="none"){sa.setAttribute("display","none");sa.getAttribute("width")<=2&&sa.getAttribute("height")<=2&&La.toSelectMode(D.target)}else La.toSelectMode(D.target);G=false},toEditMode:function(D){svgedit.path.path=
this.prev){var ca=sa.getBBox(),T=svgedit.path.getGripPt(this);ca=svgedit.math.rectsIntersect(ca,{x:T.x,y:T.y,width:0,height:0});this.select(ca);ca&&svgedit.path.path.selected_pts.push(this.index)}})}},mouseUp:function(D,z,F,h){var n=oa("ctrlpointgrip_1c1"),q=oa("ctrlpointgrip_0c2");this.lastCtrlPoint=n?[n.getAttribute("cx"),n.getAttribute("cy")]:[F,h];if(!svgedit.path.first_grip)svgedit.path.first_grip=q?[q.getAttribute("cx"),q.getAttribute("cy")]:[F,h];if(Ha==="path"){m=null;if(!A){z=oa(ba());Ka=
false;C=null}return{keep:true,element:z}}if(svgedit.path.path.dragging){z=svgedit.path.path.cur_pt;svgedit.path.path.dragging=false;svgedit.path.path.dragctrl=false;svgedit.path.path.update();G&&svgedit.path.path.endChanges("Move path point(s)");!D.shiftKey&&!G&&svgedit.path.path.selectPt(z)}else if(sa&&sa.getAttribute("display")!="none"){sa.setAttribute("display","none");sa.getAttribute("width")<=2&&sa.getAttribute("height")<=2&&La.toSelectMode(D.target)}else La.toSelectMode(D.target);G=false},toEditMode:function(D){svgedit.path.path=
svgedit.path.getPath_(D);Ha="pathedit";xa();svgedit.path.path.show(true).update();svgedit.path.path.oldbbox=svgedit.utilities.getBBox(svgedit.path.path.elem);f=false},toSelectMode:function(D){var z=D==svgedit.path.path.elem;Ha="select";svgedit.path.path.show(false);k=false;xa();svgedit.path.path.matrix&&svgedit.path.recalcRotatedPath();if(z){M("selected",[D]);qb([D],true)}},addSubPath:function(D){if(D){Ha="path";f=true}else{La.clear(true);La.toEditMode(svgedit.path.path.elem)}},select:function(D){if(k===
D){La.toEditMode(D);Ha="pathedit"}else k=D},reorient:function(){var D=I[0];if(D)if(na(D)!=0){var z=new Da("Reorient path"),F={d:D.getAttribute("d"),transform:D.getAttribute("transform")};z.addSubCommand(new Ma(D,F));xa();this.resetOrientation(D);wa(z);svgedit.path.getPath_(D).show(false).matrix=null;this.clear();qb([D],true);M("changed",I)}},clear:function(D){k=null;if(A){var z=oa(ba());$(oa("path_stretch_line")).remove();D&&$(z).remove();$(oa("pathpointgrip_container")).find("*").attr("display",
"none");A=C=null;Ka=false}else Ha=="pathedit"&&this.toSelectMode();svgedit.path.path&&svgedit.path.path.init().show(false)},resetOrientation:function(D){if(D==null||D.nodeName!="path")return false;var z=R(D),F=aa(z).matrix;z.clear();D.removeAttribute("transform");z=D.pathSegList;for(var h=z.numberOfItems,n=0;n<h;++n){var q=z.getItem(n),u=q.pathSegType;if(u!=1){var E=[];$.each(["",1,2],function(H,J){var O=q["x"+J],W=q["y"+J];if(O!==undefined&&W!==undefined){O=L(O,W,F);E.splice(E.length,0,O.x,O.y)}});

View File

@ -4551,7 +4551,6 @@ var pathActions = canvas.pathActions = function() {
if (stretchy) {
var prev = seglist.getItem(index);
var lastpoint = (evt.target.id === 'pathpointgrip_0');
var lastgripx = mouse_x;
var lastgripy = mouse_y;
@ -4628,8 +4627,13 @@ var pathActions = canvas.pathActions = function() {
this.lastCtrlPoint = [lastpointgrip.getAttribute('cx'), lastpointgrip.getAttribute('cy')];
else
this.lastCtrlPoint = [mouse_x, mouse_y]
if (!svgedit.path.first_grip && firstpointgrip) {
svgedit.path.first_grip = [firstpointgrip.getAttribute('cx'), firstpointgrip.getAttribute('cy')];
if (!svgedit.path.first_grip) {
if (firstpointgrip) {
svgedit.path.first_grip = [firstpointgrip.getAttribute('cx'), firstpointgrip.getAttribute('cy')];
}
else {
svgedit.path.first_grip = [mouse_x, mouse_y];
}
}
// Create mode
if(current_mode === "path") {

View File

@ -356,8 +356,8 @@ svgedit.path.is_linked=true}else{svgedit.path.setLinkControlPoints(false);svgedi
u.setAttribute("cy",F);u.setAttribute("display","inline");D=m[0];u=m[1];n.getItem(q);var O=z/v,W=F/v;H=h?D+(D-O):H;h=h?u+(u-W):J;E.setAttribute("cx",H*v);E.setAttribute("cy",h*v);E.setAttribute("display","inline");E=svgedit.path.getCtrlLine(1);J=svgedit.path.getCtrlLine(2);ma(E,{x1:z,y1:F,x2:D*v,y2:u*v,display:"inline"});ma(J,{x1:H*v,y1:h*v,x2:D*v,y2:u*v,display:"inline"});if(q===0)C=[z,F];else{n=n.getItem(q-1);z=n.x;F=n.y;if(n.pathSegType===6){z+=z-n.x2;F+=F-n.y2}else if(C){z=C[0]/v;F=C[1]/v}svgedit.path.replacePathSeg(6,
q,[D,u,this.lastCtrlPoint[0]/v,this.lastCtrlPoint[1]/v,H,h],A)}}else if(h=this.stretchy){q=n.getItem(q);n=z;u=F;if(D.target.id==="pathpointgrip_0"&&svgedit.path.first_grip){n=svgedit.path.first_grip[0];u=svgedit.path.first_grip[1]}if(q.pathSegType===6)svgedit.path.replacePathSeg(6,1,[z,F,(this.lastCtrlPoint[0]/v||q.x+(q.x-q.x2))*v,(this.lastCtrlPoint[1]/v||q.y+(q.y-q.y2))*v,n,u],h);else C?svgedit.path.replacePathSeg(6,1,[z,F,C[0],C[1],z,F],h):svgedit.path.replacePathSeg(4,1,[z,F],h)}}}else if(svgedit.path.path.dragging){n=
svgedit.path.getPointFromGrip({x:svgedit.path.path.dragging[0],y:svgedit.path.path.dragging[1]},svgedit.path.path);D=svgedit.path.getPointFromGrip({x:z,y:F},svgedit.path.path);q=D.x-n.x;n=D.y-n.y;svgedit.path.path.dragging=[z,F];!h||!svgedit.path.is_linked?svgedit.path.setLinkControlPoints(false):svgedit.path.setLinkControlPoints(true);svgedit.path.path.dragctrl?svgedit.path.path.moveCtrl(q,n):svgedit.path.path.movePts(q,n)}else{svgedit.path.path.selected_pts=[];svgedit.path.path.eachSeg(function(){if(this.next||
this.prev){var ca=sa.getBBox(),T=svgedit.path.getGripPt(this);ca=svgedit.math.rectsIntersect(ca,{x:T.x,y:T.y,width:0,height:0});this.select(ca);ca&&svgedit.path.path.selected_pts.push(this.index)}})}},mouseUp:function(D,z,F,h){var n=oa("ctrlpointgrip_1c1"),q=oa("ctrlpointgrip_0c2");this.lastCtrlPoint=n?[n.getAttribute("cx"),n.getAttribute("cy")]:[F,h];if(!svgedit.path.first_grip&&q)svgedit.path.first_grip=[q.getAttribute("cx"),q.getAttribute("cy")];if(Ha==="path"){m=null;if(!A){z=oa(ba());Ka=false;
C=null}return{keep:true,element:z}}if(svgedit.path.path.dragging){z=svgedit.path.path.cur_pt;svgedit.path.path.dragging=false;svgedit.path.path.dragctrl=false;svgedit.path.path.update();G&&svgedit.path.path.endChanges("Move path point(s)");!D.shiftKey&&!G&&svgedit.path.path.selectPt(z)}else if(sa&&sa.getAttribute("display")!="none"){sa.setAttribute("display","none");sa.getAttribute("width")<=2&&sa.getAttribute("height")<=2&&La.toSelectMode(D.target)}else La.toSelectMode(D.target);G=false},toEditMode:function(D){svgedit.path.path=
this.prev){var ca=sa.getBBox(),T=svgedit.path.getGripPt(this);ca=svgedit.math.rectsIntersect(ca,{x:T.x,y:T.y,width:0,height:0});this.select(ca);ca&&svgedit.path.path.selected_pts.push(this.index)}})}},mouseUp:function(D,z,F,h){var n=oa("ctrlpointgrip_1c1"),q=oa("ctrlpointgrip_0c2");this.lastCtrlPoint=n?[n.getAttribute("cx"),n.getAttribute("cy")]:[F,h];if(!svgedit.path.first_grip)svgedit.path.first_grip=q?[q.getAttribute("cx"),q.getAttribute("cy")]:[F,h];if(Ha==="path"){m=null;if(!A){z=oa(ba());Ka=
false;C=null}return{keep:true,element:z}}if(svgedit.path.path.dragging){z=svgedit.path.path.cur_pt;svgedit.path.path.dragging=false;svgedit.path.path.dragctrl=false;svgedit.path.path.update();G&&svgedit.path.path.endChanges("Move path point(s)");!D.shiftKey&&!G&&svgedit.path.path.selectPt(z)}else if(sa&&sa.getAttribute("display")!="none"){sa.setAttribute("display","none");sa.getAttribute("width")<=2&&sa.getAttribute("height")<=2&&La.toSelectMode(D.target)}else La.toSelectMode(D.target);G=false},toEditMode:function(D){svgedit.path.path=
svgedit.path.getPath_(D);Ha="pathedit";xa();svgedit.path.path.show(true).update();svgedit.path.path.oldbbox=svgedit.utilities.getBBox(svgedit.path.path.elem);f=false},toSelectMode:function(D){var z=D==svgedit.path.path.elem;Ha="select";svgedit.path.path.show(false);k=false;xa();svgedit.path.path.matrix&&svgedit.path.recalcRotatedPath();if(z){M("selected",[D]);qb([D],true)}},addSubPath:function(D){if(D){Ha="path";f=true}else{La.clear(true);La.toEditMode(svgedit.path.path.elem)}},select:function(D){if(k===
D){La.toEditMode(D);Ha="pathedit"}else k=D},reorient:function(){var D=I[0];if(D)if(na(D)!=0){var z=new Da("Reorient path"),F={d:D.getAttribute("d"),transform:D.getAttribute("transform")};z.addSubCommand(new Ma(D,F));xa();this.resetOrientation(D);wa(z);svgedit.path.getPath_(D).show(false).matrix=null;this.clear();qb([D],true);M("changed",I)}},clear:function(D){k=null;if(A){var z=oa(ba());$(oa("path_stretch_line")).remove();D&&$(z).remove();$(oa("pathpointgrip_container")).find("*").attr("display",
"none");A=C=null;Ka=false}else Ha=="pathedit"&&this.toSelectMode();svgedit.path.path&&svgedit.path.path.init().show(false)},resetOrientation:function(D){if(D==null||D.nodeName!="path")return false;var z=R(D),F=aa(z).matrix;z.clear();D.removeAttribute("transform");z=D.pathSegList;for(var h=z.numberOfItems,n=0;n<h;++n){var q=z.getItem(n),u=q.pathSegType;if(u!=1){var E=[];$.each(["",1,2],function(H,J){var O=q["x"+J],W=q["y"+J];if(O!==undefined&&W!==undefined){O=L(O,W,F);E.splice(E.length,0,O.x,O.y)}});

View File

@ -4551,7 +4551,6 @@ var pathActions = canvas.pathActions = function() {
if (stretchy) {
var prev = seglist.getItem(index);
var lastpoint = (evt.target.id === 'pathpointgrip_0');
var lastgripx = mouse_x;
var lastgripy = mouse_y;
@ -4628,8 +4627,13 @@ var pathActions = canvas.pathActions = function() {
this.lastCtrlPoint = [lastpointgrip.getAttribute('cx'), lastpointgrip.getAttribute('cy')];
else
this.lastCtrlPoint = [mouse_x, mouse_y]
if (!svgedit.path.first_grip && firstpointgrip) {
svgedit.path.first_grip = [firstpointgrip.getAttribute('cx'), firstpointgrip.getAttribute('cy')];
if (!svgedit.path.first_grip) {
if (firstpointgrip) {
svgedit.path.first_grip = [firstpointgrip.getAttribute('cx'), firstpointgrip.getAttribute('cy')];
}
else {
svgedit.path.first_grip = [mouse_x, mouse_y];
}
}
// Create mode
if(current_mode === "path") {