I have a script that makes fairly complex PDF reports from a set of SVG templates. The problem is that one of them templates contains a box of text that is generated by the script. Is there a good algorithm for figuring out the font size, line spacing, and line breaks so that the text fills the box? In other words, I want to be able to specify a font, the width and height of the box in pixels, and the text, and have the script set the font size and determine where the line breaks need to be and what the line spacing should be so that the text is as large as possible within the box.