One more attempt at namespace sanity

This commit is contained in:
Jacques Distler 2010-02-14 16:36:26 -06:00
parent 2151c8d86b
commit ee5d03dca6

View file

@ -943,6 +943,8 @@ function BatchCommand(text) {
nsMap[xlinkns] = 'xlink'; nsMap[xlinkns] = 'xlink';
nsMap[xmlns] = 'xmlns'; nsMap[xmlns] = 'xmlns';
nsMap[se_ns] = 'se'; nsMap[se_ns] = 'se';
nsMap[htmlns] = 'xhtml';
nsMap[mathns] = 'mathml';
var svgcontent = svgdoc.createElementNS(svgns, "svg"); var svgcontent = svgdoc.createElementNS(svgns, "svg");
$(svgcontent).attr({ $(svgcontent).attr({
@ -1495,8 +1497,23 @@ function BatchCommand(text) {
if(elem.id == 'svgcontent') { if(elem.id == 'svgcontent') {
// Process root element separately // Process root element separately
var res = canvas.getResolution(); var res = canvas.getResolution();
out.push(' width="' + res.w + '" height="' + res.h + '" xmlns="'+svgns+'" xmlns:xlink="'+xlinkns+'"'); out.push(' width="' + res.w + '" height="' + res.h + '" xmlns="'+svgns+'"');
var i = attrs.length;
while (i--) {
attr = attrs.item(i);
var attrVal = attr.nodeValue;
// only serialize attributes we don't use internally
if (attrVal != "" &&
$.inArray(attr.localName, ['width','height','xmlns','x','y','viewBox','id','overflow']) == -1)
{
// map various namespaces to our fixed namespace prefixes
// (the default xmlns attribute itself does not get a prefix)
if(!attr.namespaceURI || nsMap[attr.namespaceURI]) {
out.push(' '); out.push(attr.nodeName); out.push("=\"");
out.push(attrVal); out.push("\"");
}
}
}
} else { } else {
for (var i=attrs.length-1; i>=0; i--) { for (var i=attrs.length-1; i>=0; i--) {
attr = attrs.item(i); attr = attrs.item(i);
@ -1523,11 +1540,8 @@ function BatchCommand(text) {
// map various namespaces to our fixed namespace prefixes // map various namespaces to our fixed namespace prefixes
// (the default xmlns attribute itself does not get a prefix) // (the default xmlns attribute itself does not get a prefix)
if (nsMap[attr.namespaceURI] != "xmlns"|| attr.localName != "xlink") { if(!attr.namespaceURI || nsMap[attr.namespaceURI]) {
if(attr.namespaceURI && nsMap[attr.namespaceURI] && nsMap[attr.namespaceURI] != "xmlns") { out.push(attr.nodeName); out.push("=\"");
out.push(nsMap[attr.namespaceURI]+':');
}
out.push(attr.localName); out.push("=\"");
out.push(attrVal); out.push("\""); out.push(attrVal); out.push("\"");
} }
} }
@ -3034,7 +3048,7 @@ function BatchCommand(text) {
}); });
var m = svgdoc.createElementNS(mathns, 'math'); var m = svgdoc.createElementNS(mathns, 'math');
m.setAttributeNS(xmlns, 'xmlns', mathns); m.setAttributeNS(xmlns, 'xmlns', mathns);
m.setAttributeNS(mathns, 'display', 'inline'); m.setAttribute('display', 'inline');
var mi = svgdoc.createElementNS(mathns, 'mo'); var mi = svgdoc.createElementNS(mathns, 'mo');
mi.textContent = "\u03A6"; mi.textContent = "\u03A6";
m.appendChild(mi); m.appendChild(mi);