posted 15 years ago
I think FontMetrics.getHeight takes into account some extra space so the letters on two lines won't touch each other. I can't think of any other reason.
Searching for spaces is usually the best way - search for the last space, get the substring until that space, until the width is just fine.
That leaves a cutting-off technique in case splitting at spaces (or whitespace in general) would still not solve the issue because some of the words are too long. You would need to broaden your splitting character set. -, / and \ are usually good candidates as well.