Thing-a-Day 2011 #21 - Auto-scaling Hershey fonts in JavaScript

This post used to be on Posterous. I rescued my posts before Posterous shut down and am now sharing them here.

Ok, this is kind of fun, even though the code is very naive.

I've added a height-check at the end of my line-breaking code. If there are too many lines of text to fit within the allowed space, the algorithm will rescale everything and try again:

Screenshot of web app with text area and rendered text in Hershey script font. There are many lines of text, and the font has been downsized to fit more text. It's a lot of filler text that I won't repeat here.
This isn't great for real-time text flow, but it is fine for fitting text, I think.