diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 268c4374..9e1f7a4c 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -8610,6 +8610,8 @@ this.importSvgString = function(xmlString) { // import new svg document into our document var svg = svgdoc.importNode(newDoc.documentElement, true); + uniquifyElems(svg); + var innerw = convertToNum('width', svg.getAttribute("width")), innerh = convertToNum('height', svg.getAttribute("height")), innervb = svg.getAttribute("viewBox"), diff --git a/test/test1.html b/test/test1.html index bdf4b46a..751c66b6 100644 --- a/test/test1.html +++ b/test/test1.html @@ -2,6 +2,7 @@ + @@ -67,7 +68,7 @@ // "m 0,0 l 200,0 l 0,100 L 0,100" svgCanvas.setSvgString("" + - "" + + "" + "" + ""); @@ -79,19 +80,19 @@ equal(p1.nodeName, "path", "Expected 'path', got"); - equal(seglist.numberOfItems, 3, "Number of segments before conversion"); + equal(seglist.numberOfItems, 4, "Number of segments before conversion"); // verify segments before conversion curseg = seglist.getItem(0); - equal(curseg.pathSegTypeAsLetter, "M", "Before conversion, segment #1 type"); + equal(curseg.pathSegTypeAsLetter.toUpperCase(), "M", "Before conversion, segment #1 type"); curseg = seglist.getItem(1); - equal(curseg.pathSegTypeAsLetter, "L", "Before conversion, segment #2 type"); - curseg = seglist.getItem(2); - equal(curseg.pathSegTypeAsLetter, "Z", "Before conversion, segment #3 type" + d_abs); + equal(curseg.pathSegTypeAsLetter.toUpperCase(), "L", "Before conversion, segment #2 type"); + curseg = seglist.getItem(3); + equal(curseg.pathSegTypeAsLetter.toUpperCase(), "Z", "Before conversion, segment #3 type" + d_abs); // convert and verify segments var d = convert(p1, true); - equal(d, "m100,100l100,0z", "Converted path to relative string"); + equal(d, "m100,100l100,0l-100,0z", "Converted path to relative string"); // TODO: see why this isn't working in SVG-edit d = convert(p2, true); @@ -188,15 +189,19 @@ // This test makes sure import/export properly handles namespaced attributes test("Test importing/exporting namespaced attributes", function() { expect(5); - var set = svgCanvas.setSvgString(''+ + var setStr = svgCanvas.setSvgString(''+ '' + - '' + + '' + ''); var attrVal = document.getElementById('se_test_elem').getAttributeNS("http://svg-edit.googlecode.com", "foo"); equal(attrVal === "bar", true, "Preserved namespaced attribute on import"); - +// +// console.log('getSvgString' in svgCanvas) + var output = svgCanvas.getSvgString(); +// } catch(e) {console.log(e)} +// console.log('output',output); 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; @@ -233,9 +238,9 @@ test("Test escaping XML entities", function() { expect(3); - equal(svgCanvas.getPrivateMethods().toXml("<"), "<", "Escaped < properly"); - equal(svgCanvas.getPrivateMethods().toXml(">"), ">", "Escaped > properly"); - equal(svgCanvas.getPrivateMethods().toXml("&"), "&", "Escaped & properly"); + equal(svgCanvas.Utils.toXml("<"), "<", "Escaped < properly"); + equal(svgCanvas.Utils.toXml(">"), ">", "Escaped > properly"); + equal(svgCanvas.Utils.toXml("&"), "&", "Escaped & properly"); // TODO: what about " and ' ? });