Tweaks to svgToString() to produce slightly tidier output
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@209 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
a676614787
commit
6b7bd3eaf8
|
@ -213,7 +213,7 @@ function SvgCanvas(c)
|
||||||
var attr;
|
var attr;
|
||||||
var i;
|
var i;
|
||||||
var childs = elem.childNodes;
|
var childs = elem.childNodes;
|
||||||
for (i=0; i<indent; i++) out += " ";
|
for (i=0; i<indent; i++) out += " ";
|
||||||
out += "<" + elem.nodeName;
|
out += "<" + elem.nodeName;
|
||||||
for (i=attrs.length-1; i>=0; i--) {
|
for (i=attrs.length-1; i>=0; i--) {
|
||||||
attr = attrs.item(i);
|
attr = attrs.item(i);
|
||||||
|
@ -222,22 +222,26 @@ function SvgCanvas(c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (elem.hasChildNodes()) {
|
if (elem.hasChildNodes()) {
|
||||||
out += ">\n";
|
out += ">";
|
||||||
indent++;
|
indent++;
|
||||||
|
var bOneLine = false;
|
||||||
for (i=0; i<childs.length; i++)
|
for (i=0; i<childs.length; i++)
|
||||||
{
|
{
|
||||||
if (childs.item(i).nodeType == 1) { // element node
|
if (childs.item(i).nodeType == 1) { // element node
|
||||||
out = out + svgToString(childs.item(i), indent);
|
out += "\n" + svgToString(childs.item(i), indent);
|
||||||
} else if (childs.item(i).nodeType == 3) { // text node
|
} else if (childs.item(i).nodeType == 3) { // text node
|
||||||
for (j=0; j<indent; j++) out += " ";
|
bOneLine = true;
|
||||||
out += childs.item(i).nodeValue + "";
|
out += childs.item(i).nodeValue + "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
indent--;
|
indent--;
|
||||||
for (i=0; i<indent; i++) out += " ";
|
if (!bOneLine) {
|
||||||
out += "</" + elem.nodeName + ">\n";
|
out += "\n";
|
||||||
|
for (i=0; i<indent; i++) out += " ";
|
||||||
|
}
|
||||||
|
out += "</" + elem.nodeName + ">";
|
||||||
} else {
|
} else {
|
||||||
out += " />\n";
|
out += "/>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
|
@ -882,7 +886,8 @@ function SvgCanvas(c)
|
||||||
// remove the selected outline before serializing
|
// remove the selected outline before serializing
|
||||||
this.selectNone();
|
this.selectNone();
|
||||||
var str = "<?xml version=\"1.0\" standalone=\"no\"?>\n";
|
var str = "<?xml version=\"1.0\" standalone=\"no\"?>\n";
|
||||||
str += "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
|
// see http://jwatt.org/svg/authoring/#doctype-declaration
|
||||||
|
// str += "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
|
||||||
str += svgToString(svgroot, 0);
|
str += svgToString(svgroot, 0);
|
||||||
this.saveHandler(str);
|
this.saveHandler(str);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue