From 89ed9b3985f1a220b17770925f06ba70559cdc23 Mon Sep 17 00:00:00 2001 From: Alexis Deveria Date: Fri, 26 Feb 2010 19:44:41 +0000 Subject: [PATCH] Fixed bug on deleting first node of open path and made imported closed paths have correct end segment git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1431 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svgcanvas.js | 90 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 68 insertions(+), 22 deletions(-) diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index ff89c898..cd32665b 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -1352,6 +1352,7 @@ function BatchCommand(text) { if (node.nodeName == 'path' && attrName == 'd') { // Convert to absolute node.setAttribute('d',pathActions.convertPath(node)); + pathActions.fixEnd(node); } // for the style attribute, rewrite it in terms of XML presentational attributes if (attrName == "style") { @@ -3732,6 +3733,28 @@ function BatchCommand(text) { function retPath() { return path; } + + function resetD(p) { + p.setAttribute("d", pathActions.convertPath(p)); + } + + function insertItemBefore(elem, newseg, index) { + // Support insertItemBefore on paths for FF2 + var list = elem.pathSegList; + var len = list.numberOfItems; + var arr = []; + for(var i=0; i 0 ? sel_pts[0]-1 : 1; path.clearSelection(); - path.addPtsToSelection(sel_pt); - + + // TODO: Find right way to select point now + // path.selectPt(sel_pt); if(window.opera) { // Opera repaints incorrectly var cp = $(path.elem); cp.attr('d',cp.attr('d')); } @@ -5078,6 +5092,38 @@ function BatchCommand(text) { seg.move(diff.x, diff.y); path.endChanges("Move path point"); }, + fixEnd: function(elem) { + // Adds an extra segment if the last seg before a Z doesn't end + // at its M point + // M0,0 L0,100 L100,100 z + var segList = elem.pathSegList; + var len = segList.numberOfItems; + var last_m; + for (var i = 0; i < len; ++i) { + var item = segList.getItem(i); + if(item.pathSegType === 2) { + last_m = item; + } + + if(item.pathSegType === 1) { + var prev = segList.getItem(i-1); + if(prev.x != last_m.x && prev.y != last_m.y) { + // Add an L segment here + var newseg = elem.createSVGPathSegLinetoAbs(last_m.x, last_m.y); + if(support.pathInsertItemBefore) { + segList.insertItemBefore(newseg, i); + } else { + insertItemBefore(elem, newseg, i); + } + // Can this be done better? + pathActions.fixEnd(elem); + break; + } + + } + } + if(isWebkit) resetD(elem); + }, // Convert a path to one with only absolute or relative values convertPath: function(path, toRel) { var segList = path.pathSegList;