At the moment I'm trying to render some projectnames as svg on my website. i use a webfont and on the first load, my script calculates the wrong width for the inline svg, as soon as I reload my website, the width is calculated properly. (for reproducing the error its enough to delete the browser cache)
<script>
var startup81 = function (evt) {
var svgNS = "http://www.w3.org/2000/svg";
var txtNode = document.createTextNode("D");
text = document.createElementNS(svgNS,"text");
text.setAttributeNS(null,"x",5);
text.setAttributeNS(null,"y",130);
text.setAttributeNS(null,"style","font-family:MatryoshkaL; font-size:185px;");
text.setAttributeNS(null,"fill","url(#pattern81)");
text.appendChild(txtNode);
document.getElementById("main81").appendChild(text);
var width;
width = text.getComputedTextLength() +3;
var elem = evt.target;
elem.setAttribute("width", + Math.round(width));
}
</script>
<svg id="main81" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" onload="startup81(evt)" height="168" ><defs id="defs81"><pattern x="-108" y="-71" id="pattern81" width="200" height="160" patternUnits="userSpaceOnUse" patternTransform="rotate(-35)"><image id="image81" preserveAspectRatio="none" height="160" width="200" xlink:href="http://i.imgur.com/WpE9bNB.jpg"></image></pattern></defs></svg>
As there a way to get the width of each svg rendered on the first visit?
thanks for your help