New figure in the draw2d family "draw2d.shape.basic.Text"

How do you get words to wrap inside a box in RaphaelJS? Or in browser-based SVG in general? Text-wrapping is not built into Raphael or the SVG spec. Period.

Coming from the HTML world, I found the absence of text wrapping pretty shocking. I implement a very first version of an word wrap element in draw2d.
Available in the new test version of draw2d 4.2.3.

code snippet from the implementation if anybody thinks this part is useful for a plain raphaelJS project.

    wrappedTextAttr: function(text, width) {
        if(this.canvas ===null){
            return {text:text, width:width, height:20};
        }
        
        if(this.cachedWrappedAttr===null){
            var abc = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
            // generate a raphaelJS node and set font, font-size,...
            //
            var svgText = this.canvas.paper.text(0, 0, "").attr($.extend({},this.calculateTextAttr(),{text:abc}));
            
            // get a good estimation of a letter width...not correct but this 
            // is working for the very first draft implementation
            var letterWidth = svgText.getBBox().width / abc.length;
    
            var words = this.text.split(" ");
            var x = 0, s = [];
            for ( var i = 0; i < words.length; i++) {
                var l = words[i].length;
                if (x + (l * letterWidth) > width) {
                    s.push("\n");
                    x = 0;
                }
                x += l * letterWidth;
                s.push(words[i] + " ");
            }
            var bbox = svgText.getBBox();
            svgText.remove();
            this.cachedWrappedAttr= {text: s.join(""), width:bbox.width), height: bbox.height)};
        }
        return this.cachedWrappedAttr;
     },


blogEntryTopper