sketching out an algorithm for uh, figuring out how much to reduce font size by to get an oversized block of text to fit in a text box. its more complicated than you think
-
Show this thread
-
if the text is word-wrapped and does not contain any manual line breaks, you *should* be able to measure the vertical overflow to determine how much to reduce the font size by (it'd be proportional to the square of that value I think, there's a square/sqrt in there somewhere)
1 reply 0 retweets 4 likesShow this thread -
if there's a few manual line breaks in there, those contribute linearly to the vertical overflow, not proportional to the square, so it gets weirder in that case. I think iterating that above thing a few times would maybe converge?
1 reply 0 retweets 3 likesShow this thread -
but I'm not sure that would converge fast enough (figuring out how much overflow there is on a specific font size is not a trivial operation, so if that would take 100 iterations to converge it might actually be noticeable)
1 reply 0 retweets 1 likeShow this thread -
but shrinking linearly would 100% get text to fit, so that would be a lower bound on the font size, and shrinking sqrtdly would be an upper bound, could binary search between those (picking whichever option is "closest" each time) and probably converge in ~5-10 iterations
2 replies 0 retweets 7 likesShow this thread -
literally just doing a dumb binary search makes it converge in ~10 iterations my other things didn't seem to be good enough estimations
1 reply 0 retweets 2 likesShow this thread -
-
One of the weird things is that for some texts it will *never* actually converge to match the height of the box exactly, because adding +.000001 font size can end up adding a whole new line of text cause of word wrapping
2 replies 0 retweets 7 likesShow this thread
Oh God I hate this kind of stuff and the horrible sins I've committed to make stuff work in multiple languages
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.