From 98fc062e475113ec53dc67456d35ca175ae11587 Mon Sep 17 00:00:00 2001 From: Jeff Schiller Date: Wed, 10 Feb 2010 15:32:36 +0000 Subject: [PATCH] Make foreignObject with foreign content movable, resizable, rotatable git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1368 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svgcanvas.js | 13 +++++++++++++ test/test1.html | 9 ++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index cbb07e46..25477427 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -87,6 +87,8 @@ function SvgCanvas(container) var isOpera = !!window.opera, isWebkit = navigator.userAgent.indexOf("AppleWebKit") != -1, support = {}, + htmlns = "http://www.w3.org/1999/xhtml", + mathns = "http://www.w3.org/1998/Math/MathML", // this defines which elements and attributes that we support svgWhiteList = { @@ -2718,6 +2720,13 @@ function BatchCommand(text) { if (mouse_target.correspondingUseElement) mouse_target = mouse_target.correspondingUseElement; + // for foreign content, go up until we find the foreignObject + if ($.inArray(mouse_target.namespaceURI, [mathns, htmlns]) != -1) { + while (mouse_target.nodeName != "foreignObject") { + mouse_target = mouse_target.parentNode; + } + } + // go up until we hit a child of a layer while (mouse_target.parentNode.parentNode.tagName == "g") { mouse_target = mouse_target.parentNode; @@ -6495,6 +6504,10 @@ function BatchCommand(text) { ret = selected.getBBox(); ret.x += parseFloat(selected.getAttribute('x')); ret.y += parseFloat(selected.getAttribute('y')); + } else if(elem.nodeName == 'foreignObject') { + ret = selected.getBBox(); + ret.x += parseFloat(selected.getAttribute('x')); + ret.y += parseFloat(selected.getAttribute('y')); } else { try { ret = selected.getBBox(); } catch(e) { ret = null; } diff --git a/test/test1.html b/test/test1.html index 873f5f5c..f7520049 100644 --- a/test/test1.html +++ b/test/test1.html @@ -45,10 +45,11 @@ // TODO: Test these paths: // "m400.00491,625.01379a1.78688,1.78688 0 1 1-3.57373,0a1.78688,1.78688 0 1 13.57373,0z" // "m36.812,15.8566c-28.03099,0 -26.28099,12.15601 -26.28099,12.15601l0.03099,12.59399h26.75v3.781h-37.37399c0,0 -17.938,-2.034 -133.00001,26.25c115.06201,28.284 130.71801,27.281 130.71801,27.281h9.34399v-13.125c0,0 -0.504,-15.656 15.40601,-15.656h26.532c0,0 14.90599,0.241 14.90599,-14.406v-24.219c0,0 2.263,-14.65601 -27.032,-14.65601zm-14.75,8.4684c2.662,0 4.813,2.151 4.813,4.813c0,2.661 -2.151,4.812 -4.813,4.812c-2.661,0 -4.812,-2.151 -4.812,-4.812c0,-2.662 2.151,-4.813 4.812,-4.813z" + // "m 0,0 l 200,0 l 0,100 L 0,100" svgCanvas.setSvgString("" + "" + - "" + + "" + ""); var p1 = document.getElementById("p1"), @@ -72,6 +73,12 @@ // convert and verify segments var d = convert(p1, true); equals(d, "m100,100l100,0z", "Converted path to relative string"); + + // TODO: see why this isn't working in SVG-edit + d = convert(p2, true); + QUnit.log(d); + d = convert(p2, false); + QUnit.log(d); }); module("Transform Module");