When playing games, especially when there are many conversations, such as RPG games, the problem of broken line display of text is often encountered.
How can we make the text better displayed no matter how it changes? The following function can split the text and print it row by row.
The fourth parameter is mainly set for a language where multiple letters, such as English, form a word. Because English, you cannot split a word into two rows, you can pass in some word segmentation marks, such as spaces, punctuation marks, and so on."
Chinese is irrelevant
I am not very clear about Japanese, but I don't know how it is segmented. It is the same as Chinese or English.
/** @ Todo: branch a text segment. This branch is for a certain font.
* @ Author efei
* @ Param strSource String to be split
* @ Param font Font font
* @ Param width the width to be satisfied after int Branch
* @ Param strSplit String delimiter to determine characters, such as spaces and some punctuation marks. If you do not need to break a word in Chinese, an empty string is passed.
* @ Return Vector
*/
Public Vector getSubsection (String strSource, Font font
, Int width, String strSplit ){
Vector vector = new Vector ();
String temp = strSource;
Int I, j;
Int LastLength = 1;
Int step = 0;
Try {
While (! Temp. equals ("")){
I = temp. indexOf ("");
If (I> 0 ){
If (font. stringWidth (temp. substring (0, I-1)> = width ){
I =-1;
}
}
If (I =-1 ){
If (LastLength> temp. length ()){
I = temp. length ();
} Else {
I = LastLength;
Step = font. stringWidth (temp. substring (0, I)> width? -1: 1;
// Obtain the critical point
If (I <temp. length ()){
While (! (Font. stringWidth (temp. substring (0, I) <= width
& Amp; font. stringWidth (temp. substring (0, I + 1)> width )){
I = I + step;
If (I = temp. length ())
Break;