From 52d85c6d017099ef7bddc932494a58a425022056 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Fri, 12 Feb 2010 12:34:56 -0600 Subject: [PATCH] Don't use a data-url Pass the SVG to the editor, using editor.svgCanvas.setSvgString(selected); instead. (Suggested by Jeff Schiller) Fix a bug with line and freehand tools caused by activating foreignObject tool. (Again, fix due to Jeff) Sync with SVG-Edit. --- public/javascripts/page_helper.js | 8 +- .../svg-edit/editor/images/svg_edit_icons.svg | 138 +++++++++--------- public/svg-edit/editor/svg-editor.js | 3 +- public/svg-edit/editor/svgcanvas.js | 13 +- public/svg-edit/test/test1.html | 25 ++++ 5 files changed, 110 insertions(+), 77 deletions(-) diff --git a/public/javascripts/page_helper.js b/public/javascripts/page_helper.js index 4714a6b2..30e549c6 100644 --- a/public/javascripts/page_helper.js +++ b/public/javascripts/page_helper.js @@ -82,11 +82,11 @@ function setupSVGedit(path){ f.insert({top: SVGeditButton}); SVGeditButton.disabled = true; Event.observe(SVGeditButton, 'click', function(){ + var editor = window.open(path, 'Edit SVG graphic', 'status=1,resizable=1,scrollbars=1'); if (selected) { - var editor = window.open(path +'?source=data:image/svg+xml;base64,' + window.btoa(selected), - 'Editing Existing SVG Graphic', 'status=1,resizable=1,scrollbars=1'); - } else { - var editor = window.open(path, 'Creating New SVG graphic', 'status=1,resizable=1,scrollbars=1'); + editor.addEventListener("load", function() { + editor.svgCanvas.setSvgString(selected); + }, true); } SVGeditButton.disabled = true; SVGeditButton.value = 'Create SVG graphic'; diff --git a/public/svg-edit/editor/images/svg_edit_icons.svg b/public/svg-edit/editor/images/svg_edit_icons.svg index 6e1f613d..7b73ba5b 100644 --- a/public/svg-edit/editor/images/svg_edit_icons.svg +++ b/public/svg-edit/editor/images/svg_edit_icons.svg @@ -238,91 +238,91 @@ - - - - - + - + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - - - - - - diff --git a/public/svg-edit/editor/svg-editor.js b/public/svg-edit/editor/svg-editor.js index 74d1923e..d03ca307 100644 --- a/public/svg-edit/editor/svg-editor.js +++ b/public/svg-edit/editor/svg-editor.js @@ -624,7 +624,8 @@ function svg_edit_setup() { // updates the toolbar (colors, opacity, etc) based on the selected element var updateToolbar = function() { - if (selectedElement != null && + if (selectedElement != null && + selectedElement.tagName != "foreignObject" && selectedElement.tagName != "image" && selectedElement.tagName != "g") { diff --git a/public/svg-edit/editor/svgcanvas.js b/public/svg-edit/editor/svgcanvas.js index ddc6bcb7..155e5f5e 100644 --- a/public/svg-edit/editor/svgcanvas.js +++ b/public/svg-edit/editor/svgcanvas.js @@ -976,7 +976,7 @@ function BatchCommand(text) { if($.inArray(attr, w_attrs) !== -1) { return num * res.w; - } else if($.inArray(attr, w_attrs) !== -1) { + } else if($.inArray(attr, h_attrs) !== -1) { return num * res.h; } else { return num * Math.sqrt((res.w*res.w) + (res.h*res.h))/Math.sqrt(2); @@ -1003,7 +1003,7 @@ function BatchCommand(text) { val *= 100; if($.inArray(attr, w_attrs) !== -1) { val = val / res.w; - } else if($.inArray(attr, w_attrs) !== -1) { + } else if($.inArray(attr, h_attrs) !== -1) { val = val / res.h; } else { return val / Math.sqrt((res.w*res.w) + (res.h*res.h))/Math.sqrt(2); @@ -4720,11 +4720,18 @@ function BatchCommand(text) { } // else, create a new point, append to pts array, update path element else { + // Checks if current target or parents are #svgcontent + if(!$.contains(container, evt.target)) { + // Clicked outside canvas, so don't make point + return false; + } + var lastx = current_path_pts[len-2], lasty = current_path_pts[len-1]; // we store absolute values in our path points array for easy checking above current_path_pts.push(x); current_path_pts.push(y); d_attr += "L" + round(x) + "," + round(y) + " "; + path.setAttribute("d", d_attr); // set stretchy line to latest point @@ -7743,7 +7750,7 @@ function BatchCommand(text) { // Function: getVersion // Returns a string which describes the revision number of SvgCanvas. this.getVersion = function() { - return "svgcanvas.js ($Rev: 1380 $)"; + return "svgcanvas.js ($Rev: 1382 $)"; }; this.setUiStrings = function(strs) { diff --git a/public/svg-edit/test/test1.html b/public/svg-edit/test/test1.html index f7520049..e039e372 100644 --- a/public/svg-edit/test/test1.html +++ b/public/svg-edit/test/test1.html @@ -163,6 +163,31 @@ equals(null, t.getAttribute("d"), "Imported a with a d attribute"); }); + // This test makes sure import/export properly handles namespaced attributes + test("Test importing/exporting namespaced attributes", function() { + expect(5); + var set = svgCanvas.setSvgString(''+ + '' + + '' + + ''); + var attrVal = document.getElementById('se_test_elem').getAttributeNS("http://svg-edit.googlecode.com", "foo"); + + equals(true, attrVal === "bar", "Preserved namespaced attribute on import"); + + var output = svgCanvas.getSvgString(); + var has_xlink = output.indexOf('xmlns:xlink="http://www.w3.org/1999/xlink"') !== -1; + var has_se = output.indexOf('xmlns:se=') !== -1; + var has_foo = output.indexOf('xmlns:foo=') === -1; + var has_attr = output.indexOf('se:foo="bar"') !== -1; + + equals(true, has_attr, "Preserved namespaced attribute on export"); + equals(true, has_xlink, "Included xlink: xmlns"); + equals(true, has_se, "Included se: xmlns"); + equals(true, has_foo, "Did not include foo: xmlns"); + + }); + + });