Rich text display method and device of gap system, computer equipment and storage medium
By parsing and processing the label and style inheritance relationships in rich text strings, and combining lightweight rich text components to process the merged strings, the memory consumption and lag problems caused by rich text display in the existing technology are solved, and a more efficient rich text display is achieved.
Patent Information
- Application Number
- CN202510160613.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-13
- Publication Date
- 2025-06-03
- Estimated Expiration
- 2045-02-13
AI Technical Summary
When presenting rich text, existing systems need to use heavyweight rich text components to directly process rich text strings, resulting in large memory resources consumption, resulting in lag and slow response problems.
By parsing multiple tags in rich text strings, determining the style inheritance relationship, assigning the array objects of each tag to the corresponding processor for processing, and combining the processing results, and finally displaying the merged strings through a lightweight rich text component.
It reduces the memory resource consumption of rich text components, reduces the risk of lag, and makes the rich text components of the Hongmeng system more lightweight and efficient.
Smart Images

Figure CN120087331A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of data processing, and in particular, to a method, device, computer device, and storage medium for rich text display in a HarmonyOS system. Background Art
[0002] Currently, the way some systems display rich text is as follows: directly input the rich text string into the rich text component of the system, and the rich text component directly processes the rich text string, so as to display the rich text content on the interface. In this processing method, on the one hand, the rich text component consumes a relatively large amount of memory resources. Moreover, in some scenarios where the rich text component is reused, such as when the rich text component is repeatedly used in a loop in a list component, phenomena such as lag and slow sliding response will occur. Summary of the Invention
[0003] Based on this, in order to solve the above technical problems, it is necessary to provide a method, device, computer device, and storage medium for rich text display in a HarmonyOS system, which does not need to directly process the rich text string using a heavyweight rich text component, but only needs to set the string display of the rich text component to achieve the display of rich text, reducing the memory resource consumption of the rich text component and reducing the lag of the rich text component.
[0004] A method for rich text display in a HarmonyOS system includes: obtaining the string of rich text, parsing multiple tags of the rich text from the string of rich text; determining the style inheritance relationship of the rich text according to the multiple tags of the rich text; parsing an array object of each tag from the string of rich text according to the multiple tags of the rich text; identifying a processor corresponding to each tag according to each tag of the rich text; allocating the array object of each tag to the processor corresponding to each tag, so that the processor corresponding to each tag processes the array object of each tag and outputs a processing result; receiving the processing results output by each processor, and merging the processing results of each processor according to the style inheritance relationship to obtain a merged string; processing the merged string through the rich text component of the HarmonyOS system to display the rich text.
[0005] In one embodiment, the multiple tags include status - type tags and action - type tags. Merging the processing results of each processor according to the style inheritance relationship includes: obtaining the default value corresponding to the pre - configured first tag and the default action corresponding to the second tag, where the first tag is a status - type tag and the second tag is an action - type tag; merging the processing result output by the processor corresponding to the first tag with the corresponding default value to obtain a merged first merged result; merging the processing result output by the processor corresponding to the second tag with the corresponding default action to obtain a merged second merged result; and merging the first merged result, the second merged result, the processing results output by the processors corresponding to non - first tags, and the processing results output by the processors corresponding to non - second tags according to the style inheritance relationship.
[0006] In one embodiment, the status - type tags include one or more of a font tag, a link tag, a bold tag, an italic tag, a number tag, a list tag, and a strikethrough tag, and the action - type tag includes a line - break tag.
[0007] In one embodiment, the multiple tags include an image tag. Assigning the array object of each tag to the processor corresponding to each tag so that the processor corresponding to each tag processes the array object of each tag and outputs a processing result includes: assigning the array object of the image tag to the processor corresponding to the image tag. The array object of the image tag contains image information, and the processor corresponding to the image tag obtains the rich - text image based on the image information and outputs the obtained image as the processing result.
[0008] In one embodiment, if the image information is Base64 - type information, the processor corresponding to the image tag generates an image object based on the image information and outputs the generated image object as the processing result; if the image information is non - Base64 - type information, the image address is parsed from the image information, the image is obtained according to the image address, and the obtained image is output as the processing result.
[0009] In one embodiment, obtaining the image according to the image address includes: obtaining the hash value of the image address, comparing the hash value of the image address with the hash value of the pre - stored cache address; if the comparison is successful, obtaining the image from the cache according to the cache address where the comparison is successful; if the comparison fails, creating a network image download task, downloading the image through the network image download task according to the image address, and caching the downloaded image according to the hash value of the image address.
[0010] In one embodiment, determining the style inheritance relationship of rich text based on multiple tags of the rich text includes: constructing a relationship tree according to the multiple tags of the rich text, where each node of the relationship tree is each tag of the rich text, and the relationship tree represents the style inheritance relationship of the rich text; merging the processing results of each processor according to the style inheritance relationship, including: traversing each node of the relationship tree and merging the processing results of each processor corresponding to each tag according to the traversal result.
[0011] A rich text display device for HarmonyOS includes: an acquisition module, configured to acquire a string of rich text and parse multiple tags of the rich text from the string of rich text; a determination module, configured to determine the style inheritance relationship of the rich text based on the multiple tags of the rich text; a parsing module, configured to parse an array object of each tag from the string of rich text according to the multiple tags of the rich text; an identification module, configured to identify a processor corresponding to each tag according to each tag of the rich text; an allocation module, configured to allocate the array object of each tag to the processor corresponding to each tag, so that the processor corresponding to each tag processes the array object of each tag and outputs a processing result; a merging module, configured to receive the processing results output by each processor and merge the processing results of each processor according to the style inheritance relationship to obtain a merged string; a display processing module, configured to process the merged string through a rich text component of HarmonyOS to display the rich text.
[0012] A computer device includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the steps of the method according to any of the above embodiments are implemented.
[0013] A computer-readable storage medium has a computer program stored thereon. When the computer program is executed by a processor, the steps of the method according to any of the above embodiments are implemented.
[0014] For the above rich text display method, device, computer device, and storage medium for HarmonyOS, acquire a string of rich text, parse multiple tags of the rich text from the string of rich text; determine the style inheritance relationship of the rich text based on the multiple tags of the rich text; parse an array object of each tag from the string of rich text according to the multiple tags of the rich text; identify a processor corresponding to each tag according to each tag of the rich text; allocate the array object of each tag to the processor corresponding to each tag, so that the processor corresponding to each tag processes the array object of each tag and outputs a processing result; receive the processing results output by each processor and merge the processing results of each processor according to the style inheritance relationship to obtain a merged string; process the merged string through a rich text component of HarmonyOS to display the rich text.
[0015] Therefore, the string of rich text is parsed into various array objects according to the tags, and each array object is processed separately by the processors of each tag. Subsequently, the processing results of each processor are merged. The rich text component only needs to process the merged string to display the rich text, without having to process the array objects of each tag, reducing the processing volume of the rich text string and the memory resource consumption of the rich text component in the HarmonyOS system, making the rich text component in the HarmonyOS system more lightweight. In addition, since the rich text component in the HarmonyOS system does not need to process each array object, it can reduce the lag of the rich text component in the HarmonyOS system. Description of the Drawings
[0016] Figure 1 It is an application environment diagram of a rich text display method in the HarmonyOS system in one embodiment;
[0017] Figure 2 It is a schematic flowchart of a rich text display method in the HarmonyOS system in one embodiment;
[0018] Figure 3 It is a schematic flowchart of the processing flow of a rich text display method in the HarmonyOS system in a specific example;
[0019] Figure 4 It is a schematic flowchart of the task processing flow of the image processor in one embodiment;
[0020] Figure 5 It is a structural block diagram of a rich text display device in the HarmonyOS system in one embodiment;
[0021] Figure 6 It is the internal structure diagram of a computer device in one embodiment. Detailed Embodiments
[0022] In order to make the objectives, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0023] A rich text display method provided by the present application is applied to an application environment as Figure 1 shown. As Figure 1 shown, the terminal 100 is used to implement a rich text display method of the present application. Specifically, as Figure 1As shown, the terminal 100 obtains the string of rich text, parses multiple tags of the rich text from the string of rich text; determines the style inheritance relationship of the rich text according to the multiple tags of the rich text; parses the array object of each tag from the string of rich text according to the multiple tags of the rich text; identifies the processor corresponding to each tag according to each tag of the rich text; assigns the array object of each tag to the processor corresponding to each tag, so that the processor corresponding to each tag processes the array object of each tag and outputs a processing result; receives the processing results output by each processor, and merges the processing results of each processor according to the style inheritance relationship to obtain a merged string; processes the merged string through the rich text component of the HarmonyOS to display the rich text. The terminal 100 can be but is not limited to various personal computers, laptop computers, smart phones, tablet computers, etc.
[0024] In one embodiment, as Figure 2 shown, a method for displaying rich text in the HarmonyOS is provided. Taking the method applied to the Figure 1 terminal 100 in it as an example, the method includes the following steps:
[0025] S202, obtain the string of rich text, and parse multiple tags of the rich text from the string of rich text.
[0026] In this embodiment, the rich text is a text format that can display pictures and hyperlinks, and define different font sizes, colors, text bold, strikethrough, etc. It supports tag parsing, such as <font>、 、 、 、 、 etc. It supports the parsing of tag attributes, such as <width> 、 <height> 、 <size> 、 <color> 、 <src> 、 <href>etc. After parsing is completed, the text with pictures, links, and text in different colors can be displayed on a mobile device.
[0027] The rich text string includes multiple types of strings and the tags of each type of string. For example, strings for pictures, hyperlinks, font colors, and font sizes, etc. Each type of string is identified by a corresponding tag.
[0028] S204. Determine the style inheritance relationship of the rich text according to multiple tags of the rich text.
[0029] In this embodiment, there is a certain association relationship between each tag. For example, the text tag depends on the list tag, and the font tag depends on the text tag, etc. Based on the dependency relationship between the tags, the style inheritance relationship of the rich text is determined.
[0030] S206. Parse out an array object of each tag from the rich text string according to multiple tags of the rich text.
[0031] In this embodiment, as described above, the rich text supports tag parsing, such as <font>、< / font> < / href> < / src> < / color> < / size> < / height> < / width> <font>、 、 、 、 < / font> <font> etc. It also supports parsing of tag attributes, such as <width> 、 <height> 、 <size> 、 <color> 、 <src> 、 <href>And so on. Store the parsed string in the form of an array object and save the stored link address for subsequent calls.
[0032] S208. Identify the processors corresponding to each tag according to the tags of the rich text.
[0033] In this embodiment, configure the corresponding processors based on each tag. For example, configure an image processor based on the image tag, configure a font processor based on the font tag, configure a link processor based on the link tag, and so on. Furthermore, obtain the processors corresponding to each tag of the rich text.
[0034] S210. Assign the array objects of each tag to the processors corresponding to each tag, so that the processors corresponding to each tag process the array objects of each tag and output the processing results.
[0035] In this embodiment, assign the array objects of each tag to the processors corresponding to each tag. Furthermore, the processor processes the content of the array object corresponding to it and outputs the processing result. For example, the processor of the image tag processes the array object corresponding to the image tag.
[0036] In one embodiment, among the multiple tags, there is an image tag. The step of assigning the array objects of each tag to the processors corresponding to each tag, so that the processors corresponding to each tag process the array objects of each tag and output the processing results, includes: assigning the array object of the image tag to the processor corresponding to the image tag. The array object of the image tag contains image information. The processor corresponding to the image tag obtains the image of the rich text based on the image information and outputs the obtained image as the processing result.
[0037] Wherein, if the image information is Base64 type information, the processor corresponding to the image tag generates an image object based on the image information and outputs the generated image object as the processing result; if the image information is non - Base64 type information, parse out the image address from the image information, obtain the image according to the image address, and output the obtained image as the processing result.
[0038] In one example, the step of obtaining the image according to the image address includes: obtaining the hash value of the image address, comparing the hash value of the image address with the hash value of the pre - stored cache address; if the comparison is successful, obtain the image from the cache according to the cache address of the successful comparison; if the comparison fails, create a network image download task, download the image through the network image download task and according to the image address, and cache the downloaded image according to the hash value of the image address.
[0039] In this embodiment, for the string of the picture tag, the picture information can be information that can be converted into the corresponding picture or picture address information, and is specifically identified by the type of the picture information. If its type is the Base64 type, it indicates that it can be directly converted into a picture, and the picture conversion can be performed by the processor. If it is not of the Base64 type, it is determined as picture address information, and the picture can be obtained according to the parsed picture address for output. Among them, there are two ways to obtain the picture according to the picture address. One is to obtain the picture from the local storage through the picture address, and the other is to download the picture from the outside according to the picture address. Specifically, if the picture is cached locally, the hash value of the cache address is stored. When parsing the picture address from the string of the rich text, the hash value of the picture address is compared with the hash value of the cache address. If the comparison is successful, it indicates that the corresponding picture is cached locally. If the comparison fails, it indicates that there is no local cache for its corresponding picture.
[0040] If it is confirmed that there is no local cache for its corresponding picture, a network picture download task is automatically created, the corresponding picture is downloaded through the picture address, and the downloaded picture is cached according to the hash value of the picture address, so that when the picture is used later, it can be directly obtained from the cache without downloading the picture again. Therefore, the local cache resources can be reused, the bandwidth occupation can be reduced, and fast display can be achieved, providing a good experience for users.
[0041] S212, receive the processing results output by each processor, and merge the processing results of each processor according to the style inheritance relationship to obtain the merged string.
[0042] In this embodiment, the style inheritance relationship represents the inheritance and dependency relationship of the string of the rich text when it is displayed on the interface. After each processor has completed the corresponding string processing, the processing results of each processor are merged according to the style inheritance relationship, so that the logical relationship of the merged string corresponds one by one to the string in the original rich text.
[0043] In one embodiment, the step of determining the style inheritance relationship of the rich text according to multiple tags of the rich text includes: constructing a relationship tree according to multiple tags of the rich text, each node of the relationship tree being each tag of the rich text, and the relationship tree representing the style inheritance relationship of the rich text; the step of merging the processing results of each processor according to the style inheritance relationship includes: traversing each node of the relationship tree, and merging the processing results of each processor corresponding to each tag according to the traversal result.
[0044] In this embodiment, the style inheritance relationship of the rich text is represented by constructing a relationship tree. Furthermore, when merging the processing results of each processor, the processing results of each processor can be gradually merged by traversing the relationship tree, thereby improving the merging efficiency of each processing result.
[0045] In one embodiment, the multiple tags include status tags and action tags. The step of merging the processing results of each processor according to the style inheritance relationship includes: obtaining the default value corresponding to the pre-configured first tag and the default action corresponding to the second tag, where the first tag is a status tag and the second tag is an action tag; merging the processing result output by the processor corresponding to the first tag with the corresponding default value to obtain a first merged result; merging the processing result output by the processor corresponding to the second tag with the corresponding default action to obtain a second merged result; merging the first merged result, the second merged result, the processing results output by the processors other than the first tag, and the processing results output by the processors other than the second tag according to the style inheritance relationship. Among them, the status tags include one or more of font tags, link tags, bold tags, italic tags, number tags, list tags, and strikethrough tags, and the action tags include line break tags.
[0046] Specifically, the string of the status tag corresponds to static rich text when displayed on the interface. The string of the action tag corresponds to dynamic and operable rich text when displayed on the interface. The default value corresponding to the status tag and the default action of the action tag are pre-configured. When the processor corresponding to the status tag outputs a processing result, the processing result is merged with the default value to obtain a first merged result. When the processor corresponding to the action tag outputs a processing result, the processing result is merged with the default action to obtain a second merged result. Then, the processing results, the first merged result, and the second merged result are processed according to the style inheritance relationship.
[0047] If the traditional rich text processing method is adopted, that is, the entire process of directly processing the string of the rich text by using a rich text component, it is impossible to perform personalized processing on the display of the rich text, and only the style specified by the string of the rich text can be passively displayed. In this embodiment, after each processor processes the corresponding string in the original rich text, its processing result is merged with the default value or default action configured manually, and then the final merging process is performed, which can increase the personalized processing configuration and make the finally displayed rich text meet the flexible usage requirements of users. That is, in this embodiment, the parsing and rendering of the string of the rich text are decoupled. After the parsed string of the rich text is processed by the processor, the output processing result is merged with other business operations and then the final rendering operation is performed, so that the display consistency of multiple platforms can be achieved through manual operations.
[0048] For example, for the string display of character tags in rich text, after the output of the character processor is processed, the default value of the character can be merged with the processing result, so as to display the default value of the character during the final rendering. For the string display of line break tags in rich text, after the output of the line break processor is processed, the default action of the line break can be merged with the processing result, so as to provide the default action of the line break during the final rendering.
[0049] S214, process the merged string through the rich text component of the HarmonyOS to display the rich text.
[0050] In this embodiment, the terminal is configured with the HarmonyOS. The rich text component of the HarmonyOS only needs to process the merged string to render the rich text on the interface. Specifically, the merged string includes color, size, font weight, font, picture information, etc. After merging, a StyledString (attribute string) is generated for the rich text component of the HarmonyOS to process, so as to render the rich text on the interface. Traditional rich text processing method: The rich text component directly processes the string of the rich text, that is, processes the strings of each tag respectively according to the style inheritance relationship, and finally displays the processing result on the interface, that is, displays the rich text. In this embodiment, the rich text component of the HarmonyOS only needs to process the merged string to display the rich text, so a more lightweight text component can be used. For example, the Text component can be used to process the merged string to display the rich text. The Text component is a lightweight text display component that supports the general display of rich text and can meet the functional requirements of rich text display in this embodiment.
[0051] For the above rich text display method of the HarmonyOS, the string of the rich text is parsed into each array object according to the tags, and is processed separately by the processors of each tag. Subsequently, the processing results of each processor are merged. The rich text component only needs to process the merged string to display the rich text, without having to process the array objects of each tag, reducing the processing volume of the rich text string and reducing the memory resource consumption of the rich text component of the HarmonyOS, making the rich text component of the HarmonyOS more lightweight. In addition, the rich text component of the HarmonyOS does not need to process each array object, which can reduce the lag of the rich text component of the HarmonyOS.
[0052] For the above rich text display method of the HarmonyOS, a specific example is provided below for illustration, specifically in combination with< / href> < / src> < / color> < / size> < / height> < / width> Figure 3 The processing flow shown below:
[0053] First, parse the rich text string: Using the method of string traversal and regular replacement, parse the rich text string into an array object by nodes. During the parsing process, the style inheritance relationship and the preservation of the link address will be processed for subsequent use in generating the StyledString.
[0054] Furthermore, generate the StyledString: Traverse the array object parsed in the first step, input the array object into the processors of each tag of the rich text, and let the processors independently process the corresponding array object and output the processing results. Different processors only perform tasks related to their own tags, such as adding font colors and sizes. Finally, merge the processing results of each processor and return them to generate a complete StyledString.
[0055] Among them, the logical task of the image processor is relatively complex. It is necessary to judge whether the image address is of the Base64 type. If it is, directly generate an image object with the Base64 type string; if not, it is also necessary to judge whether there is a cache of the current image address on the user device; if there is a cache, create a file manager and read the locally cached image object according to the hash value of the image address; if there is no cache, create an image resource download task, and after the download task is completed, store the image object in the cache directory according to the hash value of the image address for subsequent rendering use. See the specific process in Figure 4 shown below. Therefore, by judging the image address type, it is compatible with images of various different formats. By setting the image cache, the image display can be accelerated and the consumption of the user's network resources can be reduced.
[0056] Finally, render the StyledString: Based on the Text component provided by the HarmonyOS system, a controller can be bound to this component and set and take effect through the system API after the StyledString is generated.
[0057] The above method for displaying rich text on the HarmonyOS system can achieve:
[0058] 1. Display consistency: Utilizing the highly customizable ability, it achieves the same display effect as the iOS and Android platforms.
[0059] 2. Performance optimization: Compared with the performance disadvantages of the system component RichText, this solution is based on a lighter-weight Text for rendering, greatly reducing performance consumption.
[0060] 3. Ability decoupling: This solution separates the parsing logic and the rendering logic to generate StyledString for usage scenarios other than rendering.
[0061] 4. Image caching: This solution caches image resources that affect the rendering time. When the rich text is rendered again, the effect can be quickly displayed. There is no intermediate transition state of downloading, enhancing the user experience.
[0062] It should be understood that although the steps in the flowchart are shown in sequence according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless there is a clear description in this article, there is no strict order limit for the execution of these steps, and these steps can be executed in other orders. Moreover, at least some of the steps in the accompanying drawings may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential either, but can be executed alternately or in turn with at least a part of other steps or sub-steps or stages of other steps.
[0063] This application also provides a rich text display device for the HarmonyOS. As Figure 5 shown, a rich text display device for the HarmonyOS includes an acquisition module 502, a determination module 504, a parsing module 506, an identification module 508, an allocation module 510, a merging module 512, and a display processing module 514. The acquisition module 502 is used to acquire the string of the rich text and parse out multiple tags of the rich text from the string of the rich text; the determination module 504 is used to determine the style inheritance relationship of the rich text according to the multiple tags of the rich text; the parsing module 506 is used to parse out the array object of each tag from the string of the rich text according to the multiple tags of the rich text; the identification module 508 is used to identify the processor corresponding to each tag according to each tag of the rich text; the allocation module 510 is used to allocate the array object of each tag to the processor corresponding to each tag, so that the processor corresponding to each tag processes the array object of each tag and outputs a processing result; the merging module 512 is used to receive the processing results output by each processor and merge the processing results of each processor according to the style inheritance relationship to obtain a merged string; the display processing module 514 is used to process the merged string through the rich text component of the HarmonyOS to display the rich text.
[0064] In one embodiment, the multiple tags include status tags and action tags. Merging the processing results of each processor according to the style inheritance relationship includes: obtaining the default value corresponding to the pre-configured first tag and the default action corresponding to the second tag, where the first tag is a status tag and the second tag is an action tag; merging the processing result output by the processor corresponding to the first tag with the corresponding default value to obtain a merged first merged result; merging the processing result output by the processor corresponding to the second tag with the corresponding default action to obtain a merged second merged result; merging the first merged result, the second merged result, the processing results output by the processors corresponding to non-first tags, and the processing results output by the processors corresponding to non-second tags according to the style inheritance relationship.
[0065] In one embodiment, the status tags include one or more of a font tag, a link tag, a bold tag, an italic tag, a number tag, a list tag, and a strikethrough tag, and the action tag includes a line break tag.
[0066] In one embodiment, the multiple tags include an image tag. Assigning the array object of each tag to the processor corresponding to each tag so that the processor corresponding to each tag processes the array object of each tag and outputs a processing result includes: assigning the array object of the image tag to the processor corresponding to the image tag. The array object of the image tag contains image information. The processor corresponding to the image tag obtains the image of the rich text based on the image information and outputs the obtained image as the processing result.
[0067] In one embodiment, if the image information is Base64 type information, the processor corresponding to the image tag generates an image object based on the image information and outputs the generated image object as the processing result; if the image information is non-Base64 type information, the image address is parsed from the image information, the image is obtained according to the image address, and the obtained image is output as the processing result.
[0068] In one embodiment, obtaining the image according to the image address includes: obtaining the hash value of the image address, comparing the hash value of the image address with the hash value of the pre-stored cache address; if the comparison is successful, obtaining the image from the cache according to the cache address of the successful comparison; if the comparison fails, creating a network image download task, downloading the image through the network image download task and according to the image address, and caching the downloaded image according to the hash value of the image address.
[0069] In one embodiment, determining the style inheritance relationship of rich text according to multiple tags of the rich text includes: constructing a relationship tree according to the multiple tags of the rich text, where each node of the relationship tree is each tag of the rich text, and the relationship tree represents the style inheritance relationship of the rich text; merging the processing results of each processor according to the style inheritance relationship, including: traversing each node of the relationship tree and merging the processing results of each processor corresponding to each tag according to the traversal result.
[0070] For the specific limitations of a rich text display device of a HarmonyOS system, reference can be made to the limitations of a rich text display method of a HarmonyOS system in the above text, which will not be elaborated here. Each module in the above rich text display device of a HarmonyOS system can be implemented in whole or in part by software, hardware, and their combination. The above modules can be embedded in or independent of the processor in the computer device in the form of hardware, or stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0071] In one embodiment, a computer device is provided. The computer device can be a terminal, and its internal structure diagram can be as Figure 6 shown. The computer device includes a processor, a memory, a network interface, a display screen, and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used for communication connection through the network. When the computer program is executed by the processor, it implements a rich text display method of a HarmonyOS system. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer covered on the display screen, or a button, a trackball, or a touchpad set on the shell of the computer device, or an external keyboard, touchpad, or mouse, etc.
[0072] Those skilled in the art can understand that Figure 6 the structure shown in
[0073] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the following steps are implemented: obtaining a string of rich text, and parsing multiple tags of the rich text from the string of rich text; determining a style inheritance relationship of the rich text according to the multiple tags of the rich text; parsing an array object of each tag from the string of rich text according to the multiple tags of the rich text; identifying a processor corresponding to each tag according to each tag of the rich text; allocating the array object of each tag to the processor corresponding to each tag, so that the processor corresponding to each tag processes the array object of each tag and outputs a processing result; receiving the processing results output by each processor, and merging the processing results of each processor according to the style inheritance relationship to obtain a merged string; processing the merged string through a rich text component of the HarmonyOS to display the rich text.
[0074] In one of the embodiments, the multiple tags include status tags and action tags. When the processor executes the computer program to implement the above step of merging the processing results of each processor according to the style inheritance relationship, the following steps are specifically implemented: obtaining a default value corresponding to a first tag and a default action corresponding to a second tag that are pre-configured, where the first tag is a status tag and the second tag is an action tag; merging the processing result output by the processor corresponding to the first tag with the corresponding default value to obtain a first merged result after merging; merging the processing result output by the processor corresponding to the second tag with the corresponding default action to obtain a second merged result after merging; merging the first merged result, the second merged result, the processing results output by the processors corresponding to non-first tags, and the processing results output by the processors corresponding to non-second tags according to the style inheritance relationship.
[0075] In one of the embodiments, the status tags include one or more of a font tag, a link tag, a bold tag, an italic tag, a number tag, a list tag, and a strikethrough tag, and the action tag includes a line break tag.
[0076] In one of the embodiments, the multiple tags include a picture tag. When the processor executes the computer program to implement the above step of allocating the array object of each tag to the processor corresponding to each tag, so that the processor corresponding to each tag processes the array object of each tag and outputs a processing result, the following steps are specifically implemented: allocating the array object of the picture tag to the processor corresponding to the picture tag, where the array object of the picture tag contains picture information, and the processor corresponding to the picture tag obtains a picture of the rich text based on the picture information and outputs the obtained picture as a processing result.
[0077] In one embodiment, if the picture information is Base64 type information, the processor corresponding to the picture tag generates a picture object based on the picture information and outputs the generated picture object as a processing result; if the picture information is not Base64 type information, the picture address is parsed from the picture information, the picture is obtained according to the picture address, and the obtained picture is output as a processing result.
[0078] In one embodiment, when the processor executes a computer program to implement the above step of obtaining a picture according to a picture address, the following steps are specifically implemented: obtaining the hash value of the picture address, comparing the hash value of the picture address with the hash value of the pre-stored cache address; if the comparison is successful, obtaining the picture from the cache according to the cache address with which the comparison is successful; if the comparison fails, creating a network picture download task, downloading the picture through the network picture download task and according to the picture address, and caching the downloaded picture according to the hash value of the picture address.
[0079] In one embodiment, when the processor executes a computer program to implement the above step of determining the style inheritance relationship of rich text according to multiple tags of rich text, the following steps are specifically implemented: constructing a relationship tree according to multiple tags of rich text, each node of the relationship tree being each tag of the rich text, and the relationship tree representing the style inheritance relationship of the rich text; when the processor executes a computer program to implement the above step of merging the processing results of each processor according to the style inheritance relationship, the following steps are specifically implemented: traversing each node of the relationship tree and merging the processing results of each processor corresponding to each tag according to the traversal result.
[0080] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented: obtaining a rich text string, parsing multiple tags of the rich text from the rich text string; determining the style inheritance relationship of the rich text according to the multiple tags of the rich text; parsing an array object of each tag from the rich text string according to the multiple tags of the rich text; identifying a processor corresponding to each tag according to each tag of the rich text; allocating the array object of each tag to the processor corresponding to each tag, so that the processor corresponding to each tag processes the array object of each tag and outputs a processing result; receiving the processing results output by each processor, and merging the processing results of each processor according to the style inheritance relationship to obtain a merged string; processing the merged string through a rich text component of the HarmonyOS to display the rich text.
[0081] In one embodiment, the multiple tags include status tags and action tags. When the computer program is executed by a processor to implement the step of merging the processing results of each processor according to the style inheritance relationship as described above, the following steps are specifically implemented: obtaining the default value corresponding to the pre-configured first tag and the default action corresponding to the second tag, where the first tag is a status tag and the second tag is an action tag; merging the processing result output by the processor corresponding to the first tag with the corresponding default value to obtain a merged first merged result; merging the processing result output by the processor corresponding to the second tag with the corresponding default action to obtain a merged second merged result; and merging the first merged result, the second merged result, the processing results output by the processors corresponding to non-first tags, and the processing results output by the processors corresponding to non-second tags according to the style inheritance relationship.
[0082] In one embodiment, the status tags include one or more of a font tag, a link tag, a bold tag, an italic tag, a number tag, a list tag, and a strikethrough tag, and the action tag includes a line break tag.
[0083] In one embodiment, the multiple tags include an image tag. When the computer program is executed by a processor to implement the step of allocating the array object of each tag to the processor corresponding to each tag, so that the processor corresponding to each tag processes the array object of each tag and outputs a processing result, the following steps are specifically implemented: allocating the array object of the image tag to the processor corresponding to the image tag, where the array object of the image tag contains image information, and the processor corresponding to the image tag obtains the image of the rich text based on the image information and outputs the obtained image as the processing result.
[0084] In one embodiment, if the image information is of the Base64 type, the processor corresponding to the image tag generates an image object based on the image information and outputs the generated image object as the processing result; if the image information is of a non-Base64 type, the image address is parsed from the image information, the image is obtained according to the image address, and the obtained image is output as the processing result.
[0085] In one embodiment, when the computer program is executed by a processor to implement the step of obtaining an image according to the image address, the following steps are specifically implemented: obtaining the hash value of the image address, comparing the hash value of the image address with the hash value of the pre-stored cache address; if the comparison is successful, obtaining the image from the cache according to the cache address where the comparison is successful; if the comparison fails, creating a network image download task, downloading the image through the network image download task according to the image address, and caching the downloaded image according to the hash value of the image address.
[0086] In one of the embodiments, when the computer program is executed by the processor to implement the steps of determining the style inheritance relationship of the rich text based on the multiple tags of the rich text as described above, the following steps are specifically implemented: constructing a relationship tree according to the multiple tags of the rich text, where each node of the relationship tree is each tag of the rich text, and the relationship tree represents the style inheritance relationship of the rich text; when the computer program is executed by the processor to implement the steps of merging the processing results of each processor according to the style inheritance relationship as described above, the following steps are specifically implemented: traversing each node of the relationship tree, and merging the processing results of each processor corresponding to each tag according to the traversal result.
[0087] Those of ordinary skill in the art can understand that all or part of the processes of implementing the methods in the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, storage, database, or other medium used in the embodiments provided in the present application can include non-volatile and / or volatile memories. Non-volatile memories can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memories can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0088] The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity of description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope described in this specification.
[0089] The above-described embodiments merely represent several implementation manners of the present application. Their descriptions are relatively specific and detailed, but they should not be construed as limiting the scope of the invention patent. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present application, several modifications and improvements can still be made, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application should be subject to the appended claims. < / font> < / font>
Claims
1. A rich text display method of Hongmeng system, characterized in that: The method comprises: Obtain a rich text string, and parse multiple rich text tags from the rich text string; Determining a style inheritance relationship of the rich text according to multiple tags of the rich text; Parsing the array objects of the labels from the character string of the rich text according to the multiple labels of the rich text; Identify a processor corresponding to each tag according to each tag of the rich text; Allocate the array object of each label to the processor corresponding to each label, so that the processor corresponding to each label processes the array object of each label and outputs the processing result; receiving processing results output by each processor, and merging the processing results of each processor according to the style inheritance relationship to obtain a merged string; The merged string is processed by the rich text component of the Hongmeng system to display the rich text.
2. The method according to claim 1, characterized in that The multiple tags include state tags and action tags, and merging the processing results of each processor according to the style inheritance relationship includes: Obtain a pre-configured default value corresponding to a first tag and a default action corresponding to a second tag, wherein the first tag is a state tag and the second tag is an action tag; Merging the processing result output by the processor corresponding to the first tag with the corresponding default value to obtain a first merged result; Merging the processing result output by the processor corresponding to the second tag with the corresponding default action to obtain a merged second merged result; The first merging result, the second merging result, the processing result output by the processor not corresponding to the first tag, and the processing result output by the processor not corresponding to the second tag are merged according to the style inheritance relationship.
3. The method according to claim 2, characterized in that The state tags include one or more of a font tag, a link tag, a bold tag, an italic tag, a number tag, a list tag, and a strikethrough tag, and the action tags include a line break tag.
4. The method according to claim 1, characterized in that The multiple tags include a picture tag, and the array objects of each tag are allocated to the processors corresponding to each tag, so that the processors corresponding to each tag process the array objects of each tag and output the processing results, including: Assign the array object of the picture tag to the processor corresponding to the picture tag, the array object of the picture tag contains picture information, the processor corresponding to the picture tag obtains the picture of the rich text based on the picture information, and outputs the obtained picture as a processing result.
5. The method according to claim 4, characterized in that If the picture information is Base64 type information, the processor corresponding to the picture tag generates a picture object based on the picture information, and outputs the generated picture object as a processing result; If the picture information is non-Base64 type information, the picture address is parsed from the picture information, the picture is obtained according to the picture address, and the obtained picture is output as a processing result.
6. The method according to claim 5, characterized in that The acquiring the picture according to the picture address includes: Obtaining a hash value of the image address, and comparing the hash value of the image address with a hash value of a pre-stored cache address; If the comparison is successful, the image is obtained from the cache according to the cache address where the comparison is successful; If the comparison fails, a network image download task is created, the image is downloaded according to the image address through the network image download task, and the downloaded image is cached according to the hash value of the image address.
7. The method according to claim 1, characterized in that The determining the style inheritance relationship of the rich text according to the multiple tags of the rich text includes: Constructing a relationship tree according to the multiple tags of the rich text, each node of the relationship tree is a tag of the rich text, and the relationship tree represents the style inheritance relationship of the rich text; The merging of the processing results of each processor according to the style inheritance relationship includes: Each node of the relationship tree is traversed, and the processing results of each processor corresponding to each label are merged according to the traversal result.
8. A rich text display device of Hongmeng system, characterized in that: The device comprises: An acquisition module is used to acquire a string of rich text and parse multiple tags of the rich text from the string of rich text; A determination module, used to determine the style inheritance relationship of the rich text according to multiple tags of the rich text; A parsing module, used for parsing the array objects of each tag from the string of the rich text according to the multiple tags of the rich text; An identification module, used to identify a processor corresponding to each tag according to each tag of the rich text; An allocation module, used to allocate the array objects of each label to the processors corresponding to each label, so that the processors corresponding to each label process the array objects of each label and output the processing results; A merging module, used for receiving the processing results output by each processor, and merging the processing results of each processor according to the style inheritance relationship to obtain a merged string; A display processing module is used to process the merged string through the rich text component of the Hongmeng system to display the rich text.
9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Method for analyzing marking language document and analyzer
CN101329665A
Method and system for cross-label processing of html rich text data with format
CN103530430A
Method and system for presenting webpage by native user interface assembly
CN106371844A
WeChat applet rich text conversion method based on an education system and electronic equipment
CN109582932A
Image-text display control method and device and electronic equipment
CN111708535A