[whatwg] Still beating the drawString() dead horse...

Mathieu HENRI p01 at opera.com
Tue Nov 14 02:34:06 PST 2006

Stefan Haustein wrote:
> Hi,
> I have tried to sum up the requirements for 
> CanvasRenderingContext2D.drawString() at
> http://rhino-canvas.sf.net/www/drawstring.html
> The page contains an API proposal based on the Font/TextStyle object 
> approach that meets all those requirements, and also some motivation
> why I have implemented this approach and not one of the alternatives
> discussed here.

I still think by introducing the drawString() method into Canvas we are 
opening the same can of worms that was open in SVG.

If we go that way we will need a drawParagraph() method to draw multi 
line strings or blocks of text with wrapping and a bounding width. We 
also need to be able to stylize the text, i.e. changing the font-weight 
/ color / font-style ... of any word.

The list goes on and on ... and HTML and CSS already cover it all.

The HTMLElement.drawElement() method should be no problem to implement 
since userAgents already do render HTMLElements.

Having it return an ImageData object will make it insanely simple to 
manipulate in Canvas. The text elements/contents can easily be in the 
fall back content of the Canvas tag thus keeping it accessible. Getting 
the bounding box of an HTMLElement is no problem either in JavaScript. 
And applying gradients and patterns can be done using a fillRect() with 
the appropriate globalCompositeOperation.

Everything (almost) is there. Let's not re-invent a square wheel.

Mathieu 'p01' HENRI
JavaScript developer, Opera Software ASA

More information about the whatwg mailing list