"Zoom" text to be as big as possible within constraints/box
Posted
by stolsvik
on Stack Overflow
See other posts from Stack Overflow
or by stolsvik
Published on 2010-05-14T20:30:09Z
Indexed on
2010/05/14
20:34 UTC
Read the original article
Hit count: 234
First problem: You have 400 pixels width to go on, and need to fit some text within that constraint as large as possible (thus, the text shall use that amount of space).
Throw in a new constraint: If the text is just "A", then it shall not zoom this above 100 pixels (or some specific font size).
Then, a final situation: Linebreaks. Fit some text in the largest possible way within e.g. 400 x 150 pixels.
An obvious way is to simply start with point 1, and then increase until you can't fit it anymore. This would work for all three problems, but would be very crude. The fitting of a single line within bounds could be done by writing it with some fixed point size, check the resulting pixel bounds of the text, and then simply scale it with a transform (the text scales properly too then, check out TransformUI).
Any ideas of other ways to attack this would be greatly appreciated!
© Stack Overflow or respective owner