« me and the stl are gonna be good pals | Home | music memory »

August 10, 2004

crudmium

crud. say you've got a bounding rect


now, if you want to fit the string "bibble babble crunch" in there, obviously you're going to have to recalculate the font size because the font you're looking at now won't fit.

tragically, it seems on windows the way to do this is to guess and check until you get it right:

- do some crap to make a 12 point font
- ask windows if "bibble babble crunch" in 12 point fits in the rect
- yes? okay, try 18 point font
- ask windows if "bibble babble crunch" in 18 point fits in the rect
- no? okay, try 17 point font
- ask windows if "bibble babble crunch" in 17 point fits in the rect
- yes? okay, I guess we should use 17 point font

man, it's gonna look even worse in code. i hope i can think of a way out... i spose I won't if even the brainiacs at msft can't.

1 Comment

I was just searching for a solution to this issue. And you're right, the code is quite ugly if you do it that way.

you could simplify it with a while loop, but wouldn't it be nice if the Graphics class had a DrawStringToRect() function that would figure out the best size for the rect, and possibly center the text?

Leave a comment

About this Entry

This page contains a single entry by sainttoad published on August 10, 2004 9:17 PM.

me and the stl are gonna be good pals was the previous entry in this blog.

music memory is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.