Summary of the invention
The invention provides a kind of character method for trimming and device, at least to solve the problems referred to above.
According to an aspect of the invention, it is provided a kind of character method for trimming, including: can rendering text district creating
Territory size is the control of SizeA, and after obtaining viewing area size SizeS distributing to described control, at least holds
The most following circulation of row: treat character finishing text by described control and draw, and obtain and wait for a right man to marry described in drafting
Size SizeB of symbol finishing text;In the case of the condition of not met end loop, it is judged that whether SizeB is equal to
To described, SizeS, in the case of judged result is no, treats that character finishing text cuts out or extensive according to pre-defined rule
The character of multiple predetermined number, obtains new treating that text repaired in character;Wherein, the condition of described end loop includes:
Using the urtext repaired without character as described treat character finishing text and described judged result be SizeB be less than or
In the case of SizeS, terminate described circulation, and determine the result that described urtext is character finishing, or
Person, in the circulation after first time, judged result is, in the case of SizeB is equal to SizeS, to terminate described circulation,
And determine that the result that character finishing text is character finishing is treated in obtain in last circulation new.
Preferably, in the case of described control allows line feed automatically, SizeA is highly unlimited and that length is fixing district
Territory, wherein, the length of SizeS and the length of SizeB are equal.
Preferably, in the case of described control does not allows automatically to enter a new line, SizeA is highly to fix and infinite in length
Region, wherein, the height of SizeS and the height of SizeB are equal.
Preferably, determining in the case of the SizeB result whether equal to SizeS is no, according to described pre-set pattern
Then treat that character finishing text cuts out or recovers the character of predetermined number by described, obtain new treating that text bag repaired in character
Include: determining SizeB more than in the case of SizeS, treating that text repaired in character according to described pre-defined rule by described
Cut out the character of predetermined number, obtain described new treating that text repaired in character;Determining SizeB less than SizeS's
In the case of, according to described pre-defined rule by described treat character finishing text recover predetermined number character, obtain described newly
Treat character repair text.
Preferably, described pre-defined rule includes one below: binary chop, one by one character cut out method.
Preferably, in the case of described pre-defined rule is binary chop, the condition of described end loop also includes:
In circulation after first time, judged result is that SizeB is less than obtain in SizeS, and previous cycle new and treats character
Finishing text draw after size and previous cycle before a circulation in obtain new treat that character finishing text is drawn
After equal in magnitude in the case of, terminate described circulation, and determine that character finishing literary composition is treated in obtain in previous cycle new
This is the result of character finishing.
Preferably, in the case of described pre-defined rule is described binary chop, according to described binary chop to institute
State and treat that character finishing text cuts out or recovers the character of predetermined number, obtain described new treating that text bag repaired in character
Include:
In the case of circulating at the 1st time, cut out the individual character of described text to be trimmed [LenB/2], obtain the 1st new
Text to be trimmed, wherein, LenB represent described in treat character finishing text number of characters, [] represent round
Or round up;
In the case of n-th circulates, cut out described N-1 new text [LenB/2 to be trimmedN] individual character,
Or, recover described N-1 new text [LenB/2 to be trimmedN] individual character, obtain new to be trimmed of n-th
Text, wherein, N is the integer more than 1.
Preferably, in the case of described pre-defined rule is described binary chop, according to described binary chop to institute
State and treat that character finishing text cuts out or recovers the character of predetermined number, obtain described new treating that text bag repaired in character
Include:
In the case of circulating at the 1st time, cutting out the individual character of described text to be trimmed [LenB/2], obtaining number of characters is
[LenB]1The 1st new text to be trimmed, wherein, LenB represent described in treat character finishing text number of characters,
[] represents round or rounds up;
In the case of circulating at the 2nd time, cut out described 1st new text to be trimmed [(LenB-[LenB]1)/2] individual
Character, or, recover described 1st new text to be trimmed [| (LenB-[LenB]1) |/2] individual character, obtain word
Symbol number is [LenB]2The 2nd new text to be trimmed;
In the case of n-th circulates, cut out described N-1 new text to be trimmed
[([LenB]N-2-[LenB]N-1)/2] individual character, or, recover described N-1 new text to be trimmed
[|([LenB]N-2-[LenB]N-1) |/2] individual character, obtain size for [LenB]NThe new text to be trimmed of n-th,
Wherein, N is the integer more than 2.
Preferably, in performing the circulation after described circulation primary, treat character finishing literary composition by described control to described
Originally carry out drafting to include: treating that character adds book character after repairing text described, wherein, described book character is used
Described in representing, treat that character finishing text is for by the trimmed text of character;By described control to adding described reserved word
Treat described in after symbol that character finishing text is drawn.
According to another aspect of the present invention, additionally provide a kind of character trimming device, including: processing module, it is used for
Establishment can rendering text area size be the control of SizeA, and obtains the viewing area size distributing to described control
SizeS;Loop module, at least performing the most following circulation: treat character finishing text by described control and enter
Row is drawn, and obtains size SizeB treating character finishing text described in drafting;Condition in not met end loop
In the case of, it is judged that whether SizeB is equal to SizeS, in the case of judged result is no, according to pre-defined rule to institute
State and treat that character finishing text cuts out or recovers the character of predetermined number, obtain new treating that text repaired in character;Wherein,
The condition of described end loop includes: using the urtext repaired without character as described treat character finishing text and
Described judged result is in the case of SizeB is less than or equal to SizeS, terminates described circulation, and determines described original
Text is the result of character finishing;Or, in the circulation after first time, judged result is that SizeB is equal to SizeS
In the case of, terminate described circulation, and determine that obtain in last circulation new treats that character finishing text is that character is repaiied
Whole result.
Preferably, described pre-defined rule includes one below: binary chop, one by one character cut out method.
By the present invention, using creating rendering text area size to be the control of SizeA, and control is distributed in acquisition
After viewing area size SizeS of part, at least perform the most following circulation: treat character finishing text by control
Draw, and obtain size SizeB treating character finishing text of drafting;Condition in not met end loop
In the case of, it is judged that whether SizeB is equal to SizeS, in the case of judged result is no, according to pre-defined rule to waiting for a right man to marry
Symbol finishing text cuts out or recovers the character of predetermined number, obtains new treating that text repaired in character;Wherein, described knot
The condition of Shu Xunhuan includes: using the urtext repaired without character as treat character finishing text and judged result be
In the case of SizeB is less than or equal to SizeS, end loop, and determine the result that urtext is character finishing, or
Person, in the circulation after first time, judged result is in the case of SizeB is equal to SizeS, end loop, and really
The new mode treating result that character finishing text is character finishing obtained in fixed last time circulation, solves relevant skill
Art intercepts caused problem according to word to the text exceeding layout width viewing area, improves text and show
The effect shown, thus improve the experience of user.
Detailed description of the invention
It should be noted that in the case of not conflicting, the embodiment in the application and the feature in embodiment can phases
Combination mutually.Describe the present invention below with reference to the accompanying drawings and in conjunction with the embodiments in detail.
Present embodiments providing a kind of character method for trimming, Fig. 1 is character method for trimming according to embodiments of the present invention
Schematic flow sheet, as it is shown in figure 1, this flow process comprises the steps:
Step S102, creating rendering text area size to be the control of SizeA, and obtains the display distributing to control
Area size SizeS;
Step S104, by control treat character finishing text draw, and obtain drafting treat character finishing literary composition
This size SizeB;In the case of the condition of not met end loop, it is judged that whether SizeB is equal to SizeS,
Judged result be no in the case of, according to pre-defined rule treat character finishing text cut out or recover the word of predetermined number
Symbol, obtains new treating that text repaired in character;
Wherein, step S104 will perform at least one times, until meeting the condition of end loop: will repair without character
Whole urtext as treat character finishing text and judged result be in the case of SizeB is less than or equal to SizeS,
End loop, and determine the result that urtext is character finishing, or, the circulation after first time judges knot
Fruit for SizeB equal in the case of SizeS, end loop, and determine that character is treated in obtain in last circulation new
Finishing text is the result of character finishing.
It should be noted that can be at such as one group of computer executable instructions in the step shown in the flow chart of accompanying drawing
Computer system performs, and, although show logical order in flow charts, but in some cases, can
With to be different from the step shown or described by order execution herein.
By above-mentioned steps, use repeatedly to cutting out or recover the drafting of text of predetermined number character, and to painting
Size SizeB of result processed (that i.e. draws treats that text repaired in character) and the pass of viewing area size SizeS distributed
System judges, such that it is able to search out the text size of optimum to draw, display is in the size region as SizeS.Phase
For correlation technique, based on character, text is intercepted in the present embodiment, therefore, its optimal result
Display effect will be better than the display effect of mode in correlation technique (2), it is possible to demonstrate be easier to allow user understand and
The form accepted, thus improve the experience of user.
Above-mentioned size be the region of SizeA be the control region for tentative rendering text, in order to judge tentative painting
The region shared by text of system and size are the relation in the region of SizeA.Preferably, line feed automatically is allowed at control
In the case of, SizeA is highly unlimited and that length is fixing region, wherein, the length of SizeS and the length of SizeB
Equal.
Preferably, in the case of control does not allows automatically to enter a new line, SizeA is highly to fix and the district of infinite in length
Territory, wherein, the height of SizeS and the height of SizeB are equal.
Preferably, determining in the case of the SizeB result whether equal to SizeS is no, will according to pre-defined rule
Treat that character finishing text cuts out or recovers the character of predetermined number, obtain new treating that character finishing text includes following two
Individual aspect:
(1) determining SizeB more than in the case of SizeS, will treat that character is repaired text and cut out according to pre-defined rule
The character of predetermined number, obtains new treating that text repaired in character;
(2) determine SizeB less than in the case of SizeS, will treat character finishing text recovery according to pre-defined rule
The character of predetermined number, obtains new treating that text repaired in character.
Preferably, above-mentioned pre-defined rule includes one below: binary chop, one by one character cut out method.
Wherein, character cuts out method and refers to the most fixing character intercepting text, by repeatedly cutting out word one by one
Symbol, finds optimum text size, uses character one by one to cut out method, be the text of 2^10 for a number of characters, if
To mate with the viewing area of 21 number of characters, then to need circulation to perform 2^10-21 time.In order to reduce opening of process
Pin, uses binary chop in the preferred embodiment, is the text of 2^10 similarly for a number of characters, to
Mate with the viewing area of 21 number of characters, it is only necessary to circulate 5 times and just the number of characters of text to be trimmed can be truncated to
2^5=32, it is seen then that use binary chop can be obviously improved treatment effeciency.
Preferably, it is also possible to by binary chop and one by one character cut out method and combine, such as, in the example above,
Determine number of characters 2^5=32 > 21 and in the case of 2^4=16 < 21, can cut out one by one being 2^5 by number of characters
Character, so that it is determined that the text of optimum character length.
Preferably, in the case of pre-defined rule is binary chop, the condition of end loop also includes: for the first time
In later circulation, judged result is that SizeB is less than obtain in SizeS, and previous cycle new and treats that text repaired in character
The new size after character finishing text is drawn obtained in size after drafting and the circulation of before previous cycle
In the case of equal, end loop, and determine that obtain in previous cycle new treats that character finishing text is character finishing
Result.
Preferably, in the case of pre-defined rule is binary chop, treat character finishing text according to binary chop
Cut out or recover the character of predetermined number, obtain new treating that character finishing text, during realizing, has multiple side
Formula, such as:
Mode one:
In the case of circulating at the 1st time, cut out text to be trimmed [LenB/2] individual character, obtain the 1st new to be repaired
Whole text, wherein, LenB represents the number of characters treating character finishing text, and [] represents round or upwards
Round;
In the case of n-th circulates, cut out N-1 new text [LenB/2 to be trimmedN] individual character, or
Person, recovers N-1 new text [LenB/2 to be trimmedN] individual character, obtain the text to be trimmed that n-th is new,
Wherein, N is the integer more than 1.
Mode two:
In the case of circulating at the 1st time, cutting out text to be trimmed [LenB/2] individual character, obtaining number of characters is
[LenB]1The 1st new text to be trimmed, wherein, LenB represent treat character finishing text number of characters, [] table
Show round or round up;
In the case of circulating at the 2nd time, cut out the 1st new text to be trimmed [(LenB-[LenB]1)/2] individual word
Symbol, or, recover the 1st new text to be trimmed [| (LenB-[LenB]1) |/2] individual character, obtaining number of characters is
[LenB]2The 2nd new text to be trimmed;
In the case of n-th circulates, cut out N-1 new text to be trimmed
[([LenB]N-2-[LenB]N-1)/2] individual character, or, recover N-1 new text to be trimmed
[|([LenB]N-2-[LenB]N-1) |/2] individual character, obtain size for [LenB]NThe new text to be trimmed of n-th,
Wherein, N is the integer more than 2.
Preferably, in performing the circulation after step S104, treat character finishing text by control and carry out
Drafting includes: adding book character after treating character finishing text, such as, subscribing character is " ... ", and this makes a reservation for
For expression, character treats that character finishing text is for by the trimmed text of character;By control to adding after book character
Treat that character finishing text is drawn.
The present embodiment additionally provides a kind of character trimming device, and this device is used for realizing above-mentioned character method for trimming, its tool
The process that realizes of body had carried out detailed description in embodiment of the method, did not repeated them here.
Fig. 2 is the structural representation of character trimming device according to embodiments of the present invention, as in figure 2 it is shown, this device bag
Include: processing module 22 and loop module 24, wherein, processing module 22, can rendering text area size for establishment
For the control of SizeA, and obtain viewing area size SizeS distributing to control;Loop module 24 coupled to process
Module 22, at least performing the most following circulation: the first processing unit 242 treats character finishing text by control
Draw, and obtain size SizeB treating character finishing text of drafting;Second processing unit 244 is at not met
In the case of the condition of end loop, it is judged that whether SizeB is equal to SizeS, in the case of judged result is no, root
Treat character finishing text according to pre-defined rule cut out or recover the character of predetermined number, obtain new treating character finishing literary composition
This;
Wherein, the condition of end loop includes: using the urtext repaired without character as treat character repair text
And judged result is in the case of SizeB is less than or equal to SizeS, end loop, and determine that urtext is character
The result of finishing;Or, in the circulation after first time, judged result is in the case of SizeB is equal to SizeS,
End loop, and determine that the result that character finishing text is character finishing is treated in obtain in last circulation new.
Module, unit involved in embodiments of the invention can realize by the way of software, it is also possible to pass through
The mode of hardware realizes.Described module, unit in the present embodiment can also be arranged within a processor, example
As, can be described as: a kind of processor includes processing module 22 and loop module 24.Wherein, the name of these modules
Claiming to be not intended that under certain conditions the restriction to this module itself, such as, processing module is also described as " using
Can rendering text area size be viewing area size SizeS that control is distributed in the control of SizeA acquisition in creating
Module ".
Preferably, in the case of control allows line feed automatically, SizeA is highly unlimited and that length is fixing region,
Wherein, the length of SizeS and the length of SizeB are equal.
Preferably, in the case of control does not allows automatically to enter a new line, SizeA is highly to fix and the district of infinite in length
Territory, wherein, the height of SizeS and the height of SizeB are equal.
Preferably, the second processing unit 244 is determining in the case of the SizeB result whether equal to SizeS is no also
For:
Determining SizeB more than in the case of SizeS, will treat that character is repaired text and cut out predetermined according to pre-defined rule
The character of number, obtains new treating that text repaired in character;
Determining SizeB less than in the case of SizeS, will treat that character finishing text recovers to make a reservation for according to pre-defined rule
The character of number, obtains new treating that text repaired in character.
Preferably, pre-defined rule includes one below: binary chop, one by one character cut out method.
Preferably, in the case of pre-defined rule is binary chop, the condition of end loop also includes: for the first time
In later circulation, judged result is that SizeB is less than obtain in SizeS, and previous cycle new and treats that text repaired in character
The new size after character finishing text is drawn obtained in size after drafting and the circulation of before previous cycle
In the case of equal, end loop, and determine that obtain in previous cycle new treats that character finishing text is character finishing
Result.
Preferably, in the case of pre-defined rule is binary chop, the second processing unit 244 is additionally operable to:
In the case of circulating at the 1st time, cut out text to be trimmed [LenB/2] individual character, obtain the 1st new to be repaired
Whole text, wherein, LenB represents the number of characters treating character finishing text, and [] represents round or upwards
Round;
In the case of n-th circulates, cut out N-1 new text [LenB/2 to be trimmedN] individual character, or
Person, recovers N-1 new text [LenB/2 to be trimmedN] individual character, obtain the text to be trimmed that n-th is new,
Wherein, N is the integer more than 1.
Preferably, in the case of pre-defined rule is binary chop, the second processing unit 244 is additionally operable to:
In the case of circulating at the 1st time, cutting out text to be trimmed [LenB/2] individual character, obtaining number of characters is
[LenB]1The 1st new text to be trimmed, wherein, LenB represent treat character finishing text number of characters, [] table
Show round or round up;
In the case of circulating at the 2nd time, cut out the 1st new text to be trimmed [(LenB-[LenB]1)/2] individual word
Symbol, or, recover the 1st new text to be trimmed [| (LenB-[LenB]1) |/2] individual character, obtaining number of characters is
[LenB]2The 2nd new text to be trimmed;
In the case of n-th circulates, cut out N-1 new text to be trimmed
[([LenB]N-2-[LenB]N-1)/2] individual character, or, recover N-1 new text to be trimmed
[|([LenB]N-2-[LenB]N-1) |/2] individual character, obtain size for [LenB]NThe new text to be trimmed of n-th,
Wherein, N is the integer more than 2.
Preferably, the first processing unit 242 is additionally operable to: in performing the circulation after circulation primary, treating that character is repaiied
Adding book character after whole text, wherein, for expression, book character treats that character finishing text is for trimmed by character
Text;Treat that character finishing text draw to adding after book character by control.
It is described below in conjunction with preferred embodiment.
Fig. 3 is the schematic flow sheet of character method for trimming according to the preferred embodiment of the invention.As it is shown on figure 3, this reality
The step executing example character method for trimming includes:
Step S1: size SizeS of record current control distribution.
Step S2: judge whether control arranges permission line feed (wrapping) automatically;When the situation that judged result is yes
Under, perform step S3;In the case of judged result is no, perform step S4.
Step S3: setting drafting target sizes unlimited as height, width is the width of current control.
Step S4: set the target sizes drawn unlimited as width, height is the height of current control.
Step S5: obtaining control text drawing area size is SizeA, and wherein, SizeA is step S3 or step S4
The middle area size determined.
Step S6: set urtext TextA.
Step S7: create text and draw control ControlA and SizeA is appointed as the size of control.
It is SizeB that step S8:ControlA carries out the size after being drawn.
Step S9: judge that SizeB, whether more than SizeS, wherein, in the case of judged result is no, performs step
Rapid S10;In the case of judged result is for being, perform step S11.
Step S10: current ControlA is set as the content element of control.
Step S11: length LengthTextA of recording text.
Step S12: block text according to the length of LengthTextA/2.
Step S13: length LengthTextC of record rendering text last time.
Step S14: set text TextB to be redrawn, and text size LengthTextB.
Step S15: set and treat that rendering text adds " ... " character as TextB.
Step S16: create text and draw control ControlA and SizeA is appointed as the size of control.
It is SizeC that step S17:ControlA carries out the size after being drawn.
Step S18: judge that whether SizeC is more than SizeS;Wherein, in the case of judged result is for being, perform step
Rapid S19;In the case of judged result is no, perform step S20.
Step S19: reset according to LengthTextB/2 and treat rendering text;Wherein, after performing step S19, continue to hold
Row step S17.
Step S20: round according to (LengthTextB+LengthTextC)/2 and obtain LengthTextD.
Step S21: judge that whether LengthTextD is equal to LengthTextB or LengthTextC;Wherein, when
Judged result be no in the case of, perform step S22, in the case of judged result is for being, execution step S10.
Step S22: reset according to LengthTextD length and treat rendering text;Wherein, after performing step S22, continue
Continuous execution step S17.
Obviously, those skilled in the art should be understood that each module of the above-mentioned present invention or each step can be with general
Calculating device realize, they can concentrate on single calculating device, or is distributed in multiple calculating device institute
On the network of composition, alternatively, they can realize with calculating the executable program code of device, it is thus possible to
It is stored in storing in device and is performed by calculating device, or they are fabricated to respectively each integrated circuit die
Block, or the multiple modules in them or step are fabricated to single integrated circuit module realize.So, the present invention
It is not restricted to any specific hardware and software combine.
The foregoing is only the preferred embodiments of the present invention, be not limited to the present invention, for the skill of this area
For art personnel, the present invention can have various modifications and variations.All within the spirit and principles in the present invention, made
Any modification, equivalent substitution and improvement etc., should be included within the scope of the present invention.