A text display method, device, equipment and storage medium
By cropping text according to text container parameters and character arrangement number in the web page, the problem of low cropping efficiency in the prior art is solved, and processing efficiency and terminal fluency are improved.
Patent Information
- Application Number
- CN202111644854.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-29
- Publication Date
- 2024-12-10
- Estimated Expiration
- 2041-12-29
AI Technical Summary
The prior art requires multiple processing when cropping too long text in web pages, resulting in long processing time and a large amount of resources, which can easily cause body lag and web page crashes, reducing processing efficiency and loading speed.
By obtaining the parameters of the target text and text container, determine whether it is necessary to crop. If necessary, crop the text according to the crop parameters and character arrangement number to reduce the number of crops and improve efficiency and speed.
Reduces the number of text cropping times, reduces processing time, reduces memory usage, and ensures the smoothness of the terminal.
Smart Images

Figure CN114330232B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of data processing technology, and in particular to a text display method, device and storage medium. Background Art
[0002] With the continuous development and progress of science and technology, the Internet has become an indispensable part of people's life, work and study as Internet technology gradually rises and matures. People can obtain knowledge and information through the Internet. People obtain information through the Internet, mostly using terminals and browsing the web. Some web pages will display some brief title information for people to browse.
[0003] When browsing web pages, in order to display more information on the web page, most of the information is simplified, such as by displaying part of the information on the web page or displaying a brief title. Therefore, in some cases where the text content that needs to be displayed cannot be displayed completely or the text is too long to display the second half, this part of the text needs to be cropped. Currently, text cropping is mostly done by removing one character at a time from the end. Especially when the text content is too long, the text needs to be processed multiple times, which takes a long time and consumes a lot of processing time and processing resources. In addition, more processing elements will be generated during the processing, resulting in a large amount of memory being occupied when the program is running, which can easily cause the body to freeze and the web page to crash, thereby greatly reducing processing efficiency and loading speed. Summary of the invention
[0004] The embodiments of the present disclosure at least provide a text display method, apparatus, device and storage medium.
[0005] The present disclosure provides a text display method, the method comprising:
[0006] Acquire a target text, a text container for displaying the target text, and container parameters of the text container for displaying the text in a target page;
[0007] Based on the container parameters, determining whether the target text needs to be clipped;
[0008] If the target text needs to be cropped, determining cropping parameters for the target text;
[0009] Based on the cropping parameters and the arrangement sequence numbers of the characters in the target text, cropping the target text at least once to obtain a text to be displayed;
[0010] The obtained text to be displayed is added to the text container to display the text to be displayed in the target page.
[0011] In an optional implementation manner, determining whether the target text needs to be clipped based on the container parameter includes:
[0012] Initialize the text container;
[0013] Determining a preset display height of the text container based on a preset number of display lines and a preset single-line height in the container parameters;
[0014] Adding a preset character to a preset position in the text container after initialization;
[0015] Adding the target text to the text container to which the preset characters are added, and obtaining a target display height for displaying the target text through the text container;
[0016] If the target display height is greater than the preset display height, it is determined that the target text needs to be cropped.
[0017] In an optional implementation manner, if the target text needs to be cropped, determining the cropping parameters for the target text includes:
[0018] If the target text needs to be cropped, determining cropping parameters for the target text based on the total amount of characters in the target text and the container parameters; or
[0019] If the target text needs to be cropped, obtain preset cropping parameters for the target text.
[0020] In an optional implementation, the step of performing at least one cropping on the target text based on the cropping parameters and the sequence numbers of the characters in the target text to obtain the text to be displayed includes:
[0021] Determining a first cropping position for the target text based on the arrangement sequence number of the first character and the arrangement sequence number of the last character in the target text and the cropping parameter;
[0022] The target text is cropped according to the first cropping position to obtain a first text segment where the first character in the target text is located, wherein the first text segment includes the first character in the target text and the second character corresponding to the first cropping position;
[0023] Determining whether the first text segment needs to be clipped based on the container parameter;
[0024] If necessary, continue cropping the first text segment as the target text until, after multiple croppings, the second text segment finally cropped is added to the text container and the real-time display height is less than or equal to the preset display height of the text container determined based on the container parameters, and the second text segment is used as the text to be displayed;
[0025] If not needed, the first text segment obtained by the first cutting is used as the text to be displayed.
[0026] In an optional implementation, determining the first cropping position for the target text based on the arrangement sequence number of the first character and the arrangement sequence number of the last character in the target text and the cropping parameter includes:
[0027] Determine the sum of the numerical values of the arrangement sequence number of the first character and the arrangement sequence number of the last character in the target text;
[0028] Calculate the result of calculation between the numerical value and the clipping parameter;
[0029] Rounding the calculation result to obtain a target sequence number closest to the calculation result;
[0030] The target sequence number is determined as the first cropping position.
[0031] In an optional implementation, the method includes:
[0032] When the first text segment or the second text segment as the text to be displayed is added to the text container, and the real-time display height of the text container is less than the preset display height of the text container determined based on the container parameters, the first text segment or the second text segment is used as the text segment to be spliced, and a third text segment adjacent to the text segment to be spliced in the target text is determined, wherein the third text segment includes a target character and the last character in the target text, and the target character is the first character in the target text after the last character of the text segment to be spliced;
[0033] Based on the arrangement sequence number of the characters in the third text segment and the cropping parameter, the third text segment is cropped at least once to obtain a fourth text segment, wherein a text segment obtained by splicing the fourth text segment and the text segment to be spliced is added to the text container and has a real-time display height equal to the preset display height;
[0034] The text segment obtained by splicing the text segment to be spliced and the fourth text segment is used as the text to be displayed.
[0035] In an optional implementation manner, the step of performing at least one cropping on the third text segment based on the arrangement sequence number of the characters in the third text segment and the cropping parameter to obtain the fourth text segment includes:
[0036] Determining a second cropping position for the third text segment based on the arrangement sequence number of the first character and the arrangement sequence number of the last character in the third text segment and the cropping parameter;
[0037] The third text segment is cropped according to the second cropping position to obtain a fifth text segment and a sixth text segment, wherein the fifth text segment is a text segment including the first character in the third text segment, and the sixth text segment is a text segment adjacent to the fifth text segment and including the last character in the third text segment;
[0038] When the text segment obtained by splicing the fifth text segment and the text segment to be spliced is added to the text container and the real-time display height of the text container is still less than the preset display height, the sixth text segment is used as the third text segment for further cropping, until the text segment obtained by splicing the text segment to be spliced and at least two of the fifth text segments obtained by cropping are added to the text container and the cropping is stopped when the real-time display height of the text container is equal to the preset display height;
[0039] The text segment obtained by splicing at least two of the fifth text segments obtained by cutting is used as the fourth text segment.
[0040] In an optional implementation manner, after the third text segment is cropped according to the second cropping position to obtain a fifth text segment and a sixth text segment, the method includes:
[0041] After the fifth text segment and the text segment to be spliced are spliced and added to the text container, if the real-time display height of the text container is greater than the preset display height, the fifth text segment is used as the target text for cropping until after multiple cropping, the real-time display height of the seventh text segment obtained by the last cropping and the text segment to be spliced and added to the text container after splicing is equal to the preset height, and the process stops;
[0042] The seventh text segment is used as the fourth text segment.
[0043] In an optional implementation, during the process of clipping the target text, the method includes:
[0044] For each text segment obtained by clipping, if the arrangement sequence number of the first character and the arrangement sequence number of the last character in the text segment are the same, clipping is stopped.
[0045] In an optional implementation manner, after the target text is cropped at least once based on the cropping parameters and the arrangement sequence numbers of the characters in the target text to obtain the text to be displayed, the method includes:
[0046] Detecting whether the last character in the text to be displayed is a special character that has been counted in advance and does not need to be displayed;
[0047] If so, the last character in the text to be displayed is cut off to obtain the processed text to be displayed.
[0048] The present disclosure also provides a text display device, the device comprising:
[0049] An acquisition module, used for acquiring a target text, a text container for displaying the target text, and container parameters of the text container for displaying the text in a target page;
[0050] A first determination module, used for determining whether the target text needs to be clipped based on the container parameters;
[0051] A second determination module, configured to determine a cropping parameter for the target text if the target text needs to be cropped;
[0052] A text clipping module, used for clipping the target text at least once based on the clipping parameters and the arrangement sequence numbers of the characters in the target text to obtain a text to be displayed;
[0053] The text display module is used to add the obtained text to be displayed to the text container to display the text to be displayed in the target page.
[0054] In an optional implementation manner, the first determining module is specifically configured to:
[0055] Initialize the text container;
[0056] Determining a preset display height of the text container based on a preset number of display lines and a preset single-line height in the container parameters;
[0057] Adding a preset character to a preset position in the text container after initialization;
[0058] Adding the target text to the text container to which the preset characters are added, and obtaining a target display height for displaying the target text through the text container;
[0059] If the target display height is greater than the preset display height, it is determined that the target text needs to be cropped.
[0060] In an optional implementation manner, the second determining module is specifically configured to:
[0061] If the target text needs to be cropped, determining cropping parameters for the target text based on the total amount of characters in the target text and the container parameters; or
[0062] If the target text needs to be cropped, obtain preset cropping parameters for the target text.
[0063] In an optional implementation manner, the text clipping module is specifically used to:
[0064] Determining a first cropping position for the target text based on the arrangement sequence number of the first character and the arrangement sequence number of the last character in the target text and the cropping parameter;
[0065] The target text is cropped according to the first cropping position to obtain a first text segment where the first character in the target text is located, wherein the first text segment includes the first character in the target text and the second character corresponding to the first cropping position;
[0066] Determining whether the first text segment needs to be clipped based on the container parameter;
[0067] If necessary, continue cropping the first text segment as the target text until, after multiple croppings, the second text segment finally cropped is added to the text container and the real-time display height is less than or equal to the preset display height of the text container determined based on the container parameters, and the second text segment is used as the text to be displayed;
[0068] If not needed, the first text segment obtained by the first cutting is used as the text to be displayed.
[0069] In an optional implementation manner, when the text cropping module is used to determine the first cropping position for the target text based on the arrangement sequence number of the first character and the arrangement sequence number of the last character in the target text and the cropping parameter, it is specifically used to:
[0070] Determine the sum of the numerical values of the arrangement sequence number of the first character and the arrangement sequence number of the last character in the target text;
[0071] Calculate the result of calculation between the numerical value and the clipping parameter;
[0072] Rounding the calculation result to obtain a target sequence number closest to the calculation result;
[0073] The target sequence number is determined as the first cropping position.
[0074] In an optional implementation manner, the text clipping module is further used to:
[0075] When the first text segment or the second text segment as the text to be displayed is added to the text container, and the real-time display height of the text container is less than the preset display height of the text container determined based on the container parameters, the first text segment or the second text segment is used as the text segment to be spliced, and a third text segment adjacent to the text segment to be spliced in the target text is determined, wherein the third text segment includes a target character and the last character in the target text, and the target character is the first character in the target text after the last character of the text segment to be spliced;
[0076] Based on the arrangement sequence number of the characters in the third text segment and the cropping parameter, the third text segment is cropped at least once to obtain a fourth text segment, wherein a text segment obtained by splicing the fourth text segment and the text segment to be spliced is added to the text container and has a real-time display height equal to the preset display height;
[0077] The text segment obtained by splicing the text segment to be spliced and the fourth text segment is used as the text to be displayed.
[0078] In an optional implementation manner, when the text cropping module is used to crop the third text segment at least once based on the arrangement sequence number of the characters in the third text segment and the cropping parameter to obtain the fourth text segment, it is specifically used to:
[0079] Determining a second cropping position for the third text segment based on the arrangement sequence number of the first character and the arrangement sequence number of the last character in the third text segment and the cropping parameter;
[0080] The third text segment is cropped according to the second cropping position to obtain a fifth text segment and a sixth text segment, wherein the fifth text segment is a text segment including the first character in the third text segment, and the sixth text segment is a text segment adjacent to the fifth text segment and including the last character in the third text segment;
[0081] When the text segment obtained by splicing the fifth text segment and the text segment to be spliced is added to the text container and the real-time display height of the text container is still less than the preset display height, the sixth text segment is used as the third text segment for further cropping, until the text segment obtained by splicing the text segment to be spliced and at least two of the fifth text segments obtained by cropping are added to the text container and the cropping is stopped when the real-time display height of the text container is equal to the preset display height;
[0082] A text segment obtained by splicing at least two of the fifth text segments obtained by cutting is used as the fourth text segment.
[0083] In an optional implementation manner, the text clipping module is further used to:
[0084] After the fifth text segment and the text segment to be spliced are spliced and added to the text container, if the real-time display height of the text container is greater than the preset display height, the fifth text segment is used as the target text for cropping until after multiple cropping, the real-time display height of the seventh text segment obtained by the last cropping and the text segment to be spliced and added to the text container after splicing is equal to the preset height, and the process stops;
[0085] The seventh text segment is used as the fourth text segment.
[0086] In an optional implementation manner, the text clipping module, during the process of clipping the target text, is specifically used to:
[0087] For each text segment obtained by clipping, if the arrangement sequence number of the first character and the arrangement sequence number of the last character in the text segment are the same, clipping is stopped.
[0088] In an optional implementation, the device further includes a character detection module, and the character detection module is used to:
[0089] Detecting whether the last character in the text to be displayed is a special character that has been counted in advance and does not need to be displayed;
[0090] If so, the last character in the text to be displayed is cut off to obtain the processed text to be displayed.
[0091] An embodiment of the present disclosure also provides an electronic device, including: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate through the bus, and when the machine-readable instructions are executed by the processor, the steps of the above-mentioned text display method are performed.
[0092] The embodiment of the present disclosure further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned text display method are executed.
[0093] The text display method, apparatus, device and storage medium provided by the embodiments of the present disclosure obtain a target text, a text container for displaying the target text, and container parameters of the text container for displaying the text in a target page; based on the container parameters, determine whether it is necessary to crop the target text; if it is necessary to crop the target text, determine the cropping parameters for the target text; based on the cropping parameters and the arrangement sequence number of the characters in the target text, crop the target text at least once to obtain a text to be displayed; and add the obtained text to be displayed to the text container to display the text to be displayed in the target.
[0094] In this way, by using the container parameters when displaying text in the text container, as well as the cropping parameters for the target text and the arrangement sequence numbers of the characters in the target text, the target text can be cropped at least once from the corresponding position in the target text, thereby greatly reducing the number of text cropping times and reducing the text processing time to improve the efficiency and speed of text processing. At the same time, it will also reduce the number of cropped elements to reduce the invalid occupation of the body memory to ensure the smoothness of the terminal operation.
[0095] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0096] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following is a brief introduction to the drawings required for use in the embodiments. The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present disclosure and are used together with the specification to illustrate the technical solutions of the present disclosure. It should be understood that the following drawings only illustrate certain embodiments of the present disclosure and should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can also be obtained based on these drawings without creative work.
[0097] Figure 1 A flowchart of a text display method provided by an embodiment of the present disclosure is shown;
[0098] Figure 2 A flowchart of another text display method provided by an embodiment of the present disclosure is shown;
[0099] Figure 3 A schematic diagram of clipping logic of a text display method provided in an embodiment of the present disclosure;
[0100] Figure 4 One of the schematic diagrams of a text display device provided by an embodiment of the present disclosure is shown;
[0101] Figure 5 A second schematic diagram of a text display device provided by an embodiment of the present disclosure is shown;
[0102] Figure 6 A schematic diagram of an electronic device provided by an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0103] In order to make the purpose, technical scheme and advantages of the embodiments of the present disclosure clearer, the technical scheme in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. The components of the embodiments of the present disclosure generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the present disclosure for protection, but merely represents the selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present disclosure.
[0104] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0105] The term "and / or" herein only describes an association relationship, indicating that three relationships may exist. For example, A and / or B may represent the following three situations: A exists alone, A and B exist at the same time, and B exists alone. In addition, the term "at least one" herein represents any combination of at least two of any one or more of a plurality of. For example, including at least one of A, B, and C may represent including any one or more elements selected from the set consisting of A, B, and C.
[0106] Research has found that the current method of text cropping is mostly to remove one character at a time starting from the end. Especially when the text content is too long, the text needs to be processed repeatedly, which takes a long time and consumes a lot of processing time and resources. In addition, more processing elements will be generated during the processing, resulting in a large amount of memory being occupied when the program is running, which can easily cause the body to freeze and the web page to crash, thereby greatly reducing processing efficiency and loading speed.
[0107] Based on the above research, the present disclosure provides a text display method, which obtains a target text, a text container for displaying the target text, and container parameters of the text container for displaying the text in a target page; based on the container parameters, determines whether it is necessary to crop the target text; if the target text needs to be cropped, determines the cropping parameters for the target text; based on the cropping parameters and the arrangement sequence number of the characters in the target text, crops the target text at least once to obtain a text to be displayed; and adds the obtained text to be displayed to the text container to display the text to be displayed in the target.
[0108] In this way, by using the container parameters when displaying text in the text container, as well as the cropping parameters for the target text and the arrangement sequence numbers of the characters in the target text, the target text can be cropped at least once from the corresponding position in the target text, thereby greatly reducing the number of text cropping times and reducing the text processing time to improve the efficiency and speed of text processing. At the same time, it will also reduce the number of cropped elements to reduce the invalid occupation of the body memory to ensure the smoothness of the terminal operation.
[0109] To facilitate understanding of this embodiment, a text display method disclosed in the embodiment of the present disclosure is first introduced in detail. The execution subject of the text display method provided in the embodiment of the present disclosure is generally a computer device with certain computing capabilities, and the computer device includes, for example: a terminal device or a server or other processing device, and the terminal device can be a user equipment (User Equipment, UE), a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (Personal Digital Assistant, PDA), a handheld device, a computing device, a wearable device, etc. In some possible implementations, the text display method can be implemented by a processor calling a computer-readable instruction stored in a memory.
[0110] See also Figure 1 , Figure 1 A flowchart of a text display method provided by an embodiment of the present disclosure. Figure 1 As shown in , the text display method provided by the embodiment of the present disclosure includes:
[0111] S101: Acquire a target text, a text container for displaying the target text, and container parameters of the text container for displaying the text in a target page.
[0112] In this step, when the user needs to use the terminal to browse information on the web page, the user can use the terminal to open the corresponding web page. In the web page, the brief titles of each piece of information can be displayed. At this time, for a piece of information that needs to display the brief title, the target text of this piece of information and the text container required to display the target text through the web page can be obtained. At the same time, the container parameters for displaying text in the target page using the text container, which are set in advance, can be obtained.
[0113] Among them, the container parameters set in advance may include the preset number of display lines (total number of display lines), preset number of display characters (total number of characters), and preset single-line height when the text container displays the target text. It may also include the preset number of characters per single line (the maximum number of characters that can be displayed per line), preset display height (the overall height during text display), etc. of the text container when displaying the target text.
[0114] Among them, the container parameters set in advance can be set by the user according to factors such as the user's browsing needs and page display needs, or can be the default of the web page or adjusted dynamically in real time by the web page.
[0115] S102: Determine whether it is necessary to crop the target text based on the container parameters.
[0116] In this step, after obtaining the container parameters and the target text, it can be detected whether the display of the target text through the text container exceeds the display specifications of the text container, that is, whether it meets the container parameter requirements of the text container, by comparing and matching the container parameters and the target text, so as to determine whether it is necessary to crop the target text.
[0117] Among them, the display specifications of the text container can be the display specifications under the container parameters, such as within the preset number of display lines or within the preset number of display characters, etc.
[0118] Among them, when it is necessary to display the thumbnail text or brief title of the target text on the target page through the text container, usually special characters or characters such as "abbrev." or "..." will be attached to the thumbnail text or brief title to indicate that only part of the text is displayed. These special characters or characters can be fixed display contents added in the text container, and they do not occupy the capacity of the text container for text. For example, if the maximum number of display characters of the text container is 100 characters, then due to the existence of special characters or characters, the maximum number of display characters of the text container for text is 99.
[0119] When determining whether the target text needs to be cropped, specifically, the text container can be initialized first to ensure the practicability of the text container and reduce factors that may affect the subsequent text content cropping. Then, the preset display height of the text container can be determined based on the preset number of display lines and the preset single-line height in the container parameters. That is, with the help of the preset display height and taking the preset display height as a reference, the range or amount of text allowed to display the target text in the target page can be determined, and then preset characters can be added to the preset position in the text container after initialization to occupy a position in advance, thereby directly helping to further determine the range or amount of text allowed to display the target text in the target page in the experimental stage. The preset characters can represent part of the text that cannot be displayed in the target text, and then the target text can be It is added to the text container to which the preset characters are added, so as to try to display the target text through the text container, thereby obtaining the target display height of the target text displayed through the text container, that is, the actual height when the target text is displayed on the actual web page. Furthermore, the preset display height of the text container can be determined based on the preset number of display lines and the preset single-line height in the container parameters, that is, through the preset number of display lines and the preset single-line height, the display specification allowed when the text container displays text on the target page, that is, the preset display height, can be known. Therefore, by comparing the target display height with the preset display height, it can be determined whether the target text will exceed the specification when actually displayed. Finally, if the target display height is greater than the preset display height, it can be determined that the target text needs to be cropped.
[0120] On the contrary, if the target display height is less than or equal to the preset display height, there is no need to crop the text.
[0121] In addition to the above-mentioned comparison by height, factors such as the number of words can also be used to determine whether the target text needs to be cropped. For example, the total number of characters in the target text and the preset display number of words of the text container indicated by the container parameter can be obtained. If the total number of characters in the target text is greater than the preset display number of words, it can also be determined that the target text needs to be cropped. In addition, whether the target text needs to be cropped can also be determined by the number of lines, that is, whether the number of lines to be displayed after the target text is placed in the text container exceeds the maximum display number of lines.
[0122] Exemplarily, taking the target text to be displayed as "one, two, three, four, five, six, seven, eight, nine, ten, hundred, thousand, ten thousand, hundred million", the preset number of display lines of the text container for displaying the text is 2 lines, the preset number of characters per line is 3 characters, and the preset height of a single-line text is 20 pixels as an example. Since the preset height of a single-line text is 20 pixels and the preset number of display lines is 2 lines, the preset display height allowed when displaying the text on the target page through the text container is 40 pixels. When adding the target text to the text container, because the preset number of characters per line of the text container is 3 characters, plus the special text "omitted" bound in the text container and to be displayed, the actual content to be displayed is 5 lines, and the target display height reaches 100 pixels. The target display height is much larger than the preset display height, so the target text needs to be cropped.
[0123] S103: If it is necessary to crop the target text, determine the cropping parameters for the target text.
[0124] Among them, the cropping parameters can refer to the parameters related to the cropping position, cropping amount, etc. determined when it is necessary to crop the target text.
[0125] The cropping parameters can be fixed parameters, such as the fixed parameters bound to the text container and the target page, or dynamic parameters dynamically adjusted according to the actual display situation of the target page, the text container, and the actual text situation of the target text.
[0126] Specifically, for determining the cropping parameters, when it is necessary to crop the target text, that is, if it is necessary to crop the target text, the preset cropping parameters for the target text can be directly obtained, that is, the preset fixed parameters; or when it is determined that it is necessary to crop the target text, that is, if it is necessary to crop the target text, first determine the total number of characters in the target text, and obtain the container parameters. Based on the total number of characters in the target text and the container parameters, that is, through the comparison between the parameters included in the container parameters, such as the preset number of characters per line, and the total number of characters, the cropping parameters for the target text are dynamically determined.
[0127] For example, if the total amount of characters in the target text is large, but the amount of text allowed to be displayed in the target page is small, or far less than the total amount of characters, then it can be considered that the number of times that cropping is required is large, and the cropping parameter can be appropriately increased accordingly. On the contrary, the cropping parameter can be appropriately reduced. Here, the cropping parameter can refer to the parameters indicating the position, number of words, etc. from the text end of the target text to the text front end. For example, if the cropping parameter is one third, it can be a parameter indicating the position and number of words, etc., about one third from the text end of the target text to the front.
[0128] S104: Based on the cropping parameters and the arrangement sequence numbers of the characters in the target text, the target text is cropped at least once to obtain a text to be displayed.
[0129] In this step, after determining the cropping parameters, the cropping parameters can be used, combined with the arrangement of each character in the target text, such as the arrangement sequence of each character, to determine factors such as the cropping position of a single crop in the text, the number of characters to be cropped at a single time, and then the target text can be cropped to obtain the text to be displayed.
[0130] The characters in the target text may refer to words, numbers, symbols, English words, English letters, etc. that occupy a character position.
[0131] The arrangement sequence number of each character may be a number pre-set for each character in sequence according to the number of characters and the character arrangement in the target text.
[0132] Specifically, when the target text is clipped, the following process may be performed:
[0133] Based on the arrangement sequence number of the first character and the arrangement sequence number of the last character in the target text and the cropping parameter, a first cropping position for the target text is determined.
[0134] Here, the sequence numbers of the characters in the text may be pre-added, or may be added to each character in accordance with the sequence of each character in the text after each text is obtained, wherein the sequence numbers of two adjacent characters are continuous natural numbers. The sequence numbers of each character may start from 0 and be marked 0, 1, 2, 3, ... in sequence, or may start from 1 and be expressed in sequence as 1, 2, 3, 4, ..., without any limitation.
[0135] After obtaining the arrangement number of each character, the first cropping position that can be cropped in the target text can be calculated using the arrangement numbers of the characters, such as the arrangement number of the first character and the arrangement number of the last character, and the cropping parameters obtained previously.
[0136] Specifically, to determine the first cropping position, the arrangement number of the first character and the arrangement number of the last character in the target text may be first obtained, and then calculation is performed using the numerical values of the arrangement number of the first character and the arrangement number of the last character to determine the numerical sum of the arrangement number of the first character and the arrangement number of the last character in the target text, and then the calculation result between the numerical sum and the cropping parameter is calculated. Since the calculated result may have a remainder, that is, it may contain a decimal point and a decimal after the decimal point, it is necessary to round the calculation result to obtain a target number that is closest to the calculation result, wherein the difference between the calculation result and the target number is less than or equal to the difference between the calculation result and the other number, and finally the target number is determined as the first cropping position.
[0137] Among them, the calculation method of the numerical value and the cropping parameter can be determined according to the expression form of the cropping parameter. For example, when the text needs to be cropped in two, that is, the text is cropped into two parts, in most cases, the cropping parameter can be expressed as 1 / 2, which is used to indicate cropping in half. At this time, for the calculation between the numerical value and the cropping parameter, the two can be multiplied to obtain the calculation result. On the contrary, if the cropping parameter is expressed in other ways, such as taking the binary cropping as an example, when the cropping parameter is expressed by "binary" in the binary cropping, that is, when the cropping parameter is 2, for the calculation between the numerical value and the cropping parameter, it is necessary to use the numerical value and divide the cropping parameter to obtain the calculation result.
[0138] The target sequence number is a natural number, which is one of the sequence numbers of multiple characters in the target text.
[0139] The calculation result is rounded, which can be rounded up or rounded down, or it can be dynamically determined whether to round up or round down based on the specific value of the calculation result to obtain the nearest integer, that is, the difference between the calculation result and the target sequence number is less than or equal to the difference between the calculation result and the other sequence number.
[0140] Among them, determining the target serial number as the first cropping position may refer to determining the position of the character corresponding to the target serial number as the first cropping position, that is, taking the position before or after the character corresponding to the target serial number as the first cropping position. Specifically, when cropping, it is the position before or after the character corresponding to the target serial number. The cropping position may be determined by referring to factors such as the rounding direction and the size of the cropping parameters.
[0141] For example, when determining the target serial number, it is rounded up. Then, when taking the cropping position, the position before the character corresponding to the target serial number can be used as the first cropping position to balance the effect of rounding up.
[0142] Then, the target text may be cropped according to the first cropping position to obtain a first text segment where the first character in the target text is located, wherein the first text segment includes the first character in the target text and the second character corresponding to the first cropping position.
[0143] Here, after the first cropping position is determined, the target text may be cropped at the first cropping position in the target text to obtain the cropped front text segment as the first text segment.
[0144] Here, when taking the first text segment, the text content consisting of the first character in the target text and the second character corresponding to the first cropping position is taken as the first text segment, that is, if the first cropping position is after the second character corresponding to the target sequence number, then the first text segment may include the second character, but is not limited to this. In other embodiments, for example, if the first cropping position is before the second character corresponding to the target sequence number, then the first text segment may not include the second character, that is, after cropping, the first text segment includes the first character in the target text and the second character corresponding to the first cropping position.
[0145] Next, determine whether the first text segment needs to be cropped based on the container parameters. If necessary, that is, when it is determined based on the container parameters that the first text segment needs to be cropped, continue to crop the first text segment as the target text until, after multiple croppings, the last cropped second text segment is added to the text container and the real-time display height is less than or equal to the preset display height of the text container determined based on the container parameters, and stop, and use the second text segment as the text to be displayed; if not necessary, use the first text segment obtained by the first cropping as the text to be displayed.
[0146] Here, since a single cropping often cannot produce the text to be displayed that meets the display requirements, multiple cropping operations are required. On the contrary, after the target text is cropped for the first time to obtain the first text segment, if the arrangement sequence number of the first character in the first text segment is the same as the arrangement sequence number of the last character, that is, there is only one character in the first text segment, cropping is no longer possible, and cropping can be stopped directly.
[0147] Therefore, after the first text segment is obtained by cropping for the first time, the first text segment can be detected again based on the container parameters to detect whether the first text segment needs to be cropped again. Specifically, the first text segment can be added to the text container to see the actual display height of the first text segment. Then, the actual display height can be compared with the preset display height indicated in the container parameters. If the actual display height is less than or equal to the preset display height, it can be considered that the first text segment does not need to be cropped again, and the first text segment obtained by the first cropping can be directly used as the text to be displayed.
[0148] On the contrary, if the actual display height is greater than the preset display height, then it can be considered that the first text segment needs to be cropped a second time. At this time, the first text segment can be used as the target text, and the first cropping position for the target text, that is, the first text segment, can be determined again through cropping parameters, etc. for cropping. After the second text segment is obtained by the second cropping, if it is determined again that the second text segment needs to be cropped, the second text segment can be cropped according to the above process until the second text segment obtained by the last cropping does not need to be cropped again after multiple croppings. That is, after the second text segment obtained by the last cropping is added to the text container, if the actual display height is less than or equal to the preset display height of the text container determined based on the container parameters, it is considered that cropping can be stopped. At this time, the second text segment obtained by the last cropping can be used as the text to be displayed.
[0149] After multiple cropping of the target text, if the content of the second text segment obtained by cropping, that is, the content of the text to be displayed, is compatible with the text container, for example, the actual display height is equal to the preset display height, and the number of characters in the second text segment is the same as the preset display number of characters in the text container, it can be considered to be the most appropriate cropping result. However, often in the cropping process, due to excessive cropping, the cropped second text segment cannot be exactly adapted, that is, the real-time display height of the second text segment added to the text container is less than the preset height, or although the real-time display height is equal to the preset height, the number of characters in the last line is small, resulting in less or insufficient content actually displayed on the target page. Therefore, a part of the characters after the first text segment can be cropped and spliced after the first text segment, so that the final text to be displayed is exactly adapted to the text container.
[0150] Specifically, when the target text is cropped multiple times, in the process of cropping the target text, after the first text segment or the second text segment is cropped, the first text segment or the second text segment as the text to be displayed can be added to the text container. If, when the first text segment or the second text segment as the text to be displayed is added to the text container, the real-time display height of the text container is less than the preset display height of the text container determined based on the container parameters, it can be considered that the text displayed in the target page is insufficient. At this time, the first text segment or the second text segment can be used as the text segment to be spliced, and then a third text segment adjacent to the text segment to be spliced in the target text is determined, wherein the third text segment includes a target character and the last character in the target text, and the target character is the first character in the target text after the last character of the text segment to be spliced.
[0151] Then, based on the arrangement sequence number of the characters in the third text segment and the cropping parameters, the third text segment is cropped at least once to obtain a fourth text segment. Finally, the text segment obtained by splicing the text segment to be spliced and the fourth text segment is used as the text to be displayed.
[0152] The real-time display height of the text segment obtained by splicing the fourth text segment and the text segment to be spliced is added to the text container and is equal to the preset display height.
[0153] Specifically, at least one clipping of the third text segment may be achieved through the following process:
[0154] First, the second cropping position for the third text segment may be determined based on the arrangement sequence number of the first character and the arrangement sequence number of the last character in the third text segment and the cropping parameter.
[0155] Here, the method and specific process of determining the second cropping position may be the same as the method and specific process of determining the first cropping position.
[0156] Then, the third text segment is cropped according to the second cropping position to obtain a fifth text segment and a sixth text segment, wherein the fifth text segment is a text segment including the first character in the third text segment, and the sixth text segment is a text segment adjacent to the fifth text segment and including the last character in the third text segment.
[0157] Here, after the second cropping position is determined, the third text segment may be cropped at the second cropping position in the third text segment to obtain a cropped fifth text segment and a sixth text segment.
[0158] The third text segment is a text segment including the first character in the second text segment, and the fourth text segment is a text segment adjacent to the third text segment and including the last character in the second text segment.
[0159] Here, when taking the third text segment, the first character in the second text segment, the fourth character corresponding to the second cropping position, and at least one fifth character between the first character and the fourth character in the second text segment may be used as the third text segment. Correspondingly, if the second cropping position is after the fourth character, the third text segment may include the fourth character, and if the second cropping position is before the fourth character, the third text segment may not include the fourth character.
[0160] Then, the fifth text segment obtained after cropping the third text segment is spliced with the text segment to be spliced, and the text segment obtained by splicing the fifth text segment and the text segment to be spliced is added to the text container. When the real-time display height of the text container is still less than the preset display height, the sixth text segment is cropped again as the third text segment, until the text segment obtained by splicing the text segment to be spliced and at least two of the cropped fifth text segments is added to the text container. When the real-time display height of the text container is equal to the preset display height, the cropping is stopped, and the text segment obtained by splicing at least two of the cropped fifth text segments is used as the fourth text segment.
[0161] Here, after obtaining the fifth text segment, the fifth text segment and the text segment to be spliced can be spliced, and the spliced text can be detected again. If the real-time display height of the spliced text in the text container is still less than the preset display height, then it can be considered that the spliced text is still insufficient and needs to be added. At this time, the sixth text segment obtained by cutting can be used as the third text segment for cutting again to supplement the spliced text. Specifically, the sixth text segment can be used as the third text segment, and the sixth text segment as the third text segment can be cut again according to the above process. After multiple cuttings, the text segment to be spliced and the at least two fifth text segments obtained by cutting are added to the text container. When the real-time display height of the text container is equal to the preset display height, it can be considered that all the cut texts meet the display requirements of the target page, and cutting can be stopped.
[0162] On the contrary, after obtaining the fifth text segment, the fifth text segment and the text segment to be spliced are spliced, and the fifth text segment and the text segment to be spliced are added to the text container after being spliced and then tested again. If the real-time display height of the text container is greater than the preset display height after the fifth text segment and the text segment to be spliced are added to the text container, it can be considered that the spliced text has exceeded the limit. At this time, the fifth text segment can be cropped as the target text until the real-time display height of the seventh text segment obtained by the last cropping and the text segment to be spliced are added to the text container after being spliced is equal to the preset height after multiple cropping. At this time, the seventh text segment can be used as the fourth text segment.
[0163] Furthermore, in order to align the content finally displayed on the target page with other information and ensure the integrity of each piece of information in the target page, when the sixth text segment is cropped again as the third text segment, the cropping may be stopped only when the number of characters in the text segment to be spliced and the text segment spliced after the at least two fifth text segments are cropped is equal to the preset character capacity in the text container determined based on the container parameters during multiple cropping processes.
[0164] Furthermore, since during the cropping process, each time cropping is performed, the cropped text needs to be spliced and placed in the text container for detection. To reduce the content to be detected and simplify the detection process, the arrangement sequence numbers of each character in the cropped text can also be used as a reference for comparison. Specifically, during the cropping process, when the sixth text segment is used as the third text segment for further cropping until the arrangement sequence number corresponding to the second cropping position is the same as the arrangement sequence number of the last character in the cropped third text, the cropping stops.
[0165] Finally, when the cropped second text segment is used as the text to be displayed, since a new fourth text segment that needs to be supplemented is obtained, the text segment after splicing the text segment to be spliced and the fourth text segment can be used as the text to be displayed.
[0166] Exemplarily, still taking the target text to be displayed as "one, two, three, four, five, six, seven, eight, nine, ten, hundred, thousand, ten thousand, hundred million", the preset number of display lines of the text container for displaying text is 2 lines, the preset number of characters per line is 3 characters, and the preset single-line text height is 20 pixels as an example. When it is determined that the target text needs to be cropped, the cropping parameters for the target text can be obtained, for example, 1 / 2. Taking the numbering of "one, two, three, four, five, six, seven, eight, nine, ten, hundred, thousand, ten thousand, hundred million" starting from 0 as an example, the arrangement sequence numbers of each character are 0, 1, 2, 3, …, 11, 12, 13 in sequence. The specific cropping process is as follows:
[0167] The first cropping: m = (0 + 13) / 2 = 6.5, where m is the first cropping position, 0 is the arrangement sequence number of the first character "one" in the target text, 13 is the arrangement sequence number of the last character "hundred million" in the target text. Taking rounding down as an example, here m takes 6, that is, the position where the character "seven" with the arrangement sequence number 6 is located is used as the first cropping position. Taking cropping before "seven" as an example, the first text segment obtained by the first cropping is "one, two, three, four, five, six". At this time, the first text segment is added to the text container, plus the special character "略" that needs to be displayed preset. At this time, the actual number of display lines is three lines, which is greater than the preset number of display lines 2. Therefore, the cropped first text segment needs to be used as the target text for the second cropping;
[0168] Second cut: m = (0 + 5) / 2 = 2.5, where m is the new first cut position, 0 is the new target text, i.e., the arrangement serial number of the first character 'one' in the first text segment after the first cut, 5 is the new target text, i.e., the arrangement serial number of the last character'six' in the first text segment after the first cut. Still taking rounding down as an example, here m is taken as 2, that is, the position where the character 'three' with the arrangement serial number 2 is located is used as the new first cut position. Taking cutting before 'three' as an example, the first text segment obtained from the second cut is 'one two'. At this time, the new first text segment is added to the text container, and with the addition of the preset special text 'omitted', the actual number of displayed lines is one line, which is less than the preset number of displayed lines 2, so the cutting can be stopped. However, since the content is too little when actually displayed on the target page, therefore, the first text segment obtained can be supplemented. It is necessary to cut some text from the subsequent text for splicing with the first text segment to perform text supplementation;
[0169] Third cut: m = (2 + 5) / 2 = 3.5, where m is the second cut position, 2 is the arrangement serial number of the first character 'three' in the second text after the above cut, 5 is the arrangement serial number of the character'six' corresponding to the first cut position during the first cut. Still taking rounding down as an example, here m is taken as 3, that is, the position where the character 'four' with the arrangement serial number 3 is located is used as the second cut position. Taking cutting before 'four' as an example, the third text segment obtained from the third cut is 'three'. After the first text segment and the third text segment are spliced and added to the text container, with the addition of the special text 'omitted', the actual number of displayed lines is 2 lines, which is equal to the preset number of displayed lines 2. At this time, the cutting can be stopped. However, in order to make the final text to be displayed fit exactly with the text container, the fourth text segment can be cut again:
[0170] Fourth cut: m = (3 + 5) / 2 = 4, where m is the new second cut position, 3 is the arrangement serial number of the first character 'four' in the fourth text after the above cut, 5 is the arrangement serial number of the character'six' corresponding to the first cut position during the first cut. Taking the position where the character 'five' with the arrangement serial number 4 is located as the second cut position. Taking cutting before 'five' as an example, the third text segment obtained from the fourth cut is 'four'. After the first text segment and the two obtained third text segments are spliced and added to the text container, with the addition of the special text 'omitted', the actual number of displayed lines is 2 lines, which is equal to the preset number of displayed lines 2, but there are only two characters in the second line, and more need to be added;
[0171] The fifth cut: m = (4 + 5) / 2 = 4.5. m is the new second cut position. 4 is the arrangement serial number of the first character '五' in the fourth text after the above cuts, and 5 is the arrangement serial number of the character '六' corresponding to the first cut position during the first cut. Taking the position where the character '五' with the arrangement serial number 4 is located as the second cut position. At this time, if cutting is still done before '五', the result will be the same as the previous cut result. Therefore, at this time, cutting can be done after '五'. The third text segment obtained from the fifth cut is '五'. After the first text segment and the three obtained third text segments are spliced and added to the text container, adding the special text '略', the actual displayed text is '一二三四五略', the number of displayed lines is 2, which is equal to the preset number of displayed lines 2, and the total number of characters is 6, which is the same as the preset number of displayed characters. That is, the cutting can be stopped.
[0172] S105: Add the obtained text to be displayed to the text container to display the text to be displayed on the target page.
[0173] The text display method provided by the present disclosure example includes: obtaining a target text, a text container for displaying the target text, and container parameters for the text container to display text on a target page; determining whether the target text needs to be cut based on the container parameters; if the target text needs to be cut, determining cutting parameters for the target text; performing at least one cut on the target text based on the cutting parameters and the arrangement serial numbers of the characters in the target text to obtain a text to be displayed; and adding the obtained text to be displayed to the text container to display the text to be displayed on the target page.
[0174] In this way, through the container parameters when displaying text by the text container, as well as the cutting parameters for the target text and the arrangement serial numbers of the characters in the target text, at least one cut can be performed on the target text from the corresponding position in the target text, thereby greatly reducing the number of text cuts, reducing the text processing time, improving the efficiency and speed of text processing, and at the same time reducing the number of elements cut off, reducing the ineffective occupation of the body memory to ensure the smooth operation of the terminal.
[0175] Please refer to Figure 2 , Figure 2 which is a flowchart of another text display method provided by the present disclosure example. As shown in Figure 2 , the method includes:
[0176] S201: Obtain a target text, a text container for displaying the target text, and container parameters for the text container to display text on a target page.
[0177] S202: Determine whether the target text needs to be clipped based on the container parameters.
[0178] S203: If the target text needs to be cropped, determine cropping parameters for the target text.
[0179] S204: Based on the cropping parameters and the arrangement sequence numbers of the characters in the target text, crop the target text at least once to obtain a text to be displayed.
[0180] S205: Detect whether the last character in the text to be displayed is a special character that has been counted in advance and does not need to be displayed.
[0181] In this step, after the text to be displayed is preliminarily obtained, special characters that are pre-counted and do not need to be displayed can be obtained, and the last character in the text to be displayed is matched with the special character to detect whether the last character is the special character.
[0182] The special characters may refer to punctuation marks, special symbols, calculation symbols, etc. that do not need to appear in the form of title information, etc.
[0183] S206: If yes, the last character in the text to be displayed is cut off to obtain the processed text to be displayed.
[0184] S207: Add the obtained text to be displayed to the text container to display the text to be displayed in the target page.
[0185] Please also see Figure 3 , Figure 3 A schematic diagram of the clipping logic of a text display method provided in an embodiment of the present disclosure. Figure 3As shown in, after the text container storing the text is initialized, the preset characters to be displayed at the end of the text need to be added to the text container, and then the target text is placed in the text container with the preset characters added to obtain the target display height of the target text. Furthermore, the preset display height of the text container needs to be calculated based on the preset number of display lines and the preset single-line height in the container parameters, and then the target display height is compared with the preset display height to determine whether the target text needs to be cropped. If the target display height is less than or equal to the preset display height, the current text does not need to be cropped and the processing is completed; if the target display height is greater than the preset display height, it means that the number of characters in the target text is exceeded, and the cropping stage can be entered. When the arrangement sequence number of the first character in the first text segment obtained after at least one cropping of the target text after entering the cropping stage is less than the arrangement sequence number of the last character, then Entering into a loop clipping, if the arrangement number of the first character in the first text segment obtained after at least one clipping is equal to the arrangement number of the last character, the loop clipping stage can be jumped out to obtain the text to be displayed; at the same time, if the number of characters in the first text segment obtained after the target text is clipped at least once is much smaller than the preset number of characters, the text can be clipped from the text segment adjacent to the first text segment to supplement the first text segment, and the process stops when the arrangement number of the first character in the supplemented text is equal to the arrangement number of the last character, to obtain the text to be displayed, and then the obtained text to be displayed is detected, and the last character in the text to be displayed is cyclically detected to see if it is a special character that has been pre-counted and does not need to be displayed. If so, the last character of the current text is clipped off to obtain the final text to be displayed. If not, the loop is jumped out directly to obtain the final text to be displayed.
[0186] The text display method provided by the embodiment of the present disclosure obtains a target text, a text container for displaying the target text, and container parameters of the text container for displaying the text in a target page; based on the container parameters, determines whether the target text needs to be cropped; if the target text needs to be cropped, determines the cropping parameters for the target text; based on the cropping parameters and the arrangement sequence number of the characters in the target text, crops the target text at least once to obtain a text to be displayed; detects whether the last character in the text to be displayed is a special character that has been pre-counted and does not need to be displayed; if so, crops the last character in the text to be displayed to obtain the processed text to be displayed; and adds the obtained text to be displayed to the text container to display the text to be displayed in the target.
[0187] In this way, by using the container parameters when displaying text in the text container, the cropping parameters for the target text and the arrangement sequence numbers of the characters in the target text, the target text can be cropped at least once from the corresponding position in the target text, and the last character in the text can be filtered after obtaining the text to be displayed to remove special characters that do not need to be displayed, thereby greatly reducing the number of text cropping times and reducing text processing time to improve the efficiency and speed of text processing. At the same time, the number of cropped elements will be reduced to reduce the invalid occupation of the body memory to ensure the smoothness of terminal operation.
[0188] Those skilled in the art will appreciate that, in the above method of specific implementation, the order in which the steps are written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of the steps should be determined by their functions and possible internal logic.
[0189] Based on the same inventive concept, a text display device corresponding to the text display method is also provided in the embodiment of the present disclosure. Since the principle of solving the problem by the device in the embodiment of the present disclosure is similar to the above-mentioned text display method in the embodiment of the present disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated.
[0190] See also Figure 4 and Figure 5 , Figure 4 This is one of the schematic diagrams of a text display device provided in an embodiment of the present disclosure, Figure 5 This is a second schematic diagram of a text display device provided by an example of the present disclosure. Figure 4 As shown in , the text display device 400 provided by the present disclosure example includes:
[0191] The acquisition module 410 is used to acquire the target text, a text container for displaying the target text, and container parameters of the text container for displaying the text in the target page.
[0192] The first determination module 420 is used to determine whether the target text needs to be clipped based on the container parameters.
[0193] The second determination module 430 is configured to determine cropping parameters for the target text if cropping of the target text is required.
[0194] The text clipping module 440 is used to clip the target text at least once based on the clipping parameters and the arrangement sequence numbers of the characters in the target text to obtain the text to be displayed.
[0195] The text display module 450 is used to add the obtained text to be displayed to the text container to display the text to be displayed in the target page.
[0196] In an optional implementation manner, the first determining module 420 is specifically configured to:
[0197] Initialize the text container;
[0198] Determining a preset display height of the text container based on a preset number of display lines and a preset single-line height in the container parameters;
[0199] Adding a preset character to a preset position in the text container after initialization;
[0200] Adding the target text to the text container to which the preset characters are added, and obtaining a target display height for displaying the target text through the text container;
[0201] If the target display height is greater than the preset display height, it is determined that the target text needs to be cropped.
[0202] In an optional implementation manner, the second determining module 430 is specifically configured to:
[0203] If the target text needs to be cropped, determining cropping parameters for the target text based on the total amount of characters in the target text and the container parameters; or
[0204] If the target text needs to be cropped, obtain preset cropping parameters for the target text.
[0205] In an optional implementation manner, the text clipping module 440 is specifically used for:
[0206] Determining a first cropping position for the target text based on the arrangement sequence number of the first character and the arrangement sequence number of the last character in the target text and the cropping parameter;
[0207] The target text is cropped according to the first cropping position to obtain a first text segment where the first character in the target text is located, wherein the first text segment includes the first character in the target text and the second character corresponding to the first cropping position;
[0208] Determining whether the first text segment needs to be clipped based on the container parameter;
[0209] If necessary, continue cropping the first text segment as the target text until, after multiple croppings, the second text segment finally cropped is added to the text container and the real-time display height is less than or equal to the preset display height of the text container determined based on the container parameters, and the second text segment is used as the text to be displayed;
[0210] If not needed, the first text segment obtained by the first cutting is used as the text to be displayed.
[0211] In an optional implementation manner, the text cropping module 440, when used to determine the first cropping position for the target text based on the arrangement sequence number of the first character and the arrangement sequence number of the last character in the target text and the cropping parameter, is specifically used to:
[0212] Determine the sum of the numerical values of the arrangement sequence number of the first character and the arrangement sequence number of the last character in the target text;
[0213] Calculate the result of calculation between the numerical value and the clipping parameter;
[0214] Rounding the calculation result to obtain a target sequence number closest to the calculation result;
[0215] The target sequence number is determined as the first cropping position.
[0216] In an optional implementation manner, the text clipping module 440 is further used to:
[0217] When the first text segment or the second text segment as the text to be displayed is added to the text container, and the real-time display height of the text container is less than the preset display height of the text container determined based on the container parameters, the first text segment or the second text segment is used as the text segment to be spliced, and a third text segment adjacent to the text segment to be spliced in the target text is determined, wherein the third text segment includes a target character and the last character in the target text, and the target character is the first character in the target text after the last character of the text segment to be spliced;
[0218] Based on the arrangement sequence number of the characters in the third text segment and the cropping parameter, the third text segment is cropped at least once to obtain a fourth text segment, wherein a text segment obtained by splicing the fourth text segment and the text segment to be spliced is added to the text container and has a real-time display height equal to the preset display height;
[0219] The text segment obtained by splicing the text segment to be spliced and the fourth text segment is used as the text to be displayed.
[0220] In an optional implementation manner, the text cropping module 440, when used to crop the third text segment at least once based on the arrangement sequence number of the characters in the third text segment and the cropping parameter to obtain the fourth text segment, is specifically used to:
[0221] Determining a second cropping position for the third text segment based on the arrangement sequence number of the first character and the arrangement sequence number of the last character in the third text segment and the cropping parameter;
[0222] The third text segment is cropped according to the second cropping position to obtain a fifth text segment and a sixth text segment, wherein the fifth text segment is a text segment including the first character in the third text segment, and the sixth text segment is a text segment adjacent to the fifth text segment and including the last character in the third text segment;
[0223] When the text segment obtained by splicing the fifth text segment and the text segment to be spliced is added to the text container and the real-time display height of the text container is still less than the preset display height, the sixth text segment is used as the third text segment for further cropping, until the text segment obtained by splicing the text segment to be spliced and at least two of the fifth text segments obtained by cropping are added to the text container and the cropping is stopped when the real-time display height of the text container is equal to the preset display height;
[0224] The text segment obtained by splicing at least two of the fifth text segments obtained by cutting is used as the fourth text segment.
[0225] In an optional implementation manner, after the text clipping module 440 is used to clip the third text segment according to the second clipping position to obtain the fifth text segment and the sixth text segment, it is specifically used to:
[0226] After the fifth text segment and the text segment to be spliced are spliced and added to the text container, if the real-time display height of the text container is greater than the preset display height, the fifth text segment is used as the target text for cropping until after multiple cropping, the real-time display height of the seventh text segment obtained by the last cropping and the text segment to be spliced and added to the text container after splicing is equal to the preset height, and the process stops;
[0227] The seventh text segment is used as the fourth text segment.
[0228] In an optional implementation manner, during the process of cropping the target text, the text cropping module 440 is specifically used to:
[0229] For each text segment obtained by clipping, if the arrangement sequence number of the first character and the arrangement sequence number of the last character in the text segment are the same, clipping is stopped.
[0230] In a possible implementation, Figure 5 As shown in , the text display device 400 further includes a character detection module 460, and the character detection module 460 is used to:
[0231] Detecting whether the last character in the text to be displayed is a special character that has been counted in advance and does not need to be displayed;
[0232] If so, the last character in the text to be displayed is cut off to obtain the processed text to be displayed.
[0233] The text display device proposed in the example of the present disclosure obtains a target text, a text container for displaying the target text, and container parameters of the text container for displaying the text in a target page; based on the container parameters, determines whether it is necessary to crop the target text; if it is necessary to crop the target text, determines the cropping parameters for the target text; based on the cropping parameters and the arrangement sequence number of the characters in the target text, crops the target text at least once to obtain a text to be displayed; and adds the obtained text to be displayed to the text container to display the text to be displayed in the target.
[0234] In this way, by using the container parameters when displaying text in the text container, as well as the cropping parameters for the target text and the arrangement sequence numbers of the characters in the target text, the target text can be cropped at least once from the corresponding position in the target text, thereby greatly reducing the number of text cropping times and reducing the text processing time to improve the efficiency and speed of text processing. At the same time, it will also reduce the number of cropped elements to reduce the invalid occupation of the body memory to ensure the smoothness of the terminal operation.
[0235] For descriptions of the processing flow of each module in the device and the interaction flow between each module, reference may be made to the relevant descriptions in the above method embodiment, which will not be described in detail here.
[0236] Corresponds to Figure 1 and Figure 2 The text display method in the present disclosure also provides an electronic device 600, such as Figure 6 FIG. 6 is a schematic diagram of the structure of an electronic device 600 provided in an embodiment of the present disclosure, including:
[0237] Processor 610, memory 620, and bus 630; memory 620 is used to store execution instructions, including memory 621 and external memory 622; memory 621 here is also called internal memory, which is used to temporarily store the operation data in processor 610 and the data exchanged with external memory 622 such as hard disk. Processor 610 exchanges data with external memory 622 through memory 621. When the electronic device 600 is running, the processor 610 and the memory 620 communicate through bus 630, so that the processor 610 can execute when executing. Figure 1 and Figure 2The text in the method example shown shows the steps of the method.
[0238] The present disclosure also provides a computer-readable storage medium, which stores a computer program, and when the computer program is executed by a processor, the steps of the text display method described in the above method embodiment are executed. The storage medium can be a volatile or non-volatile computer-readable storage medium.
[0239] The present disclosure also provides a computer program product that carries a program code. The program code includes instructions that can be used to execute the steps of the text display method described in the above method embodiment. For details, please refer to the above method embodiment, which will not be repeated here.
[0240] The computer program product may be implemented in hardware, software or a combination thereof. In one optional embodiment, the computer program product is implemented as a computer storage medium. In another optional embodiment, the computer program product is implemented as a software product, such as a software development kit (SDK).
[0241] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working process of the system and device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. In the several embodiments provided in the present disclosure, it should be understood that the disclosed system, device and method can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the device or unit can be electrical, mechanical or other forms.
[0242] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0243] In addition, each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0244] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present disclosure, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present disclosure. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0245] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present disclosure, which are used to illustrate the technical solutions of the present disclosure, rather than to limit them. The protection scope of the present disclosure is not limited thereto. Although the present disclosure is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed in the present disclosure, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.
Claims
1. A text display method, characterized in that: The method comprises: Acquire target text, a text container for displaying the target text, and container parameters of the text container for displaying the text in the target page; Based on the container parameters, determining whether the target text needs to be cropped; If the target text needs to be cropped, determining cropping parameters for the target text; Based on the cropping parameters and the sequence numbers of the characters in the target text, cropping the target text at least once to obtain a text to be displayed, wherein a cropping position for a first text is determined based on the sequence number of the first character in the first text, the sequence number of the last character in the first text, and the cropping parameters, and the first text is the target text or a portion of the target text; The obtained text to be displayed is added to the text container to display the text to be displayed on the target page.
2. The method according to claim 1, characterized in that The determining whether the target text needs to be clipped based on the container parameter includes: Initialize the text container; Determining a preset display height of the text container based on a preset number of display lines and a preset single-line height in the container parameters; Adding a preset character to a preset position in the initialized text container; Adding the target text to the text container to which the preset characters are added, and obtaining a target display height for displaying the target text through the text container; If the target display height is greater than the preset display height, it is determined that the target text needs to be cropped.
3. The method according to claim 1, characterized in that If the target text needs to be cropped, determining cropping parameters for the target text includes: If the target text needs to be cropped, determining cropping parameters for the target text based on the total number of characters in the target text and the container parameters; or If the target text needs to be cropped, obtain preset cropping parameters for the target text.
4. The method according to claim 1, wherein The step of cropping the target text at least once based on the cropping parameters and the sequence numbers of the characters in the target text to obtain the text to be displayed includes: Determining a first cropping position for the target text based on the arrangement sequence number of the first character and the arrangement sequence number of the last character in the target text and the cropping parameter; Cropping the target text according to the first cropping position to obtain a first text segment where the first character of the target text is located, wherein the first text segment includes the first character of the target text and a second character corresponding to the first cropping position; determining whether the first text segment needs to be clipped based on the container parameter; If necessary, continue cropping the first text segment as the target text until, after multiple cropping steps, the second text segment obtained by the last cropping is added to the text container and the real-time display height is less than or equal to the preset display height of the text container determined based on the container parameters, and then stop cropping the second text segment as the text to be displayed; If not needed, the first text segment obtained by the first cropping is used as the text to be displayed.
5. The method according to claim 4, characterized in that The determining of a first cropping position for the target text based on the arrangement sequence number of the first character and the arrangement sequence number of the last character in the target text and the cropping parameter includes: Determine the sum of the numerical values of the arrangement sequence number of the first character and the arrangement sequence number of the last character in the target text; Calculating a calculation result between the numerical value and the cropping parameter; Rounding the calculation result to obtain a target sequence number closest to the calculation result; The target sequence number is determined as the first cropping position.
6. The method according to claim 4, characterized in that The method comprises: When the first text segment or the second text segment as the text to be displayed is added to the text container, and the real-time display height of the text container is less than the preset display height of the text container determined based on the container parameters, the first text segment or the second text segment is used as the text segment to be spliced, and a third text segment adjacent to the text segment to be spliced in the target text is determined, wherein the third text segment includes a target character and the last character in the target text, and the target character is the first character in the target text after the last character of the text segment to be spliced; Based on the arrangement sequence number of the characters in the third text segment and the cropping parameter, the third text segment is cropped at least once to obtain a fourth text segment, wherein a text segment obtained by splicing the fourth text segment and the text segment to be spliced is added to the text container at a real-time display height equal to the preset display height; The text segment obtained by splicing the text segment to be spliced and the fourth text segment is used as the text to be displayed.
7. The method according to claim 6, characterized in that The step of performing at least one cropping operation on the third text segment based on the sequence number of the characters in the third text segment and the cropping parameter to obtain a fourth text segment includes: determining a second cropping position for the third text segment based on the arrangement sequence number of the first character and the arrangement sequence number of the last character in the third text segment and the cropping parameter; cropping the third text segment according to the second cropping position to obtain a fifth text segment and a sixth text segment, wherein the fifth text segment is a text segment including the first character in the third text segment, and the sixth text segment is a text segment adjacent to the fifth text segment and including the last character in the third text segment; After the fifth text segment and the text segment to be spliced are added to the text container, if the real-time display height of the text container is still less than the preset display height, cropping the sixth text segment again as the third text segment until the text segment to be spliced and at least two cropped fifth text segments are added to the text container, and cropping is stopped when the real-time display height of the text container is equal to the preset display height. The text segment obtained by splicing at least two of the fifth text segments obtained by cutting is used as the fourth text segment.
8. The method according to claim 7, characterized in that After the third text segment is cropped according to the second cropping position to obtain a fifth text segment and a sixth text segment, the method includes: After the fifth text segment and the text segment to be spliced are spliced and added to the text container, if the real-time display height of the text container is greater than the preset display height, the fifth text segment is used as the target text for cropping until, after multiple cropping steps, the real-time display height of the seventh text segment obtained by the last cropping and the text segment to be spliced and added to the text container equals the preset height; The seventh text segment is used as the fourth text segment.
9. The method according to any one of claims 1 to 8, characterized in that In the process of cropping the target text, the method includes: For each text segment obtained by clipping, if the arrangement sequence number of the first character and the arrangement sequence number of the last character in the text segment are the same, clipping is stopped.
10. The method according to claim 1, characterized in that After the target text is cropped at least once based on the cropping parameters and the sequence numbers of the characters in the target text to obtain the text to be displayed, the method includes: Detecting whether the last character in the text to be displayed is a pre-counted special character that does not need to be displayed; If so, the last character in the text to be displayed is cut off to obtain the processed text to be displayed.
11. A text display device, characterized in that: The device comprises: An acquisition module, configured to acquire a target text, a text container for displaying the target text, and container parameters of the text container for displaying the text in a target page; A first determining module, configured to determine whether the target text needs to be clipped based on the container parameters; A second determining module is configured to determine cropping parameters for the target text if cropping of the target text is required; a text cropping module, configured to crop the target text at least once based on the cropping parameters and the sequence numbers of the characters in the target text to obtain a text to be displayed, wherein a cropping position for a first text is determined based on the sequence number of the first character in the first text, the sequence number of the last character in the first text, and the cropping parameters, and the first text is the target text or a portion of the target text; The text display module is used to add the obtained text to be displayed to the text container to display the text to be displayed in the target page.
12. An electronic device, characterized in that: include: A processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the steps of the text display method as described in any one of claims 1 to 10 are performed.
13. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, which, when executed by a processor, executes the steps of the text display method according to any one of claims 1 to 10.
Citation Information
Patent Citations
Text data processing method and device, electronic equipment and readable medium
CN113408241A
