-
Notifications
You must be signed in to change notification settings - Fork 72
WordBreak
In versions before 0.8.5, word wrapping has been stupid simple by splitting the text by blanks. If a word did not fit into the line, it has been put to the next line. If it was not fitting a full line, it has been left as it is...resulting in an overflow:
Since 0.8.5 a new strategy has been implemented: If a word is to long to fit into a full line, it will be hard cut into pieces:
Also, a lot of people wanted to break words at certain characters if necessary (and not only at blanks). Let's see the following example text:
The new strategy currently breaks words after a hyphen, slash, comma and period. This eases up things, if there is e.g. no blank after a comma or period. Also hyphen is a perfect place to break.
Hey, I don't need no stinkin' word breaking. I want it to work as it was! No problem, you can configure it to use the old strategy if you want. Just set the legacy strategy by setting a system property:
System.setProperty(WordBreakerFactory.WORD_BREAKER_CLASS_PROPERTY,
WordBreakerFactory.LEGACY_WORD_BREAKER_CLASS_NAME);
Word breaking has been implemented as a strategy, so you might alter the existing one. Or write it completely on your own to implement a hyphenation-algorithm. Or...whatever you want. Just implement the interface WordBreaker
...
public class MySuperDuperWordBreaker implements WordBreaker {
@Override
Pair<String> breakWord(final String word,
final FontDescriptor fontDescriptor, final float maxWidth,
final boolean breakHardIfNecessary) throws IOException;
// TODO implement
}
...and register your implementation by setting the following system property:
System.setProperty(WordBreakerFactory.WORD_BREAKER_CLASS_PROPERTY,
MySuperDuperWordBreaker.class.getName());