Make foreignObject with foreign content movable, resizable, rotatable

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1368 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Jeff Schiller 2010-02-10 15:32:36 +00:00
parent 5628254649
commit 98fc062e47
2 changed files with 21 additions and 1 deletions

View File

@ -87,6 +87,8 @@ function SvgCanvas(container)
var isOpera = !!window.opera, var isOpera = !!window.opera,
isWebkit = navigator.userAgent.indexOf("AppleWebKit") != -1, isWebkit = navigator.userAgent.indexOf("AppleWebKit") != -1,
support = {}, 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 // this defines which elements and attributes that we support
svgWhiteList = { svgWhiteList = {
@ -2718,6 +2720,13 @@ function BatchCommand(text) {
if (mouse_target.correspondingUseElement) if (mouse_target.correspondingUseElement)
mouse_target = 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 // go up until we hit a child of a layer
while (mouse_target.parentNode.parentNode.tagName == "g") { while (mouse_target.parentNode.parentNode.tagName == "g") {
mouse_target = mouse_target.parentNode; mouse_target = mouse_target.parentNode;
@ -6495,6 +6504,10 @@ function BatchCommand(text) {
ret = selected.getBBox(); ret = selected.getBBox();
ret.x += parseFloat(selected.getAttribute('x')); ret.x += parseFloat(selected.getAttribute('x'));
ret.y += parseFloat(selected.getAttribute('y')); 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 { } else {
try { ret = selected.getBBox(); } try { ret = selected.getBBox(); }
catch(e) { ret = null; } catch(e) { ret = null; }

View File

@ -45,10 +45,11 @@
// TODO: Test these paths: // 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" // "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" // "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("<svg xmlns='http://www.w3.org/2000/svg' width='400' x='300'>" + svgCanvas.setSvgString("<svg xmlns='http://www.w3.org/2000/svg' width='400' x='300'>" +
"<path id='p1' d='M100,100 L200,100 Z'/>" + "<path id='p1' d='M100,100 L200,100 Z'/>" +
"<path id='p2' d='M100,100 L200,100 Z'/>" + "<path id='p2' d='m 0,0 l 200,0 l 0,100 L 0,100'/>" +
"</svg>"); "</svg>");
var p1 = document.getElementById("p1"), var p1 = document.getElementById("p1"),
@ -72,6 +73,12 @@
// convert and verify segments // convert and verify segments
var d = convert(p1, true); var d = convert(p1, true);
equals(d, "m100,100l100,0z", "Converted path to relative string"); 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"); module("Transform Module");