Pomax/fontmetrics.js — pull request #2 by oampo (2012-01-16 16:25:20+00:00)
Title: Allow measurement of whitespace only strings

At the moment if you call something like:

```js
context.measureText(' ');
```
fontmetrics.js hangs the browser in the while loops used for text measuring because no pixels are filled. Using the standard measureText function it is possible to check the width of whitespace. This commit looks to see whether the string passed is whitespace, in which case it skips the text measuring functions, and returns sensible(ish) values for the bounds, ascent etc.

I've had to rearrange the order of the code slightly so I can put the logic into a single if statement, and I'm not certain of the value of working out the leading when we have a whitespace only string, but it gives a value so I've left in in there!

Also many thanks for the library - it's incredibly clever, incredibly useful and the project I'm working on would be a non-starter without it!