This is a pretty specific problem, but I'm wondering if anyone would have a brilliant solution. I'm trying to fit a string with a fixed font size in a box of arbitrary size, such that, if the whole string doesn't fit, I want to trim it and ad an ellipses (...).
So if my text is "the netherlands" I want to determine what portion of that fits in my box of arbitrary size to look something like "the nether..."
I'm using jruby, so java or ruby is fine. I can't come up with a fantastic solution, other than trimming/testing char-by-char to see if the string fits. Since it's not a fixed width font, I can't just take each char as the same width, which would make this much easier.
Any thoughts, or tips that might point me in the right direction?