[html5] Measure tons of text in a fast way

Ian Hickson ian at hixie.ch
Fri Feb 11 12:26:04 PST 2011

On Tue, 18 Jan 2011, Sebastian Werner wrote:
> What we need would be a method to measure text. The text only have basic 
> font formatting (font-family, line-height, font-size, font-style, etc.) 
> and all styles which should be respected are locally applied or can be 
> given through a method.

You can do this using the 2dcontext.measureText() method of the <canvas> 
element. Currently it will only give you the width, but we'll be adding 
more metrics over time.

> Alexander ("bga_" on Twitter) already suggested to use 
> Canvas.measureText, but this does not support any of the CSS font styles 
> which are important for my use case.

Which ones in particular?

Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

More information about the Help mailing list