I need good word-wrapping handling for Java. Not too difficult, except for one wrinkle: since I'm working on an internationalized application, it needs to handle Chinese, Japanese and Korean text properly. In those languages, word wrapping occurs between characters, since the characters themselves are words and there are no spaces. Not only that, but since that text may include foreign words rendered with Latin characters, those words must be treated specially and not broken between characters like the rest of the text. Wrapping needs to be supported for both text and graphics context (coordinates expressed in either character or pixel units).
Is there an existing package that does this? I haven't seen one. If not, can anyone show me a good algorithm for handling this scenario? The code would have access to a Locale
object corresponding to the language of the text to be wrapped, if needed. A greedy algorithm (each line takes as much text as possible) is fine.