A method and device for displaying a rich text in a harmonious system, a computer device and a storage medium
By parsing the tags in the rich text string and assigning them to the processor for processing, and then merging the processing results for display by a lightweight component, the memory consumption and lag issues of rich text components are solved, achieving efficient rich text display.
Patent Information
- Application Number
- CN202510160613.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-13
- Publication Date
- 2026-01-23
- Estimated Expiration
- 2045-02-13
AI Technical Summary
In existing technologies, rich text components consume a lot of memory resources, especially in scenarios with repeated use, which can lead to lag and slow scrolling response.
By parsing multiple tags in the rich text string, assigning them to the corresponding processors for processing, and merging the processing results according to style inheritance relationships, the direct processing of the rich text component is reduced, and a lightweight component is used to display the rich text.
It reduces the memory consumption of rich text components, improves response speed, achieves lightweight rich text display, and supports consistent display across multiple platforms.
Smart Images

Figure CN120087331B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to a rich text display method, apparatus, computer device, and storage medium for the HarmonyOS system. Background Technology
[0002] Currently, some systems display rich text by directly inputting the rich text string into the system's rich text component, which then processes the string and displays the rich text content on the interface. This approach has two drawbacks: firstly, rich text components consume significant memory resources; secondly, in scenarios where rich text components are used repeatedly, such as looping through a list component, stuttering and slow scrolling response may occur. Summary of the Invention
[0003] Therefore, it is necessary to provide a rich text display method, device, computer equipment, and storage medium for the HarmonyOS system to address the above-mentioned technical problems. This eliminates the need to use heavyweight rich text components to directly process rich text strings. Instead, it only requires setting the string display of the rich text component to achieve rich text display, thereby reducing the memory resource consumption of the rich text component and reducing its lag.
[0004] A rich text display method for the HarmonyOS system includes: obtaining a string of rich text; parsing multiple tags from the rich text string; determining the style inheritance relationship of the rich text based on the multiple tags; parsing array objects of each tag from the rich text string based on the multiple tags; identifying the processor corresponding to each tag based on each tag; assigning the array objects of each tag to the processor corresponding to each tag, so that the processor corresponding to each tag processes the array objects of each tag and outputs the 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; and processing the merged string through the rich text component of the HarmonyOS system to display the rich text.
[0005] In one embodiment, multiple tags include state tags and action tags. The processing results of each processor are merged according to style inheritance relationships, including: obtaining the default value corresponding to a pre-configured first tag and the default action corresponding to a second tag, where 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 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, and the processing results output by processors not corresponding to the first tag and processors not corresponding to the second tag according to style inheritance relationships.
[0006] In one embodiment, status tags include one or more of font tags, link tags, bold tags, italic tags, number tags, list tags, and strikethrough tags, and action tags include line break tags.
[0007] In one embodiment, the multiple tags include image tags. The array objects of each tag are assigned 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. This includes: assigning the array objects of image tags to the processors corresponding to the image tags, the array objects of the image tags containing image information, the processors corresponding to the image tags obtaining rich text images based on the image information, and outputting the obtained images as the processing results.
[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 not 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, retrieving an image based on an image address includes: obtaining the hash value of the image address; comparing the hash value of the image address with the hash value of a pre-stored cache address; if the comparison is successful, retrieving the image from the cache based on the successfully compared cache address; if the comparison fails, creating a network image download task, downloading the image using the network image download task and based on the image address, and caching the downloaded image based on the hash value of the image address.
[0010] In one embodiment, determining the style inheritance relationship of the rich text based on multiple tags of the rich text includes: constructing a relationship tree based on the multiple tags of the rich text, where 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; merging the processing results of each processor based on 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 results.
[0011] A rich text display device based on the HarmonyOS system includes: an acquisition module for acquiring a string of rich text and parsing multiple tags from the string; a determination module for determining the style inheritance relationship of the rich text based on the multiple tags; a parsing module for parsing an array object of each tag from the string of rich text based on the multiple tags; a recognition module for recognizing the processor corresponding to each tag based on the tags; an allocation module for allocating the array objects of each tag to the processor corresponding to each tag, so that the processor corresponding to each tag processes the array objects of each tag and outputs the processing result; a merging module 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; and a display processing module for processing the merged string through the rich text component of the HarmonyOS system to display the rich text.
[0012] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of any of the methods described above.
[0013] A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of any of the methods described above.
[0014] The aforementioned rich text display method, apparatus, computer device, and storage medium for the HarmonyOS system involve: acquiring a rich text string; parsing multiple tags from the rich text string; determining the style inheritance relationship of the rich text based on the multiple tags; parsing array objects of each tag from the rich text string; identifying the processor corresponding to each tag; assigning the array objects of each tag to the corresponding processor, so that the processor processes the array objects of each tag and outputs the processing results; 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; and processing the merged string through the rich text component of the HarmonyOS system to display the rich text.
[0015] Therefore, the rich text string is parsed into array objects according to tags, and each tag's processor handles these objects separately. The processing results are then merged. The rich text component only needs to process the merged string to display the rich text, without needing to process the array objects of each tag. This reduces the amount of string processing and the memory resource consumption of the HarmonyOS rich text component, making it more lightweight. Furthermore, since the HarmonyOS rich text component does not need to process individual array objects, it reduces lag issues. Attached Figure Description
[0016] Figure 1 This is an application environment diagram of a rich text display method for the HarmonyOS system in one embodiment.
[0017] Figure 2 This is a flowchart illustrating a rich text display method for the HarmonyOS system in one embodiment.
[0018] Figure 3 This is a schematic diagram illustrating the processing flow of a rich text display method in the HarmonyOS system, as shown in a specific example.
[0019] Figure 4 This is a schematic diagram of the task processing flow of an image processor in one embodiment;
[0020] Figure 5 This is a structural block diagram of a rich text display device based on the HarmonyOS system in one embodiment.
[0021] Figure 6 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0022] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0023] This application provides a rich text display method for the HarmonyOS system, applicable to, for example... Figure 1 The application environment shown. For example... Figure 1 As shown, terminal 100 is used to implement a rich text display method for the HarmonyOS system according to this application. Specifically, as... Figure 1As shown, terminal 100 acquires a rich text string, parses multiple tags from the rich text string, determines the style inheritance relationship of the rich text based on the multiple tags, parses array objects of each tag from the rich text string, identifies the processor corresponding to each tag, assigns the array objects of each tag to the corresponding processor, so that the processor of each tag processes the array objects of each tag and outputs the 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, and processes the merged string through the rich text component of the HarmonyOS system to display the rich text. Terminal 100 can be, but is not limited to, various personal computers, laptops, smartphones, and tablets.
[0024] In one embodiment, such as Figure 2 As shown, a rich text display method for the HarmonyOS system is provided, which is then applied to... Figure 1 Taking terminal 100 as an example, the explanation includes the following steps:
[0025] S202, obtain the rich text string, and parse out multiple tags from the rich text string.
[0026] In this embodiment, rich text is a text format that can display images and hyperlinks, and define different font sizes and colors, text bolding, strikethrough, etc. It supports tag parsing, such as... <font>、 、 、 、 、 It supports tag attribute parsing, such as... <width> 、 <height> 、 <size> 、 <color> 、 <src> 、 <href>After parsing, the text can be displayed on mobile devices, including images, links, and text in different colors.
[0027] Rich text strings include multiple string types and tags for each type. Examples include image strings, hyperlink strings, font color strings, and font size strings. Each string type is identified by its corresponding tag.
[0028] S204 determines the style inheritance relationship of the rich text based on multiple tags of the rich text.
[0029] In this embodiment, there are certain relationships between the various tags. For example, the text tag depends on the list tag, and the font tag depends on the text tag. Based on the dependencies between tags, the style inheritance relationship of the rich text is determined.
[0030] S206, Parse an array object of each tag from the string of the rich text based on the multiple tags of the rich text.
[0031] In this embodiment, as explained above, the rich text can support tag parsing, such as... <font>、< / font> < / href> < / src> < / color> < / size> < / height> < / width> <font>、 、 、 、 < / font> <font> It can also support tag attribute parsing, such as... <width> 、 <height> 、 <size> 、 <color> 、 <src> 、 <href>The parsed string is stored as an array object, and its storage address is saved for later use.
[0032] S208 identifies the processor corresponding to each tag based on the tags of the rich text.
[0033] In this embodiment, a corresponding processor is configured based on each tag. For example, an image processor is configured based on the image tag, a font processor is configured based on the font tag, and a link processor is configured based on the link tag. This allows the processor corresponding to each tag of the rich text to be obtained.
[0034] S210, assign the array objects of each tag to the processor corresponding to each tag, so that the processor corresponding to each tag can process the array objects of each tag and output the processing results.
[0035] In this embodiment, the array object of each tag is assigned to the processor corresponding to each tag. The processor then processes the contents of its corresponding array object and outputs the processing result. For example, the processor for the image tag processes the array object corresponding to the image tag.
[0036] In one embodiment, the multiple tags include image tags. The step of assigning the array objects of each tag to the processor corresponding to each tag, so that the processor corresponding to each tag processes the array objects of each tag and outputs the processing result, includes: assigning the array objects of image tags to the processor corresponding to the image tags, wherein the array objects of image tags contain image information, the processor corresponding to the image tags obtains the rich text image based on the image information, and outputs the obtained image as the processing result.
[0037] If the image information is 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 not Base64 type, the image address is parsed from the image information, the image is obtained based on the image address, and the obtained image is output as the processing result.
[0038] In one example, the steps for retrieving an image based on its URL include: obtaining the hash value of the image URL; comparing the hash value of the image URL with the hash value of a pre-stored cache address; if the comparison is successful, retrieving the image from the cache based on the successfully compared cache address; if the comparison fails, creating a network image download task, downloading the image using the network image download task and based on the image URL, and caching the downloaded image based on the hash value of the image URL.
[0039] In this embodiment, the image information for the image tag string can be either information that can be converted into a corresponding image or image address information, specifically identified by the type of image information. If its type is Base64, it indicates that it can be directly converted into an image, and the processor can perform the image conversion. If it is not Base64, it is determined to be image address information, and the image can be obtained and output based on the parsed image address. There are two ways to obtain the image based on the image address. One is to obtain the image from local storage using the image address, and the other is to download the image from an external source using the image address. Specifically, if the image is cached locally, the hash value of the cache address is stored. When parsing the image address from the rich text string, the hash value of the image address is compared with the hash value of the cache address. If the comparison is successful, it indicates that the corresponding image is cached locally; if the comparison fails, it indicates that the corresponding image is not cached locally.
[0040] If it's confirmed that the corresponding image isn't cached locally, a network image download task is automatically created. The image is downloaded using its URL, and then cached based on the hash value of that URL. This allows the image to be retrieved directly from the cache when needed later, eliminating the need to download it again. Therefore, local cached resources can be reused, reducing bandwidth consumption and enabling faster display, providing a better user experience.
[0041] S212 receives the processing results output by each processor and merges 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 relationships of the rich text strings when displayed on the interface. After each processor completes its corresponding string processing, the processing results are merged according to the style inheritance relationship, so that the merged string corresponds one-to-one with the logical relationship of the original rich text strings.
[0043] In one embodiment, the step of determining the style inheritance relationship of the rich text based on multiple tags of the rich text includes: constructing a relationship tree based on the multiple tags of the rich text, where 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 step of merging the processing results of each processor based on 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 results.
[0044] In this embodiment, the style inheritance relationship of rich text is represented by constructing a relation tree. Furthermore, when merging the processing results of each processor, the processing results of each processor can be merged sequentially by traversing the relation tree, thereby improving the merging efficiency of the processing results.
[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 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, and the processing results output by processors not corresponding to the first tag and processors not corresponding to the second tag according to the style inheritance relationship. The status tags include one or more of the following: font tags, link tags, bold tags, italic tags, number tags, list tags, and strikethrough tags. The action tags include line break tags.
[0046] Specifically, the strings for status tags correspond to static rich text when displayed on the interface. The strings for action tags correspond to dynamic and interactive rich text when displayed on the interface. Default values for status tags and default actions for action tags are pre-configured. When the processor corresponding to a status tag outputs its processing result, the processing result and the default value are merged to obtain the first merged result. When the processor corresponding to an action tag outputs its processing result, the processing result and the default action are merged to obtain the second merged result. Then, each processing result, as well as the first and second merged results, are processed according to style inheritance relationships.
[0047] Traditional rich text processing methods, where rich text components directly process the rich text strings, cannot personalize the display and can only passively display the strings' prescribed styles. In this embodiment, after each processor processes the corresponding strings in the original rich text, the processing results are merged with manually configured default values or actions before a final merging process. This allows for more personalized processing configurations, ensuring the final displayed rich text meets users' flexible usage needs. In other words, this embodiment decouples the parsing and rendering of rich text strings. The parsed rich text strings are processed by processors, and the output results are merged with other business operations before final rendering. This enables consistent display across multiple platforms through manual operation.
[0048] For example, when displaying character tags as strings in rich text, the default value of the character can be merged with the processing result after the character processor outputs its processing result, thus displaying the default value of the character during final rendering. Similarly, when displaying line break tags as strings in rich text, the default action for line breaks can be merged with the processing result after the line break processor outputs its processing result, thus providing the default action for line breaks during final rendering.
[0049] S214 uses the HarmonyOS rich text component to process the merged string in order to display rich text.
[0050] In this embodiment, the terminal is configured with the HarmonyOS system. The HarmonyOS rich text component only needs to process the merged string to render rich text on the interface. Specifically, the merged string includes color, size, font weight, font, image information, etc. The merged string generates a StyledString (attribute string) for the HarmonyOS rich text component to process, thereby rendering rich text on the interface. Traditional rich text processing involves the rich text component directly processing the rich text string, that is, processing the strings of each tag according to the style inheritance relationship, and finally displaying the processing result on the interface, i.e., displaying rich text. In this embodiment, the HarmonyOS rich text component only needs to process the merged string to display rich text, therefore a more lightweight text component can be used. For example, the Text component can be used to process the merged string to display rich text. The Text component is a lightweight text display component that supports general rich text display and can meet the functional requirements of rich text display in this embodiment.
[0051] The aforementioned rich text display method for HarmonyOS parses the rich text string into array objects based on tags, processes each tag's handler separately, and then merges the processing results. The rich text component only needs to process the merged string to display the rich text, without needing to process the array objects of each tag. This reduces the amount of rich text string processing and the memory resource consumption of the HarmonyOS rich text component, making it more lightweight. Furthermore, since the HarmonyOS rich text component does not need to process individual array objects, it can reduce lag issues.
[0052] Regarding the aforementioned rich text display method for the HarmonyOS system, a specific example is provided below for illustration, combining...< / href> < / src> < / color> < / size> < / height> < / width> Figure 3 The processing flow shown is as follows:
[0053] First, the rich text string is parsed: using string traversal and regular expression replacement, the rich text string is parsed into an array object by node. During the parsing process, style inheritance relationships and link addresses are saved for subsequent StyledString generation.
[0054] Next, the StyledString is generated: the array object parsed in the first step is traversed, and the array object is input into the processors of each tag in the rich text. The processors independently process the corresponding array objects and output the processing results. Different processors only perform tasks related to their own tags, such as adding font color and size. Finally, the processing results of each processor are merged and returned to generate a complete StyledString.
[0055] The image processor's logic is relatively complex. It needs to determine if the image address is of Base64 type. If so, it directly generates an image object using the Base64 string. If not, it needs to check if the current image address is cached on the user's device. If cached, it creates a file manager and reads the locally cached image object based on the image address's hash value. If not cached, it creates an image resource download task, waits for the download task to complete, and then stores the image object in the cache directory based on the image address's hash value for subsequent rendering. See [link to detailed process] for more information. Figure 4 As shown. Therefore, by determining the image address type, it can be compatible with various image formats. By setting image caching, image display can be sped up and the consumption of user network resources can be reduced.
[0056] Finally, StyledString rendering: Based on the Text component provided by the HarmonyOS system, a controller can be bound to this component, and the StyledString can be set and taken effect through the system API after it is generated.
[0057] The above-mentioned rich text display method for the HarmonyOS system can achieve:
[0058] 1. Display consistency: Utilizing highly customizable capabilities, it achieves a display effect consistent with iOS and Android platforms.
[0059] 2. Performance Optimization: Compared with the performance disadvantage of the system component RichText, this solution is based on the lighter-weight Text implementation for rendering, which greatly reduces performance consumption.
[0060] 3. Capability Decoupling: This solution separates the parsing logic and the rendering logic, generating a StyledString that can be used in scenarios other than rendering.
[0061] 4. Image Caching: This solution caches image resources that affect rendering speed, allowing for faster display of effects during the second rendering of rich text. There is no intermediate download process, enhancing the user experience.
[0062] It should be understood that although the steps in the flowchart are shown sequentially as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they 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 completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.
[0063] This application also provides a rich text display device for the HarmonyOS system. For example... Figure 5 As shown, a rich text display device for the HarmonyOS system includes an acquisition module 502, a determination module 504, a parsing module 506, a recognition module 508, an allocation module 510, a merging module 512, and a display processing module 514. The module 502 is used to acquire the rich text string and parse multiple tags from it. The module 504 is used to determine the style inheritance relationship of the rich text based on the multiple tags. The module 506 is used to parse the rich text string into array objects of each tag based on the multiple tags. The module 508 is used to identify the processor corresponding to each tag. The module 510 is used to allocate the array objects of each tag to the processor corresponding to each tag, so that the processor corresponding to each tag processes the array objects of each tag and outputs the processing results. The 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 the merged string. The module 514 is used to process the merged string through the rich text component of the HarmonyOS system to display the rich text.
[0064] In one embodiment, multiple tags include state tags and action tags. The processing results of each processor are merged according to style inheritance relationships, including: obtaining the default value corresponding to a pre-configured first tag and the default action corresponding to a second tag, where 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 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, and the processing results output by processors not corresponding to the first tag and processors not corresponding to the second tag according to style inheritance relationships.
[0065] In one embodiment, status tags include one or more of font tags, link tags, bold tags, italic tags, number tags, list tags, and strikethrough tags, and action tags include line break tags.
[0066] In one embodiment, the multiple tags include image tags. The array objects of each tag are assigned 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. This includes: assigning the array objects of image tags to the processors corresponding to the image tags, the array objects of the image tags containing image information, the processors corresponding to the image tags obtaining rich text images based on the image information, and outputting the obtained images as the processing results.
[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 not 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, retrieving an image based on an image address includes: obtaining the hash value of the image address; comparing the hash value of the image address with the hash value of a pre-stored cache address; if the comparison is successful, retrieving the image from the cache based on the successfully compared cache address; if the comparison fails, creating a network image download task, downloading the image using the network image download task and based on the image address, and caching the downloaded image based on the hash value of the image address.
[0069] In one embodiment, determining the style inheritance relationship of the rich text based on multiple tags of the rich text includes: constructing a relationship tree based on the multiple tags of the rich text, where 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; merging the processing results of each processor based on 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 results.
[0070] For specific limitations regarding a rich text display device based on the HarmonyOS operating system, please refer to the limitations of a rich text display method based on the HarmonyOS operating system described above, which will not be repeated here. Each module in the aforementioned rich text display device based on the HarmonyOS operating system can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in the computer device in hardware form, or stored in the memory of the computer device in software form, so that the processor can call and execute the corresponding operations of each module.
[0071] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 6 As shown, the computer device includes a processor, memory, network interface, display screen, and input devices connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The network interface is used for communication connections via a network. When the computer program is executed by the processor, it implements a rich text display method for the HarmonyOS system. The display screen can be an LCD screen or an e-ink screen. The input devices can be a touch layer covering the display screen, buttons, a trackball, or a touchpad mounted on the computer device casing, or an external keyboard, touchpad, or mouse.
[0072] Those skilled in the art will understand that Figure 6 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device on which the present application is intended to be applied. A specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0073] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it performs the following steps: acquiring a rich text string; parsing multiple rich text tags from the rich text string; determining the style inheritance relationship of the rich text based on the multiple rich text tags; parsing array objects of each tag from the rich text string based on the multiple rich text tags; identifying the processor corresponding to each tag based on each rich text tag; assigning the array objects of each tag to the processor corresponding to each tag, so that the processor corresponding to each tag processes the array objects of each tag and outputs the 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; and processing the merged string through the rich text component of the HarmonyOS system to display the rich text.
[0074] In one embodiment, the multiple tags include status tags and action tags. When the processor executes the computer program to implement the above-described step of merging the processing results of each processor according to the style inheritance relationship, the specific steps are as follows: obtain the default value corresponding to the 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; merge the processing result output by the processor corresponding to the first tag with the corresponding default value to obtain a merged first merged result; merge 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 merge the first merged result, the second merged result, and the processing results output by the processors not corresponding to the first tag and the processors not corresponding to the second tag according to the style inheritance relationship.
[0075] In one embodiment, status tags include one or more of font tags, link tags, bold tags, italic tags, number tags, list tags, and strikethrough tags, and action tags include line break tags.
[0076] In one embodiment, the multiple tags include image tags. When the processor executes a computer program to implement the above-described step of allocating the array objects of each tag to the processor corresponding to each tag, so that the processor corresponding to each tag processes the array objects of each tag and outputs the processing results, the specific steps are as follows: the array objects of image tags are allocated to the processors corresponding to the image tags, the array objects of image tags contain image information, the processors corresponding to the image tags obtain rich text images based on the image information, and output the obtained images as processing results.
[0077] 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 not 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.
[0078] In one embodiment, when the processor executes the computer program to implement the above-described steps of obtaining an image based on an image address, it specifically implements the following steps: obtaining the hash value of the image address, comparing the hash value of the image address with the hash value of a pre-stored cache address; if the comparison is successful, retrieving the image from the cache based on the successfully compared cache address; if the comparison fails, creating a network image download task, downloading the image based on the image address using the network image download task, and caching the downloaded image based on the hash value of the image address.
[0079] In one embodiment, when the processor executes the computer program to implement the above-mentioned step of determining the style inheritance relationship of the rich text based on multiple tags of the rich text, the specific steps are as follows: constructing a relationship tree based on the multiple tags of the rich text, where 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; when the processor executes the computer program to implement the above-mentioned step of merging the processing results of each processor based on the style inheritance relationship, the specific steps are as follows: traversing each node of the relationship tree, and merging the processing results of each processor corresponding to each tag according to the traversal results.
[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, it performs the following steps: obtaining a string of rich text; parsing multiple tags of rich text from the string of rich text; determining the style inheritance relationship of rich text based on the multiple tags of rich text; parsing array objects of each tag from the string of rich text based on the multiple tags of rich text; identifying the processor corresponding to each tag based on each tag of rich text; assigning the array objects of each tag to the processor corresponding to each tag, so that the processor corresponding to each tag processes the array objects of each tag and outputs the 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; and processing the merged string through the rich text component of 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 the processor to implement the above-described step of merging the processing results of each processor according to the style inheritance relationship, the specific steps are as follows: obtaining the default value corresponding to the 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, and the processing results output by the processors not corresponding to the first tag and the processors not corresponding to the second tag according to the style inheritance relationship.
[0082] In one embodiment, status tags include one or more of font tags, link tags, bold tags, italic tags, number tags, list tags, and strikethrough tags, and action tags include line break tags.
[0083] In one embodiment, the multiple tags include image tags. When a computer program is executed by a processor to implement the above-described step of allocating the array objects of each tag to the processor corresponding to each tag so that the processor corresponding to each tag processes the array objects of each tag and outputs the processing results, the specific steps are as follows: the array objects of image tags are allocated to the processor corresponding to the image tags, the array objects of image tags contain image information, the processor corresponding to the image tags obtains the rich text image based on the image information, and outputs the obtained image as the processing result.
[0084] 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 not 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.
[0085] In one embodiment, when the computer program is executed by the processor to implement the above-described steps of obtaining an image based on an image address, the specific steps are as follows: obtaining the hash value of the image address, comparing the hash value of the image address with the hash value of a pre-stored cache address; if the comparison is successful, retrieving the image from the cache based on the successfully compared cache address; if the comparison fails, creating a network image download task, downloading the image based on the image address using the network image download task, and caching the downloaded image based on the hash value of the image address.
[0086] In one embodiment, when the computer program is executed by the processor to implement the above-mentioned step of determining the style inheritance relationship of the rich text based on multiple tags of the rich text, the specific steps are as follows: constructing a relationship tree based on the multiple tags of the rich text, wherein 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; when the computer program is executed by the processor to implement the above-mentioned step of merging the processing results of each processor based on the style inheritance relationship, the specific steps are as follows: traversing each node of the relationship tree, and merging the processing results of each processor corresponding to each tag according to the traversal results.
[0087] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory 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), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), 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 in any way. For the sake of brevity, 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, they should be considered to be within the scope of this specification.
[0089] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims. < / font> < / font>
Claims
1. A rich text display method for the HarmonyOS system, characterized in that, The method includes: Obtain the string of rich text, and parse out multiple tags of the rich text from the string of rich text; A relationship tree is constructed based on multiple tags of the rich text, where 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. Based on the multiple tags of the rich text, an array object of each tag is parsed from the string of the rich text; The processor corresponding to each tag is identified based on the tags of the rich text; Assign the array objects of each tag to the corresponding processor of each tag, so that the processor of each tag can process the array objects of each tag and output the processing results; Receive the processing results output by each processor, traverse each node of the relationship tree, and merge the processing results of each processor corresponding to each tag according to the traversal results to obtain the merged string; The merged string is processed by the rich text component of the HarmonyOS system to display the rich text; The plurality of tags include status tags and action tags. The step of merging the processing results of each processor corresponding to each tag according to the traversal result includes: obtaining the default value corresponding to the first tag and the default action corresponding to the second tag, wherein 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, and the processing results output by processors not corresponding to the first tag and processors not corresponding to the second tag according to the traversal result.
2. The method according to claim 1, characterized in that, The status tags include one or more of the following: font tags, link tags, bold tags, italic tags, number tags, list tags, and strikethrough tags. The action tags include line break tags.
3. The method according to claim 1, characterized in that, The plurality of tags includes image tags. The step of assigning the array objects of each tag to the corresponding processor, so that the processor of each tag processes the array objects of each tag and outputs the processing result, includes: The array object of the image tags is assigned to the processor corresponding to the image tag. The array object of the image tags 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.
4. The method according to claim 3, characterized in that, 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 not Base64 type information, then 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.
5. The method according to claim 4, characterized in that, The step of obtaining the image based on the image address includes: Obtain the hash value of the image address and compare it with the hash value of the pre-stored cache address; If the comparison is successful, the image is retrieved from the cache based on the cache address where the comparison was successful. If the comparison fails, a network image download task is created, and the image is downloaded according to the image address. The downloaded image is then cached based on the hash value of the image address.
6. A rich text display device based on the HarmonyOS system, characterized in that, The device includes: The acquisition module is used to acquire the string of rich text and parse multiple tags of the rich text from the string of rich text; The determination module is used to construct a relationship tree based on multiple tags of the rich text, wherein 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 parsing module is used to parse an array object of each tag from the string of the rich text based on the multiple tags of the rich text; The recognition module is used to identify the processor corresponding to each tag based on the tags of the rich text; The allocation module is used to allocate the array objects of each tag to the corresponding processor of each tag, so that the processor of each tag can process the array objects of each tag and output the processing results. The merging module is used to receive the processing results output by each processor, traverse each node of the relationship tree, and merge the processing results of each processor corresponding to each tag according to the traversal results to obtain the merged string. The display processing module is used to process the merged string through the rich text component of the HarmonyOS system in order to display the rich text; The plurality of tags include status tags and action tags. The step of merging the processing results of each processor corresponding to each tag according to the traversal result includes: obtaining the default value corresponding to the first tag and the default action corresponding to the second tag, wherein 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, and the processing results output by processors not corresponding to the first tag and processors not corresponding to the second tag according to the traversal result.
7. 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, it implements the steps of the method according to any one of claims 1 to 5.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Text analysis method and system, electronic equipment and storage medium
CN118193723A