KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to wrap text by building up a text string, and using getComputedTextLength to find out when the text goes beyond the allowed width. However, I can't find a simple way to incrementally build up the text which will work with getComputedTextLength . The general idea is: str = svgDocument.createTextNode(myText[word]); // first word on new line word++; obj = text.cloneNode(true); // new text element for this line obj.appendChild(str); svgDocument.documentElement.appendChild(obj); // reqd for getComputedTextLength? for( ; word < myText.length; word++) { next_width = obj.getComputedTextLength(); // get current line width if(next_width >= extent) break; str += " "; // add next word to the line str += myText[word]; ... } Can anyone tell me how to get this to work? Presumably str is copied rather than referenced in obj , but I've also tried putting obj.removeChild(str) and obj.appendChild(str) in the loop, but the appendChild crashes. I've also tried various combinations of moving around the documentElement.appendChild , and removing obj and re-appending it, and so on.
Tags (comma-separated)
Save Edits
Cancel