Content display method, apparatus, device, and storage medium
By obtaining the display width of each text object and performing line splitting, the problem of poor visual effects in existing technologies is solved, resulting in better content display and user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- TENCENT TECHNOLOGY (SHENZHEN) CO LTD
- Filing Date
- 2020-06-19
- Publication Date
- 2026-05-19
AI Technical Summary
Existing technologies, when processing content display by splitting it into lines based on the character width of each text object, result in poor visual effects and a bad user experience.
By obtaining the display width of each text object, line breaks are performed based on these widths to obtain the target text and display it in separate lines.
It improves the visual appeal of content display and page utilization, thereby enhancing the user experience.
Smart Images

Figure CN113822010B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a content display method, apparatus, device, and storage medium. Background Technology
[0002] With the rapid development of computer technology, more and more display pages are able to display content (such as mixed text and images) for users to browse and view. When the content to be displayed is long, it needs to be displayed in lines.
[0003] The existing technology, during content display, splits the text into lines based on the character width of each text object within the text to be processed, and then displays the content of each line separately. However, this method of splitting the text based on the character width of each text object results in poor line-breaking effects, a subpar visual presentation, and a poor user experience. Summary of the Invention
[0004] This application provides a content display method, apparatus, device, and storage medium, which can be used to improve the visual effect of content display. The technical solution is as follows:
[0005] On one hand, embodiments of this application provide a content display method, the method comprising:
[0006] Obtain the text to be processed, which consists of at least one text object arranged in sequence;
[0007] Get the display width corresponding to each text object. The display width of any text object is used to indicate the display width of the content corresponding to any text object on the display page.
[0008] Based on the display width corresponding to each of the text objects, the text to be processed is split into lines to obtain at least one line of target text.
[0009] The content corresponding to each of the at least one line of target text is displayed in separate lines on the display page.
[0010] On the other hand, a content display device is provided, the device comprising:
[0011] The first acquisition module is used to acquire the text to be processed, which is composed of at least one text object arranged in sequence.
[0012] The second acquisition module is used to acquire the display width corresponding to each text object. The display width corresponding to any text object is used to indicate the display width of the content corresponding to any text object on the display page.
[0013] The line splitting module is used to split the text to be processed into lines based on the display width of each text object, so as to obtain at least one line of target text.
[0014] The display module is used to display the content corresponding to the at least one line of target text in separate lines on the display page.
[0015] In one possible implementation, the line break processing module is configured to, starting from the first text object in the text to be processed, truncate the text based on the display width corresponding to at least one text object arranged sequentially, to obtain a first truncated text, the first truncated text consisting of a first candidate text and a truncation marker; use the width of the truncation marker as the width to be padded; obtain a first padded text based on the width to be padded and the text objects in the text to be processed that are located after the first candidate text; concatenate the first candidate text and the first padded text to obtain a first line of target text; and, in response to the line break processing operation not meeting the line break processing termination condition, use the other text in the text to be processed, excluding the first line of target text, as the updated text to be processed, and continue to obtain target text based on the updated text to be processed until the line break processing operation meets the line break processing termination condition, thus obtaining at least one line of target text.
[0016] In one possible implementation, the line break processing module is further configured to: 1) In response to the first text object to be padded following the first candidate text in the text to be processed having a display width that does not exceed the padded width, designate the first text object to be padded as the first target text object; 2) Determine an updated padded width based on the padded width and the display width corresponding to the first target text object; 3) In response to the updated padded width not meeting the width padding condition, continue to acquire target text objects based on the updated padded width and other text objects following the first candidate text in the text to be processed, until the updated padded width meets the width padding condition, and arrange the target text objects obtained when the width padding condition is met in the order of acquisition to form the first padded text, wherein the other text objects are text objects other than the first text object to be padded.
[0017] In one possible implementation, the line break processing module is further configured to, in response to the fact that the display width of the first text object to be padded after the first candidate text in the text to be processed exceeds the padded width, use the empty text as the first padded text.
[0018] In one possible implementation, the line splitting module is configured to, starting from the first text object in the text to be processed, sequentially superimpose the display widths corresponding to each text object until the superposition operation meets the superposition termination condition, and arrange the text objects whose display widths have been superimposed at the time of superposition termination in the superposition order to form the first line of target text; in response to the line splitting operation not meeting the line splitting termination condition, take the other texts in the text to be processed except for the first line of target text as the updated text to be processed, and continue to obtain target text based on the updated text to be processed until the line splitting operation meets the line splitting termination condition, thereby obtaining at least one line of target text.
[0019] In one possible implementation, the second acquisition module is configured to, in response to any text object being an image text, determine the image format corresponding to the any text object; determine the width of the image corresponding to the any text object based on the image format corresponding to the any text object; and use the width of the image corresponding to the any text object as the display width corresponding to the any text object.
[0020] In one possible implementation, the device further includes:
[0021] The detection module is used to perform line break detection on the text to be processed and obtain the detection results;
[0022] The line splitting module is used to respond to the detection result indicating that the text to be processed meets the line splitting conditions, and to perform line splitting processing on the text to be processed based on the display width corresponding to each text object.
[0023] In one possible implementation, the detection module is used to obtain the initial line number corresponding to the text to be processed, and obtain the detection result based on the initial line number; or, to truncate the text to be processed and use the truncation result as the detection result.
[0024] In one possible implementation, the device further includes:
[0025] The determination module is configured to determine, in response to a detection result indicating that the initial number of lines is greater than a reference value, that the detection result indicates that the text to be processed meets the line break processing condition; or, in response to a detection result indicating that the truncated text corresponding to the text to be processed is obtained after truncation processing, that the detection result indicates that the text to be processed meets the line break processing condition.
[0026] On the other hand, a computer device is provided, the computer device including a processor and a memory, the memory storing at least one piece of program code, the at least one piece of program code being loaded and executed by the processor to implement any of the content display methods described above.
[0027] On the other hand, a computer-readable storage medium is also provided, wherein at least one piece of program code is stored in the computer-readable storage medium, the at least one piece of program code being loaded and executed by a processor to implement any of the content display methods described above.
[0028] On the other hand, a computer program product or computer program is also provided, comprising computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform any of the content display methods described above.
[0029] The technical solution provided in this application has at least the following beneficial effects:
[0030] The text to be processed is split into lines based on the display width of each text object, and then the content corresponding to the target text after line splitting is displayed in separate lines. Since the display width of each text object indicates the display width of its content on the page, line splitting based on the display width of each text object results in better line splitting, higher page utilization, and a better visual effect, thus improving the user experience. Attached Figure Description
[0031] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0032] Figure 1 This is a schematic diagram of the implementation environment of a content display method provided in an embodiment of this application;
[0033] Figure 2 This is a flowchart of a content display method provided in an embodiment of this application;
[0034] Figure 3 This is a schematic diagram illustrating the process of splitting text into lines, as provided in an embodiment of this application.
[0035] Figure 4 This is a schematic diagram illustrating a content display process provided in an embodiment of this application;
[0036] Figure 5This is a schematic diagram of a content display device provided in an embodiment of this application;
[0037] Figure 6 This is a schematic diagram of a content display device provided in an embodiment of this application;
[0038] Figure 7 This is a schematic diagram of the structure of a content display device provided in an embodiment of this application. Detailed Implementation
[0039] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0040] With the rapid development of computer technology, more and more display pages are able to display content (such as mixed text and images) for users to browse and view. When the content to be displayed is long, it needs to be displayed in lines.
[0041] To address this, this application provides a content display method. Please refer to... Figure 1 The diagram illustrates the implementation environment of the content display method provided in this application embodiment, which includes a terminal 11 and a server 12.
[0042] The terminal 11 has an application or webpage installed that can display content. When the application or webpage needs to display content, the method provided in this embodiment can be used. The server 12 can store the text to be processed corresponding to the content to be displayed. The terminal 11 can obtain the text to be processed from the server 12, and then perform line-by-line processing on the text to be processed to achieve line-by-line display of the content to be displayed. Alternatively, the terminal 11 can also store the text to be processed corresponding to the content to be displayed. The terminal 11 can directly extract the text to be processed locally, and then perform line-by-line processing on the text to be processed to achieve line-by-line display of the content to be displayed.
[0043] In one possible implementation, terminal 11 is any electronic product capable of human-computer interaction with a user through one or more methods such as a keyboard, touchpad, touchscreen, remote control, voice interaction, or handwriting device. Examples include PCs (Personal Computers), mobile phones, smartphones, PDAs (Personal Digital Assistants), wearable devices, Pocket PCs, tablets, smart car systems, smart TVs, and smart speakers. Server 12 is a single server, a server cluster consisting of multiple servers, or a cloud computing service center. Terminal 11 and server 12 establish a communication connection via wired or wireless network.
[0044] Those skilled in the art should understand that the above-described terminal 11 and server 12 are merely examples. Other existing or future terminals or servers that are applicable to this application should also be included within the scope of protection of this application, and are hereby incorporated by reference.
[0045] Based on the above Figure 1 The implementation environment shown in this application provides a content display method, taking the application of this method to terminal 11 as an example. Figure 2 As shown, the method provided in this application embodiment may include the following steps:
[0046] In step 201, the text to be processed is obtained, which consists of at least one text object arranged in sequence.
[0047] The text to be processed refers to the text corresponding to the content to be displayed. The content to be displayed is used to show the content on the display page for interactive objects to browse and view, while the text to be processed is used for recognition and processing by computer devices. In other words, the text to be processed refers to the text that can be recognized and processed by computer devices after the content to be displayed has been converted. In the embodiments of this application, the content to be displayed can refer to content of any form. For example, the content to be displayed includes at least one of text and images. Text includes, but is not limited to, Chinese characters, numbers, letters, punctuation marks, etc.
[0048] The text to be processed consists of at least one text object arranged sequentially. Since the text to be processed is obtained by converting the content to be displayed, each piece of content (text, images, etc.) is converted into a text object during the conversion process. Therefore, the text to be processed consists of at least one text object arranged sequentially. If the content to be displayed includes at least one of text and an image, the at least one text object constituting the text to be processed includes at least one text object and / or at least one image object. In one possible implementation, if the content to be displayed includes both images and text, during the conversion process, images are converted into image text, and text is converted into text. In this case, the at least one text object constituting the text to be displayed includes at least one image object and at least one text object.
[0049] In one possible implementation, the process of obtaining the text to be processed is as follows: obtaining the content to be displayed; converting the content to be displayed to obtain the text to be processed corresponding to the content to be displayed. Since the content to be displayed includes at least one of images and text, the process of converting the content to be displayed includes at least one of converting images and converting text.
[0050] In one possible implementation, image conversion refers to encoding the image according to its image format. After encoding, the encoded characters corresponding to the image are used as the image text. This application does not limit the encoding method used for image encoding; the encoding method can be selected based on experience or flexibly adjusted according to the image format. It should be noted that image format refers to the format in which computer devices store images, such as JPEG (Joint Photographic Experts Group), GIF (Graphics Interchange Format), and BMP (Bitmap) formats. Images of different formats can use the same encoding method or different encoding methods; this application does not limit this. For example, Huffman coding is used to encode images of all formats.
[0051] In one possible implementation, text conversion refers to encoding the text. After encoding, the encoded characters corresponding to the text are used as the corresponding text. This application does not limit the encoding method used for text encoding; different types of text can use the same encoding method or different encoding methods. For example, Chinese characters are encoded using Unicode (a unified character encoding standard); alphabetic characters are encoded using ASCII (American Standard Code for Information Interchange).
[0052] It should be noted that when the content to be displayed includes both text and images, after the content is converted, each piece of text corresponds to a text object in the text to be processed, and each image corresponds to an image object in the text to be processed. In this embodiment, each text object or each image object is treated as a text object, and these text objects are arranged sequentially to form the text to be processed. The arrangement order of the text objects is consistent with the arrangement order of the text or image corresponding to each text object in the content to be displayed.
[0053] Both text and image text are in the form of encoded characters in the text to be processed. Any text or image text may consist of one or more encoded sub-characters. It should be noted that this application does not limit the number of encoded sub-characters constituting text or image text. For example, the number of encoded sub-characters constituting text is related to the type of the text. For instance, when the corresponding text type is Chinese characters, the text consists of two encoded sub-characters; when the corresponding text type is numbers or letters, the text consists of one encoded sub-character. The number of encoded sub-characters constituting image text is related to the image format of the image corresponding to the image text, and this application does not limit this.
[0054] In step 202, the display width corresponding to each text object is obtained. The display width corresponding to any text object is used to indicate the display width of the content corresponding to any text object on the display page.
[0055] The text to be processed consists of at least one text object arranged sequentially. After obtaining the text to be processed, at least one text object is obtained, and these text objects have a specific order in which they are arranged. After obtaining at least one text object, the display width corresponding to each text object is obtained. The display width corresponding to any text object is used to indicate the display width of the content corresponding to that text object on the display page.
[0056] It should be noted that, for cases where at least one text object includes only at least one image text or only at least one text text, obtaining the display width corresponding to each text object is the same as obtaining the display width corresponding to each image text or each text text. For cases where at least one text object includes both at least one image text and at least one text text, obtaining the display width corresponding to each text object is the same as obtaining the display width corresponding to each image text and each text text.
[0057] When at least one text object constituting the text to be processed includes both text and image text, each text object can be either text or image text. Text and image text have different methods for obtaining their display width. In one possible implementation, when any text object is text, the process of obtaining the display width corresponding to that text object is as follows: in response to any text object being text, the character width corresponding to that text object is obtained, and the character width corresponding to that text object is used as the display width corresponding to that text object. For example, the character width corresponding to any text object refers to the total width occupied by each encoded sub-character constituting that text object in the text to be processed. Each encoded sub-character constituting the text is obtained by directly encoding the text corresponding to the text, and the total width of each encoded sub-character can represent the display width of the text corresponding to the text on the display page.
[0058] In another possible implementation, when any text object is text, the process of obtaining the display width corresponding to that text object is as follows: In response to any text object being text, the text object is converted into text, and the width of the converted text is used as the display width corresponding to that text object. The process of converting any text object into text can be viewed as the reverse process of converting text into text, and the process of converting any text object into text can be viewed as the process of decoding that text object. The decoding method used depends on the encoding method used to obtain the text object.
[0059] In one possible implementation, when any text object is image text, the process of obtaining the display width corresponding to that text object is as follows: In response to any text object being image text, determine the image format corresponding to that text object; based on the image format, determine the width of the image corresponding to that text object; and use the width of the image corresponding to that text object as the display width of that text object. Since the encoded sub-characters constituting the image text are obtained by encoding the image according to the image format corresponding to the image text, the display width of the image corresponding to the image text on the display page is related to the image format. When any text object is determined to be image text, the image format corresponding to that text object needs to be determined first. In one possible implementation, after converting the content to be displayed into text to be processed, the correspondence between the image format of the image in the content to be displayed and the image text in the text to be processed is stored. In this case, the image format corresponding to any text object can be determined based on the correspondence between the image format and the image text.
[0060] In one possible implementation, determining the width of the image corresponding to any text object based on its image format involves: converting the text object into an image according to its format, and using the width of the resulting image as the width of the image corresponding to the text object. This process can be viewed as the reverse of converting the image to text based on its format, and can also be considered as decoding the text object. The decoding method used depends on the encoding method used to obtain the text object. The width of the resulting image is then the display width of the image corresponding to the text object on the display page.
[0061] In one possible implementation, the process of obtaining the display width corresponding to any text object can be directly executed by the text truncation component. The text truncation component can automatically convert image text into images and text text into text, and automatically measure the width of the converted image and the width of the converted text.
[0062] In one possible implementation, the process of obtaining the display width corresponding to each text object is as follows: according to the arrangement order of the text objects, obtain the display width corresponding to each text object one by one until the display width corresponding to each text object is obtained.
[0063] In step 203, based on the display width of each text object, the text to be processed is split into lines to obtain at least one line of target text.
[0064] The display width corresponding to any text object indicates the display width of the content corresponding to that text object on the display page, and is the actual display width of the content corresponding to that text object. By splitting the text to be processed into lines according to the display width of each text object, the content of each line of target text obtained after line splitting can largely fill the width of the content display area on the display page, improving the page utilization rate of content display.
[0065] In one possible implementation, the text to be processed is split into lines based on the display width of each text object to obtain at least one line of target text. This can be achieved in ways including, but not limited to, the following two:
[0066] Method 1: Based on the display width of each text object, the text to be processed is split into lines to obtain at least one line of target text.
[0067] This first approach requires no additional working components; it can be completed using the terminal's native working components, resulting in a short development cycle and low cost. In one possible implementation, this first approach includes the following steps 1 and 2:
[0068] Step 1: Starting from the first text object in the text to be processed, the display widths of each text object are superimposed sequentially until the superposition operation meets the superposition termination condition. The text objects whose display widths have been superimposed when the superposition termination condition is met are arranged in the superposition order to form the first line of target text.
[0069] During the line-by-line processing of the text to be processed, the target text is obtained line by line, with each line corresponding to a line of content to be displayed in the content display area of the display page. In the process of obtaining the target text line by line, the first line of target text is obtained first; step 1 describes the process of obtaining the first line of target text. In obtaining the first line of target text, starting from the first text object in the text to be processed, the display widths corresponding to each text object are sequentially added until the addition operation meets the termination condition.
[0070] In one possible implementation, the process of sequentially adding the display widths of each text object, starting from the first text object in the text to be processed, is a loop process. Starting from the first text object, each time a new text object's display width is added, it is determined whether the addition operation meets the termination condition. If the addition operation does not meet the termination condition, the process continues adding the display width of the next text object until the termination condition is met. Then, the text objects whose display widths have been added at the point where the termination condition is met are arranged sequentially according to the addition order to form the first line of target text.
[0071] In one possible implementation, the spacing between adjacent text objects is considered when sequentially stacking the display widths of each text object. For example, assuming the display width of the first text object is 'a', the display width of the second text object is 'b', and the spacing between the first and second text objects is 'm', then the total width obtained by stacking the display width of the second text object on top of the display width of the first text object is (a + m + b). In another possible implementation, the spacing between adjacent text objects is a pre-set spacing width. The spacing width between text objects, between image objects, and between text and image objects can be the same or different.
[0072] In one possible implementation, the superposition operation satisfies the superposition termination condition in the following two cases:
[0073] Case 1: The total width obtained by superposition meets the width condition.
[0074] In one possible implementation, the total width obtained by overlaying satisfies any of the following width conditions:
[0075] 1. The difference between the total width obtained by superposition and the width threshold is less than the first reference threshold.
[0076] A width threshold is used to limit the maximum display width of a line of content. In one possible implementation, the width threshold refers to the width of the content display area on the display page. The width threshold is related to the setting parameters of the display page, and this application embodiment does not limit it. For example, the setting parameters of the display page include a size parameter for the content display area used to display content. In this case, the width indicated by the width parameter in the size parameter of the content display area is used as the width threshold.
[0077] When the value of the first reference threshold is relatively small, and the difference between the total width obtained by superposition and the width threshold is less than the first reference threshold, it indicates that the total width obtained by superposition is close to the width threshold, and at this time, the total width obtained by superposition is considered to meet the width condition. The first reference threshold can be set based on experience or flexibly adjusted according to the application scenario, and this application embodiment does not limit it in this way.
[0078] Throughout the entire line processing, the same first reference threshold is used to measure whether the total width obtained by stacking meets the width condition, which is highly efficient.
[0079] 2. The difference between the total width obtained by superposition and the width threshold is less than the target width. The target width is determined based on the display width corresponding to the reference text object. The reference text object is the text object located one position after the last text object with the superpositioned display width in the text to be processed.
[0080] The target width is determined based on the display width of the reference text object. In one possible implementation, when stacking the display widths of various text objects sequentially, without considering the spacing between adjacent text objects, the target width is determined by using the display width of the reference text object as the target width. Alternatively, when considering the spacing between adjacent text objects during the stacking process, the target width is determined by using the sum of the display width of the reference text object and a specified spacing width as the target width. The specified spacing width refers to the distance between the reference text object and the last text object whose display width has been stacked.
[0081] When the difference between the total width obtained by overlaying and the width threshold is less than the target width, it means that the difference between the total width obtained by overlaying and the width threshold is no longer sufficient to allow the display width corresponding to the reference text object to be overlaid. At this point, the total width obtained by overlaying is considered to meet the width condition.
[0082] The target width is determined in real time based on the display width of the next text object whose width is to be superimposed. Then, the total width obtained by superposition is measured in real time based on the target width determined in real time to see if it meets the width condition. The measurement effect is good.
[0083] Case 2: There is no text object whose width needs to be superimposed for display.
[0084] When there are no text objects whose display widths need to be superimposed, it means that the display widths corresponding to all text objects in the text to be processed have already participated in the superposition process. At this time, it is considered that the superposition operation meets the superposition termination condition.
[0085] When any of the above conditions are met, it indicates that the overlay operation has met the overlay termination condition. The text objects whose width has been overlaid at the time the overlay termination condition is met are arranged sequentially according to their overlay order to form the first line of target text. This results in the first line of target text. This first line of target text corresponds to the text of the first line of content to be displayed.
[0086] Step 2: In response to the line break processing operation not meeting the line break processing termination condition, take the other texts in the text to be processed except for the first line of target text as the updated text to be processed, and continue to obtain the target text based on the updated text to be processed until the line break processing operation meets the line break processing termination condition, and obtain at least one line of target text.
[0087] The process of splitting the text into lines is a loop. In each loop, one line of target text is acquired. After acquiring each line of target text, it is determined whether the line splitting operation meets the termination condition. If the line splitting operation does not meet the termination condition, subsequent lines of target text are acquired until the line splitting operation meets the termination condition.
[0088] After obtaining the first line of target text based on step 1, it is determined whether the line break processing operation meets the line break processing termination condition. If the line break processing operation meets the line break processing termination condition, the line break processing is stopped, and the entire line break processing process of the text to be processed yields only one line of target text. If the line break processing operation does not meet the line break processing termination condition, the other text in the text to be processed, excluding the first line of target text, is used as the updated text to be processed. The target text is then obtained based on the updated text to be processed until the line break processing operation meets the line break processing termination condition.
[0089] In the process of obtaining target text based on the updated text to be processed, the second line of target text is obtained first. The process of obtaining the second line of target text is similar to step 1: starting from the first text object in the updated text to be processed, the display widths corresponding to each text object are sequentially superimposed until the superposition operation meets the superposition termination condition. The text objects whose display widths have been superimposed when the superposition termination condition is met are then arranged in the superposition order to form the second line of target text. It should be noted that the text objects whose display widths have been superimposed here refer to the text objects in the updated text to be processed whose display widths have been superimposed. After obtaining the second target text, it is also determined whether the line-breaking operation meets the line-breaking termination condition. If the line-breaking operation does not meet the line-breaking termination condition, the updated text to be processed is obtained again, and the target text is obtained again until the line-breaking operation meets the line-breaking termination condition. It should be noted that in the process of cyclically obtaining target text, the updated text to be processed used in each loop refers to all text in the updated text to be processed used in the previous loop, excluding the line of target text obtained in the previous loop.
[0090] In one possible implementation, the line splitting operation satisfies the line splitting termination condition when the union of the acquired target text lines is the text to be processed. As we know from the process of acquiring the target text lines, there are no overlapping text objects among different target text lines. Therefore, when the union of the acquired target text lines is the text to be processed, it means there are no text objects whose line affiliation is undetermined. At this point, the line splitting process of the text to be processed is complete, and the target text lines are obtained when the line splitting termination condition is met, i.e., at least one target text line is obtained.
[0091] Method 2: Based on the display width of each text object, the text to be processed is truncated to achieve line breaks, resulting in at least one line of target text.
[0092] The truncation function can automatically cut off a line of text based on the display width of the text object. This second method can improve the efficiency of line break processing.
[0093] In one possible implementation, this second method includes the following steps A to D:
[0094] Step A: Starting from the first text object in the text to be processed, based on the display width corresponding to each of the at least one text object arranged in sequence, the text to be processed is truncated to obtain the first truncated text, which consists of the first candidate text and the truncation mark.
[0095] Truncated text refers to a line of text that is cut off from the current text to be processed. The truncated text is the text obtained by truncating the end of the current text to be displayed based on the display width corresponding to the first part of the text object in the current text to be processed.
[0096] In one possible implementation, starting with the first text object in the text to be processed, a text truncation component is invoked to truncate the text based on the display widths of at least one of the sequentially arranged text objects. The text truncation component is used to truncate the text, starting with the first text object in the text to be processed, based on the display widths of at least one sequentially arranged text object, thus obtaining truncated text. For example, the text truncation component is a CSS (Cascading Style Sheets) component.
[0097] It should be noted that the text truncation component stores a parameter used to indicate the width threshold. The width of the truncated text obtained based on the text truncation component does not exceed the width threshold, and the difference between the truncated text and the width threshold is extremely small. This ensures that the content corresponding to the truncated text largely fills the width of the text display area on the display page.
[0098] The process of splitting the text into lines by truncating it is a loop process. In each loop, the text to be processed is first truncated to obtain a line of truncated text, and then the target text is obtained based on the truncated text. Steps A to C describe the process of obtaining the first line of target text.
[0099] In the process of obtaining the first line of target text, starting from the first text object in the text to be processed, the first truncated text is obtained based on the display width corresponding to each of the at least one text object arranged in sequence. This first truncated text is obtained after truncating the current text to be processed. In obtaining the first truncated text, the number of sequentially arranged text objects considered is related to the width threshold and the display width corresponding to the sequentially arranged text objects considered, which is not limited in this embodiment.
[0100] The first truncated text consists of a first candidate text and a truncation marker. The first candidate text is the text composed of text objects in the text to be processed. The truncation marker is a marker appended to the end of the first truncated text to indicate that truncation processing is required. The truncation marker indicates that there is other text in the text to be processed that follows the first truncated text. In one possible implementation, the truncation marker is an ellipsis.
[0101] Step B: Use the width of the truncation mark as the width to be padded; based on the width to be padded and the text object in the text to be processed that is located after the first candidate text, obtain the first padded text.
[0102] The first truncated text includes the first candidate text and a truncation marker. The first candidate text is the text in the text to be processed, and the truncation marker is a marker used to indicate truncation processing. Since the truncation marker occupies a certain width, the content corresponding to the first candidate text cannot fill the width of the content display area on the display page. Therefore, after obtaining the first truncated text, it is necessary to obtain the first padding text based on the width of the truncation marker, thereby further obtaining the first line of target text whose content can fill the width of the content display area on the display page to a large extent.
[0103] In one possible implementation, before obtaining the first padded text, the truncation mark in the first truncated text can be deleted, so that the first candidate text and the first padded text can be easily concatenated after obtaining the first padded text.
[0104] In one possible implementation, the process of obtaining the first padded text based on the width of the truncation mark is as follows: the width of the truncation mark is used as the width to be padded; based on the width to be padded and the text objects in the text to be processed that are located after the first candidate text, the first padded text is obtained. The first padded text is obtained from the text objects in the text to be processed that are located after the first candidate text. In one possible implementation, the process of obtaining the first padded text based on the width to be padded and the text objects in the text to be processed that are located after the first candidate text includes the following steps a to c:
[0105] Step a: In response to the fact that the display width of the first text object to be padded after the first candidate text in the text to be processed does not exceed the width to be padded, the first text object to be padded is taken as the first target text object.
[0106] The process of obtaining the first padded text can be viewed as a loop. Each text object following the first candidate text in the text to be processed is analyzed and padded sequentially until the updated width to be padded meets the width padding condition, thus obtaining the first padded text. First, the first text object to be padded, following the first candidate text, is analyzed to determine if its display width exceeds the padded width. The first text object to be padded is the text object located one position after the last text object in the first candidate text within the text to be processed.
[0107] When the display width of the first text object to be padded, located after the first candidate text, does not exceed the padded width, this first text object to be padded is taken as the first target text object. This first target text object is the first text object that constitutes the first padded text. In this case, it indicates that the first padded text is composed of at least one target text object. After obtaining the first target text object, continue with step b.
[0108] In one possible implementation, in response to the display width of the first text object to be padded after the first candidate text in the text to be processed exceeding the padded width, empty text is used as the first padded text. In this case, the first padded text is obtained without performing subsequent steps b and c.
[0109] In one possible implementation, when at least one text object constituting the text to be processed includes both text and image text, the first text object to be padded may be either text or image text. Before determining whether the display width corresponding to the first text object to be padded exceeds the padded width, it is pre-determined whether the first text object to be padded is image text. If the first text object to be padded is not image text, it is considered to be text text. In this case, determining whether the display width corresponding to the first text object to be padded exceeds the padded width is equivalent to determining whether the character width corresponding to the text text exceeds the padded width. If the first text object to be padded is image text, determining whether the display width corresponding to the first text object to be padded exceeds the padded width is equivalent to determining whether the width of the image corresponding to the first text object exceeds the padded width.
[0110] Step b: Determine the updated width to be padded based on the width to be padded and the display width corresponding to the first target text object.
[0111] After obtaining the first target text object, the updated width to be padded is determined based on the width to be padded and the display width corresponding to the first target text, so as to further obtain the target text object used to constitute the first padded text according to the updated width to be padded.
[0112] In one possible implementation, the updated width to be padded is determined based on the width to be padded and the display width corresponding to the first target text object by using the difference between the width to be padded and the display width corresponding to the first target text object as the updated width to be padded.
[0113] In another possible implementation, the updated width to be padded is determined based on the width to be padded and the display width corresponding to the first target text object as follows: the difference between the width to be padded and the display width corresponding to the first target text object is used as the first width; the difference between the first width and the specified width is used as the updated width to be padded. Optionally, the specified width is set according to the preset spacing width between text objects. This application embodiment does not limit the method of setting the specified width. For example, the product of the average of the three preset spacing widths between text objects and the reference weight value is used as the specified width. The reference weight value is set based on experience or according to the setting parameters of the text truncation component. The three preset spacing widths between text objects refer to the spacing width between text and text, the spacing width between text and image text, and the spacing width between image text.
[0114] After obtaining the first target text object and determining the updated width to be padded, it is determined whether the updated width to be padded meets the width padding condition. If the updated width to be padded does not meet the width padding condition, step c is executed. If the updated width to be padded meets the width padding condition, the target text objects obtained when the width padding condition is met are arranged in the order of acquisition to form the first padded text. Since only the first target text object is obtained at this time, the first target text object is used as the first padded text.
[0115] In one possible implementation, the updated width to be padded satisfies the width padding conditions, including but not limited to:
[0116] 1. The updated width to be filled is less than the second reference threshold.
[0117] The second reference threshold can be set based on experience or adjusted flexibly according to the application scenario; this application embodiment does not limit this. The second reference threshold is a small value. When the updated width to be padded is less than the second reference threshold, it indicates that the updated width to be padded is small, and at this time it is considered that the updated width to be padded has met the width padding condition.
[0118] 2. The updated width to be padded is less than the display width of the next text object to be padded in the text to be processed. The next text object to be padded refers to the text object located one position after the last target text object already obtained in the text to be processed.
[0119] When the updated width to be padded is less than the display width of the next text object to be padded in the text to be processed, it means that the updated width to be padded is no longer able to accommodate the next text object to be padded. At this time, it is considered that the updated width to be padded has met the width padding condition.
[0120] Step c: In response to the updated width to be padded not meeting the width padding condition, based on the updated width to be padded and other text objects in the text to be processed that are located after the first candidate text, continue to obtain target text objects until the updated width to be padded meets the width padding condition. Arrange the target text objects obtained when the width padding condition is met in the order they were obtained to form the first padded text. The other text objects are all text objects other than the first text object to be padded.
[0121] After obtaining the first target text object, if the updated width to be padded does not meet the width padding condition, the process continues to obtain target text objects based on the updated width to be padded and other text objects in the text to be processed that are located after the first candidate text, excluding the first text object to be padded. This process of obtaining target text objects is a loop, in which one target text object is obtained in each loop. For each target text object obtained, it is determined whether the updated width to be padded meets the width padding condition. If the updated width to be padded does not meet the width padding condition, the next loop continues until the updated width to be padded meets the width padding condition. It should be noted that the updated width to be padded refers to the width to be padded that is continuously updated during the loop.
[0122] The process of acquiring the target text object in each loop is similar to steps a and b. For example, the process of acquiring the second target text object is as follows: in response to the display width of the second text object to be padded after the first candidate text in the text to be processed not exceeding the updated padded width, the second text object to be padded is taken as the second target text object. After acquiring the second target text object, the updated padded width is determined based on the updated padded width and the display width corresponding to the second target text object. If, after acquiring the second target text object, the updated padded width still does not meet the width padding condition, then the process of acquiring target text objects continues based on the updated padded width and other text objects in the text to be processed that are located after the first candidate text, excluding the first and second text objects to be padded.
[0123] When the updated width to be padded meets the width padding condition, the target text objects obtained when the width padding condition is met are arranged in the order of acquisition to form the first padded text, thus obtaining the first padded text.
[0124] Step C: Concatenate the first candidate text and the first padded text to obtain the first line of target text.
[0125] The first completed text obtained in step B refers to the completed text corresponding to the first candidate text obtained in step A. The first candidate text and the first completed text are concatenated, and the concatenated text is used as the first line of target text.
[0126] Based on steps A to C above, the first line of target text is obtained. After obtaining the first line of target text, it is determined whether the line splitting operation meets the line splitting termination condition. If the line splitting operation does not meet the line splitting termination condition, step D is executed; if the line splitting operation meets the line splitting termination condition, the first line of target text is used as the final target text obtained after line splitting the text to be processed. At this point, the number of target texts is one line. In one possible implementation, the line splitting operation meeting the line splitting termination condition means that the union of all obtained lines of target text is the text to be processed.
[0127] Step D: In response to the line break processing operation not meeting the line break processing termination condition, take the other texts in the text to be processed except for the first line of target text as the updated text to be processed, and continue to obtain the target text based on the updated text to be processed until the line break processing operation meets the line break processing termination condition, and obtain at least one line of target text.
[0128] When the line break processing operation does not meet the termination condition, it means that line break processing needs to continue to obtain other lines of target text. The process of obtaining other lines of target text is as follows: take the text other than the first line of target text in the text to be processed as the updated text to be processed, and continue to obtain target text based on the updated text to be processed.
[0129] The process of continuously obtaining target text based on the updated text to be processed is a loop process, with each loop obtaining one line of target text. It should be noted that during the loop process of obtaining target text, each loop obtains text based on the updated text to be processed. The updated text to be processed used in each loop refers to all text in the updated text to be processed used in the previous loop, excluding the line of target text obtained in the previous loop. After obtaining each line of target text, it is determined whether the line splitting operation meets the line splitting termination condition. If the line splitting operation does not meet the line splitting termination condition, the loop continues to obtain target text until the line splitting operation meets the line splitting termination condition, resulting in at least one line of target text. Here, "at least one line of target text" refers to the final lines of target text obtained after processing the text to be processed into lines.
[0130] In one possible implementation, each loop process can be implemented as described in steps A to C. For example, the process of obtaining the second line of target text is as follows: starting from the first text object in the updated text to be processed, based on the display width corresponding to at least one text object arranged sequentially, the updated text to be processed is truncated to obtain a second truncated text, which consists of a second candidate text and a truncation marker; the width of the truncation marker is used as the width to be padded; based on the width to be padded and the text objects in the updated text to be processed that are located after the second candidate text, a second padded text is obtained; the second candidate text and the second padded text are concatenated to obtain the second line of target text. In one possible implementation, when the text is truncated using a text truncation component, since the loop process utilizes the same text truncation component, the truncation markers in the truncated text obtained after truncation are all the same, and the width of the truncation markers is also the same.
[0131] In one possible implementation, regardless of whether at least one line of target text is obtained based on method one or method two, each line of target text obtained can be stored in a string array so that the target text can be extracted from the string array and drawn and displayed later.
[0132] In one possible implementation, before performing line break processing on the text to be processed based on the display width corresponding to each text object, the method further includes: performing line break detection on the text to be processed and obtaining the detection result. The purpose of performing line break detection on the text to be processed is to determine whether the text to be processed meets the line break processing conditions based on the detection result. Whether the line break processing conditions are met is used to indicate whether the text to be processed needs to be broken into lines. In this case, the process of performing line break processing on the text to be processed based on the display width corresponding to each text object is as follows: in response to the detection result indicating that the text to be processed meets the line break processing conditions, line break processing is performed on the text to be processed based on the display width corresponding to each text object. That is, line break processing is performed on the text to be processed only when the detection result indicates that the text to be processed meets the line break processing conditions. This method is beneficial for saving resources and costs.
[0133] In one possible implementation, line break detection is performed on the text to be processed, and the detection results can be obtained in ways including but not limited to the following two:
[0134] Method 1: Obtain the initial line number of the text to be processed, and obtain the detection result based on the initial line number.
[0135] The initial line count refers to the default number of lines into which the text to be processed is divided before processing is performed using the method provided in this application embodiment. In one possible implementation, the initial line count of the text to be processed is obtained by calling the API (Application Programming Interface) in the terminal's native automatic line wrapping component to measure the total number of lines, and obtaining the initial line count of the text to be processed based on this API.
[0136] After obtaining the initial line number of the text to be processed, the detection result is obtained based on the initial line number. In one possible implementation, the process of obtaining the detection result based on the initial line number is as follows: the initial line number is compared with 1, and the comparison result is taken as the detection result. In this case, the detection result has two possibilities: the initial line number is greater than 1, or the initial line number is not greater than 1.
[0137] When the detection result shows that the initial number of lines is greater than 1, it means that the text to be processed has been divided into more than 1 lines by default, and the text to be processed is considered to need to be split into lines. When the detection result shows that the initial number of lines is not greater than 1, it means that the text to be processed has been divided into no more than 1 lines by default, and the text to be processed is considered not to need to be split into lines.
[0138] This method 1 directly calls the relevant API to implement the line detection process, which is simple and quick to operate.
[0139] Method 2: Truncate the text to be processed and use the truncation result as the detection result.
[0140] After truncating the text to be processed, the truncated result is obtained. There are two possible results: either the truncated text corresponds to the text to be processed, or the truncated text does not correspond to the text to be processed.
[0141] In one possible implementation, the process of truncating the text to be processed is as follows: A text truncation component is invoked to truncate the text. This component truncates the end of text whose total width exceeds a width threshold. During this process, the component automatically determines whether the total width of the text exceeds the threshold. If the total width exceeds the threshold, the component truncates the text; if the total width does not exceed the threshold, the component does not truncate the text. When the component truncates the text, the result is the truncated text corresponding to the original text. When the component does not truncate the text, the result is no truncated text corresponding to the original text.
[0142] After obtaining the truncation result, the truncation result is used as the detection result. That is to say, the detection result includes two types: the truncated text corresponding to the text to be processed is obtained after truncation, or the truncated text corresponding to the text to be processed is not obtained after truncation.
[0143] When the detection result is that the truncated text corresponding to the text to be processed is obtained after truncation, it means that the total width of the text to be processed exceeds the width threshold. In this case, it is considered that the text to be processed needs to be broken into lines. When the detection result is that the truncated text corresponding to the text to be processed is not obtained after truncation, it means that the total width of the text to be processed does not exceed the width threshold. In this case, it is considered that the text to be processed does not need to be broken into lines.
[0144] This method 2 has a higher efficiency in line break detection, and the truncated text obtained from the truncation process can be directly used to obtain the first line of target text.
[0145] In one possible implementation, corresponding to the two methods of obtaining detection results mentioned above, the following two situations are considered when the detection result indicates that the text to be processed meets the line break processing condition:
[0146] 1. In response to the detection result that the initial number of lines is greater than the reference value, determine that the detection result indicates that the text to be processed meets the line break processing condition.
[0147] This determination that the detection result indicates the text to be processed meets the line break processing condition occurs when the detection result is obtained in the manner described in Method 1 above. The reference value can be set based on experience; for example, the reference value is 1. That is to say, when the detection result shows that the initial line number is greater than 1, it is determined that the detection result indicates the text to be processed meets the line break processing condition.
[0148] 2. In response to the detection result being the truncated text corresponding to the text to be processed after truncation, determine that the detection result indicates that the text to be processed meets the line break processing condition.
[0149] This situation, where the detection result indicates that the text to be processed meets the line break processing conditions, occurs when the detection result is obtained in the manner described in method 2 above.
[0150] In step 204, the content corresponding to at least one line of target text is displayed in separate lines on the display page.
[0151] After obtaining at least one line of target text, the content corresponding to each line of target text is displayed in separate lines on the display page, allowing the terminal's interactive objects to browse and view the displayed content. It should be noted that each line of target text corresponds to one line of content, and displaying the content corresponding to each line of target text in separate lines on the display page means arranging the content in the order in which the target text was obtained.
[0152] In one possible implementation, the process of displaying the content corresponding to at least one line of target text in separate lines on the display page involves: drawing the at least one line of target text in separate lines to obtain the content corresponding to each line of target text; and arranging and displaying the content corresponding to each line of target text in the content display area of the display page according to the order in which the target text was obtained. In another possible implementation, the method for drawing the at least one line of target text in separate lines is to use a Static Layout component to draw the at least one line of target text in separate lines. This drawing method is beneficial for optimizing drawing performance.
[0153] After displaying the content corresponding to at least one line of target text in separate lines on the display page, the terminal's interactive object can browse and view the content displayed in separate lines on the display page. It should be noted that since each line of target text is obtained based on the display width of the content corresponding to the text object on the display page, after displaying the content corresponding to at least one line of target text in separate lines on the display page, each line of content can largely fill the width of the content display area of the display page, resulting in a more aesthetically pleasing appearance, higher page utilization, and significantly reducing the occurrence of line break chaos caused by premature automatic line wrapping. The content display method provided in this application embodiment is applicable to scenarios where various terminals display long content, which may include images, Chinese characters, letters, and numbers. Terminal types include, but are not limited to, Android terminals. Images include, but are not limited to, emoticons, landscape images, and news images.
[0154] It should be noted that steps 202, 203, and 204 do not need to be executed in a strict order. For example, after obtaining the display width corresponding to a portion of the text objects based on step 202, a portion of the target text can be obtained based on step 203. After obtaining the portion of the target text based on step 203, the content corresponding to each portion of the target text can be displayed in separate lines on the display page based on step 204. At any point during the process of obtaining the portion of the target text, after obtaining the portion of the target text, during the process of displaying the content corresponding to each portion of the target text in separate lines on the display page, or after displaying the content corresponding to each portion of the target text in separate lines on the display page, the display width corresponding to the portion of the text objects can be obtained again based on step 202, and so on, until all the target text is obtained and the content corresponding to all the target text has been displayed in separate lines on the display page. This application embodiment does not limit the number of text objects whose display width is obtained each time or the number of lines of target text obtained each time. For example, the number of lines of target text obtained each time is one line, and the number of text objects whose display width is obtained each time is 10.
[0155] For example, the process of breaking the text into lines is as follows: Figure 3 As shown. 1. Obtain the text to be processed. The text objects constituting the text to be processed include text text and image text. The text text includes, but is not limited to, Chinese characters, letters, and numbers. 2. Obtain the display width corresponding to each text object, and call the text truncation component to truncate the text to be processed, obtaining a single-line truncated text. The single-line truncated text includes candidate text and truncation markers. 3. Delete the truncation markers from the single-line truncated text to obtain candidate text. 4. Based on the width of the truncation markers, obtain the padding text corresponding to the candidate text of the single line, and obtain the target text of the single line based on the candidate text and padding text. 5. Continue to perform line splitting processing to obtain at least one line of target text. Figure 3 Only 3 lines of target text are shown in the image, and each line of target text consists of candidate text and completion text.
[0156] For example, the content display process is as follows Figure 4As shown. First, the text to be processed is obtained. After obtaining the text, it is determined whether special line break processing is required. When no special line break processing is required, the terminal's native line break component is used for line break processing, and then the resulting text is drawn and displayed. When special line break processing is required, the method provided in this embodiment is used. It should be noted that the criteria for determining whether special line break processing is required are configured and distributed in the background and can be switched at any time online. The method provided in this embodiment for line break processing has strong scalability and is visually appealing; although using the native line break component is less visually appealing, its mature line break processing technology helps maintain high line break processing performance.
[0157] When special line break processing is required, line break detection is performed on the text to determine if it meets the line break processing conditions. If the text does not meet the line break processing conditions, it means that the text only has one line of target text, and no additional line break processing is needed. In this case, the content of that one line of target text is drawn and displayed. If the text meets the line break processing conditions, it means that the text has more than one line of target text, and additional line break processing is required.
[0158] When the text to be processed meets the line break processing condition, the text truncation component is invoked to truncate the text, resulting in truncated text. The truncation markers in the truncated text are then removed, and the width of the truncation markers is used as the width to be padded. It is then determined whether the text to be padded following the candidate text in the text to be processed is an image text. If the text to be padded is an image text and its corresponding display width does not exceed the padded width, the image text is used as the target text object to construct the padded text. Based on the padded width and the corresponding display width of the image text, the updated padded width is determined, and then it is determined whether the updated padded width meets the width padding condition. If the text to be padded is text and its corresponding display width does not exceed the padded width, the text text is used as the target text object to construct the padded text. Based on the padded width and the corresponding display width of the text text, the updated padded width is determined, and then it is determined whether the updated padded width meets the width padding condition.
[0159] If the updated width to be padded does not meet the width padding condition, the process returns to the step of determining whether the text object to be padded is an image text. If the updated width to be padded meets the width padding condition, the target text of the single line obtained from the line break processing is saved, and then it is determined whether the line break processing operation meets the line break processing termination condition. It should be noted that regardless of whether the text object to be padded is an image text or text text, if the display width corresponding to the text object to be padded (image text or text text) exceeds the width to be padded, the step of saving the target text of the single line obtained from the line break processing is directly executed.
[0160] When the line break operation does not meet the line break termination condition, the process returns to the step of calling the text truncation component to obtain the truncated text. It should be noted that the truncation process of obtaining the truncated text by calling the text truncation component at this time applies to the updated text to be processed. When the line break operation meets the line break termination condition, each line of target text obtained after line break processing is drawn and displayed line by line.
[0161] This application's embodiments can solve the problem of automatic line wrapping when displaying mixed English, Chinese, and numbers content in the terminal's native components, while also being compatible with mixed text and image content. It offers greater scalability, a more aesthetically pleasing appearance, and eliminates the issue of mixed content being automatically wrapped prematurely. Unless the interactive object actively inputs a line break, regardless of the type of mixed content, each line of content ultimately fills the width of the content display area on the page to a great extent.
[0162] In this embodiment, the text to be processed is split into lines according to the display width corresponding to each text object, and then the content corresponding to the target text obtained after line splitting is displayed in lines. Since the display width corresponding to each text object is used to indicate the display width of the content corresponding to the text object on the display page, the line splitting effect of splitting the text to be processed according to the display width corresponding to each text object is better, the page utilization rate of displaying the content corresponding to the target text obtained after line splitting is higher, the visual effect of content display is better, and it is beneficial to improve the user experience.
[0163] See Figure 5 This application provides a content display device, which includes:
[0164] The first acquisition module 501 is used to acquire the text to be processed, which consists of at least one text object arranged in sequence.
[0165] The second acquisition module 502 is used to acquire the display width corresponding to each text object. The display width corresponding to any text object is used to indicate the display width of the content corresponding to any text object on the display page.
[0166] The line splitting module 503 is used to split the text to be processed into lines based on the display width of each text object, so as to obtain at least one line of target text.
[0167] Display module 504 is used to display the content corresponding to at least one line of target text in a separate line on the display page.
[0168] In one possible implementation, the line break processing module 503 is configured to, starting from the first text object in the text to be processed, truncate the text based on the display width corresponding to at least one text object arranged sequentially, to obtain a first truncated text, which consists of a first candidate text and a truncation marker; use the width of the truncation marker as the width to be padded; obtain the first padded text based on the width to be padded and the text objects in the text to be processed that are located after the first candidate text; concatenate the first candidate text and the first padded text to obtain the first line of target text; and, in response to the line break processing operation not meeting the line break processing termination condition, use the other texts in the text to be processed, excluding the first line of target text, as the updated text to be processed, and continue to obtain target text based on the updated text to be processed until the line break processing operation meets the line break processing termination condition, thus obtaining at least one line of target text.
[0169] In one possible implementation, the line break processing module 503 is further configured to: respond to the fact that the display width of the first text object to be padded after the first candidate text in the text to be processed does not exceed the padded width, take the first text object to be padded as the first target text object; determine the updated padded width based on the padded width and the display width corresponding to the first target text object; respond to the fact that the updated padded width does not meet the width padding condition, continue to obtain target text objects based on the updated padded width and other text objects in the text to be processed after the first candidate text, until the updated padded width meets the width padding condition, and arrange the target text objects obtained when the width padding condition is met in the order of acquisition to form the first padded text, and the other text objects are text objects other than the first text object to be padded.
[0170] In one possible implementation, the line break processing module 503 is further configured to, in response to the fact that the display width of the first text object to be padded after the first candidate text in the text to be processed exceeds the width to be padded, use the empty text as the first padding text.
[0171] In one possible implementation, the line break processing module 503 is used to start from the first text object in the text to be processed, and sequentially add the display width corresponding to each text object until the addition operation meets the addition termination condition. The text objects whose display widths have been added when the addition termination condition is met are arranged in the addition order to form the first line of target text. In response to the line break processing operation not meeting the line break processing termination condition, the other texts in the text to be processed except the first line of target text are taken as the updated text to be processed. The target text is then obtained based on the updated text to be processed until the line break processing operation meets the line break processing termination condition, and at least one line of target text is obtained.
[0172] In one possible implementation, the second acquisition module 502 is used to determine the image format corresponding to any text object in response to the fact that any text object is image text; determine the width of the image corresponding to any text object based on the image format corresponding to any text object; and use the width of the image corresponding to any text object as the display width of the text object.
[0173] In one possible implementation, see [link to relevant documentation]. Figure 6 The device also includes:
[0174] The detection module 505 is used to perform line break detection on the text to be processed and obtain the detection results;
[0175] The line break processing module 503 is used to process the text to be processed into lines based on the display width corresponding to each text object, in response to the detection result indicating that the text to be processed meets the line break processing conditions.
[0176] In one possible implementation, the detection module 505 is used to obtain the initial line number corresponding to the text to be processed and obtain the detection result based on the initial line number; or, the text to be processed is truncated and the truncated result is used as the detection result.
[0177] In one possible implementation, see [link to relevant documentation]. Figure 6 The device also includes:
[0178] The determination module 506 is used to determine that the detection result indicates the text to be processed meets the line break processing condition in response to the detection result that the initial line number is greater than the reference value; or, in response to the detection result that the truncated text corresponding to the text to be processed is obtained after truncation processing, the detection result indicates that the text to be processed meets the line break processing condition.
[0179] In this embodiment, the text to be processed is split into lines according to the display width corresponding to each text object, and then the content corresponding to the target text obtained after line splitting is displayed in lines. Since the display width corresponding to each text object is used to indicate the display width of the content corresponding to the text object on the display page, the line splitting effect of splitting the text to be processed according to the display width corresponding to each text object is better, the page utilization rate of displaying the content corresponding to the target text obtained after line splitting is higher, the visual effect of content display is better, and it is beneficial to improve the user experience.
[0180] It should be noted that the apparatus provided in the above embodiments is only illustrated by the division of the above functional modules. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus and method embodiments provided in the above embodiments belong to the same concept, and their specific implementation process can be found in the method embodiments, which will not be repeated here.
[0181] Figure 7 This is a schematic diagram of the structure of a content display device provided in an embodiment of this application. The device can be a terminal, such as a smartphone, tablet computer, laptop computer, or desktop computer. The terminal may also be referred to as user equipment, portable terminal, laptop terminal, desktop terminal, or other names.
[0182] Typically, a terminal includes a processor 701 and a memory 702.
[0183] Processor 701 may include one or more processing cores, such as a quad-core processor, an octa-core processor, etc. Processor 701 may be implemented using at least one hardware form selected from DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). Processor 701 may also include a main processor and a coprocessor. The main processor, also known as a CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, processor 701 may integrate a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content required to be displayed on the screen. In some embodiments, processor 701 may also include an AI (Artificial Intelligence) processor, which is used to handle computational operations related to machine learning.
[0184] The memory 702 may include one or more computer-readable storage media, which may be non-transitory. The memory 702 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In some embodiments, the non-transitory computer-readable storage media in the memory 702 are used to store at least one instruction, which is executed by the processor 701 to implement the content display method provided in the method embodiments of this application.
[0185] In some embodiments, the terminal may also optionally include: a peripheral device interface 703 and at least one peripheral device. The processor 701, memory 702, and peripheral device interface 703 can be connected via a bus or signal line. Each peripheral device can be connected to the peripheral device interface 703 via a bus, signal line, or circuit board. Specifically, the peripheral device includes at least one of: a radio frequency circuit 704, a touch display screen 705, a camera assembly 706, an audio circuit 707, and a power supply 709.
[0186] Peripheral device interface 703 can be used to connect at least one I / O (Input / Output) related peripheral device to processor 701 and memory 702. In some embodiments, processor 701, memory 702 and peripheral device interface 703 are integrated on the same chip or circuit board; in some other embodiments, any one or two of processor 701, memory 702 and peripheral device interface 703 can be implemented on separate chips or circuit boards, which is not limited in this embodiment.
[0187] The radio frequency (RF) circuit 704 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The RF circuit 704 communicates with communication networks and other communication devices via electromagnetic signals. The RF circuit 704 converts electrical signals into electromagnetic signals for transmission, or converts received electromagnetic signals back into electrical signals. Optionally, the RF circuit 704 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, etc. The RF circuit 704 can communicate with other terminals through at least one wireless communication protocol. This wireless communication protocol includes, but is not limited to: metropolitan area networks (MANs), various generations of mobile communication networks (2G, 3G, 4G, and 5G), wireless local area networks (WLANs), and / or WiFi (Wireless Fidelity) networks. In some embodiments, the RF circuit 704 may also include circuitry related to NFC (Near Field Communication), which is not limited in this application.
[0188] Display screen 705 is used to display a UI (User Interface). This UI may include graphics, text, icons, videos, and any combination thereof. When display screen 705 is a touch display screen, it also has the ability to collect touch signals on or above its surface. These touch signals can be input as control signals to processor 701 for processing. In this case, display screen 705 can also be used to provide virtual buttons and / or a virtual keyboard, also known as soft buttons and / or a soft keyboard. In some embodiments, display screen 705 may be a single screen, disposed on the front panel of the terminal; in other embodiments, display screen 705 may be at least two screens, disposed on different surfaces of the terminal or in a folded design; in still other embodiments, display screen 705 may be a flexible display screen, disposed on a curved or folded surface of the terminal. Furthermore, display screen 705 may be configured as a non-rectangular, irregular shape, i.e., a non-rectangular screen. Display screen 705 may be made of materials such as LCD (Liquid Crystal Display) or OLED (Organic Light-Emitting Diode).
[0189] The camera assembly 706 is used to acquire images or videos. Optionally, the camera assembly 706 includes a front-facing camera and a rear-facing camera. Typically, the front-facing camera is located on the front panel of the terminal, and the rear-facing camera is located on the back of the terminal. In some embodiments, there are at least two rear-facing cameras, which are any one of a main camera, a depth-sensing camera, a wide-angle camera, and a telephoto camera, to achieve background blurring by fusion of the main camera and the depth-sensing camera, panoramic shooting by fusion of the main camera and the wide-angle camera, VR (Virtual Reality) shooting, or other fusion shooting functions. In some embodiments, the camera assembly 706 may also include a flash. The flash can be a single-color temperature flash or a dual-color temperature flash. A dual-color temperature flash refers to a combination of a warm-light flash and a cool-light flash, which can be used for light compensation at different color temperatures.
[0190] The audio circuit 707 may include a microphone and a speaker. The microphone is used to collect sound waves from the user and the environment, converting the sound waves into electrical signals that are input to the processor 701 for processing, or input to the radio frequency circuit 704 for voice communication. For stereo sound acquisition or noise reduction purposes, multiple microphones may be used, each positioned at a different location on the terminal. The microphone may also be an array microphone or an omnidirectional microphone. The speaker is used to convert the electrical signals from the processor 701 or the radio frequency circuit 704 into sound waves. The speaker may be a conventional diaphragm speaker or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can convert electrical signals not only into audible sound waves but also into inaudible sound waves for purposes such as distance measurement. In some embodiments, the audio circuit 707 may also include a headphone jack.
[0191] Power supply 709 is used to power the various components in the terminal. Power supply 709 can be AC power, DC power, a disposable battery, or a rechargeable battery. When power supply 709 includes a rechargeable battery, the rechargeable battery can support wired or wireless charging. The rechargeable battery can also be used to support fast charging technology.
[0192] In some embodiments, the terminal further includes one or more sensors 710. The one or more sensors 710 include, but are not limited to: an accelerometer 711, a gyroscope 712, a pressure sensor 713, an optical sensor 715, and a proximity sensor 716.
[0193] Accelerometer 711 can detect the magnitude of acceleration along the three coordinate axes of a coordinate system established by the terminal. For example, accelerometer 711 can be used to detect the components of gravitational acceleration along the three coordinate axes. Processor 701 can control touchscreen 705 to display the user interface in landscape or portrait view based on the gravitational acceleration signal acquired by accelerometer 711. Accelerometer 711 can also be used for games or for acquiring user motion data.
[0194] The gyroscope sensor 712 can detect the terminal's orientation and rotation angle. The gyroscope sensor 712, in conjunction with the accelerometer sensor 711, can collect the user's 3D movements on the terminal. Based on the data collected by the gyroscope sensor 712, the processor 701 can perform the following functions: motion sensing (e.g., changing the UI based on the user's tilt), image stabilization during shooting, game control, and inertial navigation.
[0195] The pressure sensor 713 can be disposed on the side bezel of the terminal and / or on the lower layer of the touch display screen 705. When the pressure sensor 713 is disposed on the side bezel of the terminal, it can detect the user's grip signal on the terminal, and the processor 701 can perform left / right hand recognition or quick operation based on the grip signal collected by the pressure sensor 713. When the pressure sensor 713 is disposed on the lower layer of the touch display screen 705, the processor 701 can control the operable controls on the UI interface based on the user's pressure operation on the touch display screen 705. The operable controls include at least one of button controls, scroll bar controls, icon controls, and menu controls.
[0196] An optical sensor 715 is used to collect ambient light intensity. In one embodiment, the processor 701 can control the display brightness of the touch screen 705 based on the ambient light intensity collected by the optical sensor 715. Specifically, when the ambient light intensity is high, the display brightness of the touch screen 705 is increased; when the ambient light intensity is low, the display brightness of the touch screen 705 is decreased. In another embodiment, the processor 701 can also dynamically adjust the shooting parameters of the camera assembly 706 based on the ambient light intensity collected by the optical sensor 715.
[0197] The proximity sensor 716, also known as a distance sensor, is typically located on the front panel of the terminal. The proximity sensor 716 is used to detect the distance between the user and the front of the terminal. In one embodiment, when the proximity sensor 716 detects that the distance between the user and the front of the terminal is gradually decreasing, the processor 701 controls the touchscreen display 705 to switch from a screen-on state to a screen-off state; when the proximity sensor 716 detects that the distance between the user and the front of the terminal is gradually increasing, the processor 701 controls the touchscreen display 705 to switch from a screen-off state to a screen-on state.
[0198] Those skilled in the art will understand that Figure 7 The structure shown does not constitute a limitation on the terminal and may include more or fewer components than shown, or combine certain components, or use different component arrangements.
[0199] In an exemplary embodiment, a computer device is also provided, comprising a processor and a memory storing at least one line of program code. This at least one line of program code is loaded and executed by one or more processors to implement any of the content display methods described above.
[0200] In an exemplary embodiment, a computer-readable storage medium is also provided, which stores at least one piece of program code, which is loaded and executed by a processor of a computer device to implement any of the above-described content display methods.
[0201] In one possible implementation, the aforementioned computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a compact disc read-only memory (CD-ROM), magnetic tape, floppy disk, and optical data storage device, etc.
[0202] In an exemplary embodiment, a computer program product or computer program is also provided, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform any of the content display methods described above.
[0203] It should be understood that "multiple" as used in this article refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects have an "or" relationship.
[0204] It should be noted that the terms "first," "second," etc., used in the specification of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0205] The above description is merely an exemplary embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A content display method, characterized in that, The method includes: Obtain the content to be displayed, which includes images; The content to be displayed is converted to obtain the text to be processed corresponding to the content to be displayed. The text to be processed is composed of at least one text object arranged in sequence. The at least one text object includes at least one image text. The image text is obtained by encoding the image in the content to be displayed according to the image format of the image in the content to be displayed. Line break detection is performed on the text to be processed to obtain a detection result. The detection result is used to indicate whether the text to be processed meets the line break processing conditions. Whether the line break processing conditions are met is used to indicate whether the text to be processed needs to be processed into line breaks. In response to the detection result indicating that the text to be processed meets the line break processing condition, the display width corresponding to each text object is obtained. The display width corresponding to any text object is used to indicate the display width of the content corresponding to any text object on the display page. In the case that any text object is image text, the display width corresponding to any text object is the width of the image corresponding to any text object. The image corresponding to any text object is obtained by decoding the text object according to the image format corresponding to the text object. The text to be processed is truncated to obtain the first truncated text, which consists of the first candidate text and the truncation marker; the truncation process is used to automatically truncate a line of text according to the display width corresponding to each text object; The width of the truncation mark is used as the width to be padded; in response to the fact that the display width of the first text object to be padded after the first candidate text in the text to be processed does not exceed the width to be padded, the first text object to be padded is used as the first target text object; The difference between the width to be filled and the display width corresponding to the first target text object is used as the first width, and the difference between the first width and the specified width is used as the updated width to be filled. The specified width is set according to the preset spacing width between text objects. In response to the updated width to be padded meeting the width padding condition, the first target text object is used as the first padding text; the first candidate text and the first padding text are concatenated to obtain the first line of target text; In response to the line splitting operation meeting the line splitting termination condition, the first line of target text is used as at least one line of target text obtained after the line splitting of the text to be processed. The content corresponding to each of the at least one line of target text is displayed in separate lines on the display page.
2. The method according to claim 1, characterized in that, The method further includes: In response to the fact that the line break processing operation does not meet the line break processing termination condition, the other texts in the text to be processed, excluding the first line of target text, are taken as the updated text to be processed. The target text is then obtained based on the updated text to be processed until the line break processing operation meets the line break processing termination condition, resulting in at least one line of target text.
3. The method according to claim 1, characterized in that, The method further includes: In response to the updated width to be padded not meeting the width padding condition, based on the updated width to be padded and other text objects in the text to be processed that are located after the first candidate text, the target text objects are continued to be obtained until the updated width to be padded meets the width padding condition. The target text objects obtained when the width padding condition is met are arranged in the order of acquisition to form the first padded text. The other text objects are text objects other than the first text object to be padded.
4. The method according to claim 1, characterized in that, The method further includes: In response to the fact that the display width of the first text object to be padded in the text to be processed, which is located after the first candidate text, exceeds the width to be padded, the empty text is used as the first padded text.
5. The method according to claim 1, characterized in that, The method further includes: Starting from the first text object in the text to be processed, the display widths of each text object are sequentially superimposed until the superposition operation meets the superposition termination condition. The text objects whose display widths have been superimposed when the superposition termination condition is met are arranged in the superposition order to form the first line of target text. In response to the fact that the line break processing operation does not meet the line break processing termination condition, the other texts in the text to be processed, excluding the first line of target text, are taken as the updated text to be processed. The target text is then obtained based on the updated text to be processed until the line break processing operation meets the line break processing termination condition, resulting in at least one line of target text.
6. The method according to any one of claims 1-5, characterized in that, The process of performing line break detection on the text to be processed to obtain the detection result includes: Obtain the initial line number corresponding to the text to be processed, and obtain the detection result based on the initial line number; or, The text to be processed is truncated, and the truncated result is used as the detection result.
7. The method according to claim 6, characterized in that, The method further includes: In response to a detection result indicating that the initial number of lines is greater than a reference value, the detection result is determined to indicate that the text to be processed meets the line break processing condition; or... In response to the detection result being the truncated text corresponding to the text to be processed after truncation, it is determined that the detection result indicates that the text to be processed meets the line break processing condition.
8. A content display device, characterized in that, The device includes: The first acquisition module is used to acquire content to be displayed, which includes an image; convert the content to be displayed to obtain text to be processed corresponding to the content to be displayed, the text to be processed is composed of at least one text object arranged in sequence, the at least one text object includes at least one image text, the image text is obtained by encoding the image in the content to be displayed according to the image format of the image in the content to be displayed; The detection module is used to perform line break detection on the text to be processed and obtain a detection result. The detection result is used to indicate whether the text to be processed meets the line break processing conditions. Whether the line break processing conditions are met is used to indicate whether the text to be processed needs to be processed into line breaks. The second acquisition module is used to, in response to the detection result indicating that the text to be processed meets the line break processing condition, acquire the display width corresponding to each text object respectively. The display width corresponding to any text object is used to indicate the display width of the content corresponding to any text object on the display page. In the case that any text object is image text, the display width corresponding to any text object is the width of the image corresponding to any text object. The image corresponding to any text object is obtained by decoding the text object according to the image format corresponding to the text object. The line-cutting module is used to truncate the text to be processed to obtain a first truncated text, which consists of a first candidate text and a truncation marker. The truncation process automatically truncates a line of text based on the display width of each text object. The width of the truncation marker is used as the padding width. In response to the first padding text object following the first candidate text in the text to be processed having a display width that does not exceed the padding width, the first padding text object is used as the first target text object. The padding width is then compared with the first target text object. The difference in display width corresponding to this object is used as the first width. The difference between the first width and the specified width is used as the updated width to be padded. The specified width is set according to the preset spacing width between text objects. In response to the updated width to be padded meeting the width padding condition, the first target text object is used as the first padded text. The first candidate text and the first padded text are concatenated to obtain the first line of target text. In response to the line splitting operation meeting the line splitting termination condition, the first line of target text is used as at least one line of target text obtained after processing the text to be processed into line splits. The display module is used to display the content corresponding to the at least one line of target text in separate lines on the display page.
9. The apparatus according to claim 8, characterized in that, The line-by-line processing module is further configured to, in response to the line-by-line processing operation not meeting the line-by-line processing termination condition, take the other texts in the text to be processed, excluding the first line of target text, as the updated text to be processed, and continue to obtain target text based on the updated text to be processed until the line-by-line processing operation meets the line-by-line processing termination condition, thereby obtaining at least one line of target text.
10. The apparatus according to claim 8, characterized in that, The line-by-line processing module is further configured to respond to the updated width to be filled not meeting the width filling condition, based on the updated width to be filled and other text objects in the text to be processed that are located after the first candidate text, to continue to obtain target text objects until the updated width to be filled meets the width filling condition, and to arrange the target text objects obtained when the width filling condition is met in the order of acquisition to form the first filled text, wherein the other text objects are text objects other than the first text object to be filled.
11. The apparatus according to claim 8, characterized in that, The line break processing module is further configured to, in response to the situation where the display width of the first text object to be padded after the first candidate text in the text to be processed exceeds the padded width, use the empty text as the first padded text.
12. The apparatus according to claim 8, characterized in that, The line-by-line processing module is further configured to, starting from the first text object in the text to be processed, sequentially superimpose the display widths corresponding to each text object until the superposition operation meets the superposition termination condition, and arrange the text objects whose display widths have been superimposed at the time of superposition termination in the superposition order to form the first line of target text; in response to the line-by-line processing operation not meeting the line-by-line processing termination condition, take the other texts in the text to be processed except the first line of target text as the updated text to be processed, and continue to obtain target text based on the updated text to be processed until the line-by-line processing operation meets the line-by-line processing termination condition, thereby obtaining at least one line of target text.
13. The apparatus according to any one of claims 8-12, characterized in that, The detection module is used to obtain the initial line number corresponding to the text to be processed, and obtain the detection result based on the initial line number; or, to truncate the text to be processed and use the truncation result as the detection result.
14. The apparatus according to claim 13, characterized in that, The device further includes: The determination module is configured to determine, in response to a detection result indicating that the initial number of lines is greater than a reference value, that the detection result indicates that the text to be processed meets the line break processing condition; or, in response to a detection result indicating that the truncated text corresponding to the text to be processed is obtained after truncation processing, that the detection result indicates that the text to be processed meets the line break processing condition.
15. A computer device, characterized in that, The computer device includes a processor and a memory, the memory storing at least one piece of program code, the at least one piece of program code being loaded and executed by the processor to implement the content display method as described in any one of claims 1 to 7.
16. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one piece of program code, which is loaded and executed by a processor to implement the content display method as described in any one of claims 1 to 7.
17. A computer program product, characterized in that, The computer program product includes computer instructions stored in a computer-readable storage medium, a processor of a computer device reading the computer instructions from the computer-readable storage medium, and the processor executing the computer instructions to cause the computer device to perform the content display method as described in any one of claims 1 to 7.