How to easily display natural branches of various texts on the low-level interface of j2_m2.

Source: Internet
Author: User

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.