A kind of display packing of multirow character
Technical field
The present invention relates to user's display interface technical field, particularly relate to a kind of display packing of multirow character.
Background technology
Present stage, when showing multirow character in viewing area, the algorithm that the most multipotency of the calculating a line adopted shows how many characters is: whether the width calculated from last character to first character exceedes the width of viewing area, the words being, just recalculate the width from second-to-last character to first character, until the width calculated is less than the width of viewing area, just shows the character of this line and enter a new line.This display mode is quick not, and operational efficiency is low, and does not disclose concrete implementation method.
Summary of the invention
The technical problem to be solved in the present invention, be the display packing providing a kind of multirow character, operational effect is high, and refreshing frequency is fast, well improves the performance of user interface.
The present invention is achieved in that 1, a kind of display packing of multirow character, comprises the steps:
Step 1, from first of this section of character that will show, until the end of newline or carriage return character or this section of character, draw the width of this section of character that will show; If the character number of this section of character is n, n is natural number;
Step 2, judge whether the width of n character exceedes the width of viewing area, is no more than, directly this line of display n character and enter a new line; Enter step 4; Exceed, then enter step 3;
Step 3, to regain from first character to the n-th character, the width of viewing area can not be exceeded, maximum character number m that can show; Show this m character again and enter a new line, wherein m<n;
After the character that step 4, skew are fallen to have shown, continue to repeat step 1, until the end of this section of character.
Further, the mode that described character number m obtains adopts dichotomy, Hash lookup or binary sort tree algorithm to obtain.
Further, the mode that described character number m obtains adopts dichotomy, and described dichotomy specific implementation is as follows:
Step 31, mark low are the first character starting position that will show, and high is the position of last character, just starts, low=1, high=n;
Step 32, obtain from low position, to the width of the character of a position, (low+high)/2;
Step 33, judge whether this width exceedes the width of viewing area, if do not exceeded, low=(low+high)/2; If exceeded, high=(low+high)/2;
Step 34, continue repeat step 32 until do not satisfy condition (high-low) >1 time exit this dichotomy, the low value at this moment obtained is exactly maximum character number m that this row can show.
Tool of the present invention has the following advantages: when the present invention by showing one section of character in viewing area, will enter a new line when exceeding the rightmost of viewing area next line automatically, or also wants enter a new line to arrive next line when run into newline or carriage return character.Like this one of display section of character can be made automatically to enter a new line, and when running into newline or carriage return character, also can automatically enter a new line, the number of comparisons calculating width in the algorithm of the maximum number of the character that often row can show is few, operational efficiency is high, improve the speed of character line feed, refresh fast, optimize user's display interface.
Accompanying drawing explanation
Fig. 1 is the inventive method schematic flow sheet.
Embodiment
Refer to shown in Fig. 1, the display packing of a kind of multirow character of the present invention, comprises the steps:
Step 1, from first of this section of character that will show, until the end of newline or carriage return character or this section of character, draw the width of this section of character that will show; If the character number of this section of character is n, n is natural number;
Step 2, judge whether the width of n character exceedes the width of viewing area, is no more than, directly this line of display n character and enter a new line; Enter step 4; Exceed, then enter step 3;
Step 3, to regain from first character to the n-th character, the width of viewing area can not be exceeded, maximum character number m that can show; Show this m character again and enter a new line, wherein m<n;
After the character that step 4, skew are fallen to have shown, continue to repeat step 1, until the end of this section of character.
Wherein, the mode that described character number m obtains adopts dichotomy, Hash lookup or binary sort tree algorithm to obtain.
Described dichotomy specific implementation is as follows:
Step 31, mark low are the first character starting position that will show, and high is the position of last character, just starts, low=1, high=n;
Step 32, obtain from low position, to the width of the character of a position, (low+high)/2;
Step 33, judge whether this width exceedes the width of viewing area, if do not exceeded, low=(low+high)/2; If exceeded, high=(low+high)/2;
Step 34, continue repeat step 32 until do not satisfy condition (high-low) >1 time exit this dichotomy, the low value at this moment obtained is exactly maximum character number m that this row can show.
The algorithm calculating the character number of often row most multipotency display adopted is very important, and adopt dichotomy few to the number of comparisons of width like this, operational effect is high, and refreshing frequency is fast, well improves the performance of user interface.
In a word, the present invention can make one of display section of character automatically enter a new line, and when running into newline or carriage return character, also can automatically enter a new line, the number of comparisons calculating width in the algorithm of the maximum number of the character that often row can show is few, and operational efficiency is high, improves the speed of character line feed, refresh fast, optimize user's display interface.
The foregoing is only preferred embodiment of the present invention, all equalizations done according to the present patent application the scope of the claims change and modify, and all should belong to covering scope of the present invention.