Print text drawing method and system based on individual character attribute splitting

By splitting text into individual character units and merging them into groups, the problem of high computational overhead and high latency caused by frequent style changes is solved, achieving efficient rendering and fast response, and improving the user experience.

CN120929029AInactive Publication Date: 2025-11-11BEIJING SHUOFANG INFORMATION TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202511453449.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-10-13
Publication Date
2025-11-11
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Existing technologies suffer from high computational overhead and system latency when processing rich text with frequent style changes, which negatively impacts user experience.

Method used

The text string to be drawn is split into multiple independent character units, each character unit carries an independent set of style attributes, consecutive character units are merged into a group, and the output position is calculated according to the preset drawing base point and sequence order. Finally, the character unit group is used as the smallest unit for drawing.

Benefits of technology

It achieves fast response and efficient rendering in rich text with frequently changing styles, alleviating the performance bottleneck of traditional methods and improving user interaction experience and rendering efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120929029A_ABST
    Figure CN120929029A_ABST
Patent Text Reader

Abstract

The invention provides a printed text drawing method and system based on single character attribute splitting, and relates to the field of printing software, the method comprises the following steps: splitting a to-be-drawn target text character string into a plurality of independent character units, each character unit corresponding to a sample attribute set; merging the character units with the same style attribute set and continuous positions in the target text character string to obtain a character unit group; determining an output position of each character unit on the target canvas according to a preset drawing base point and a sequence of each character unit in the target text character string; and according to the output position and the style attribute set of the corresponding character unit, drawing the character unit by taking the character unit group as a minimum unit to obtain a character image corresponding to the target text character string. By implementing the method, not only can quick response be realized, but also efficient rendering performance can be maintained, and the problems of high calculation overhead and high system delay caused by frequent reconstruction of rendering segments in a traditional method are effectively relieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of printing software, and in particular to a method and system for drawing printed text based on single-character attribute decomposition. Background Technology

[0002] With the rapid development of computer technology and digital information technology, electronic document processing, graphical user interfaces (GUIs), and printing systems have become indispensable core components of information interaction in modern society. In these application scenarios, the accurate, efficient, and aesthetically pleasing presentation of text is a crucial fundamental capability. Whether it's complex typesetting software, web browsers, or everyday office suites, one of their core functions relies on accurately converting logical text strings and their associated rich styles (such as font, font size, color, bold, italics, etc.) into visual images on the screen or printed media. High-quality text rendering directly affects user experience and the accuracy of information transmission. Therefore, how to optimize the text rendering process and improve rendering efficiency and flexibility has always been a key focus and research area in computer graphics and software engineering.

[0003] In related technologies, a common strategy for handling rich text strings containing multiple styles is segmentation based on "style continuity." Specifically, the text processing system first traverses the entire text string to be drawn, identifying consecutive character segments with identical style attributes, and defining each such segment as a "rendering segment" or "text run." For example, for the string "Welcome to the new system!", the system parses it into three independent rendering segments: "Welcome" (normal style), "New system" (bold style), and "!" (normal style). During the drawing phase, the rendering engine uses these rendering segments as basic processing units, performing operations sequentially. For each rendering segment, the system uniformly sets the corresponding graphics context, such as selecting the font and setting the color, and then calls the underlying graphics interface to batch calculate the layout and draw all characters within the segment as a whole. This method effectively reduces the number of graphics context switches for long texts with infrequent style changes, demonstrating good processing efficiency in specific scenarios.

[0004] However, with the increasing interactivity of user interfaces and the growing demand for personalized expression, dynamic changes and local fine-tuning of text styles are becoming more frequent. For example, in collaborative editing applications, multiple users may simultaneously make minor style modifications to different parts of the text; or in some advanced typesetting scenarios, it may be necessary to fine-tune the spacing (kerning) of specific individual characters or apply special decorative effects. In these cases, modifying the style of one or a few characters in a long "rendered segment" will force the system to perform a series of complex "split-merge" operations: the original rendered segment data structure needs to be destroyed and split into two or three new rendered segments based on the modification point. This frequent reconstruction of the data structure not only leads to significant computational overhead and dynamic allocation and reclamation of memory, but more importantly, it disrupts the stability of the processing flow. Every minor local change may trigger the rearrangement and rendering of multiple rendered segments, resulting in system response delays. Especially when processing text with highly fragmented styles, performance will drop sharply, causing perceptible lag for the user. Summary of the Invention

[0005] This application provides a method and system for drawing printed text based on single-character attribute splitting, which addresses the problems of high computational overhead and high system latency caused by frequent reconstruction of rendering segments.

[0006] Firstly, this application provides a method for drawing printed text based on single-character attribute decomposition, applied to a text printing processing system, the method comprising: The target text string to be drawn is split into multiple independent character units, each of which corresponds to a style attribute set, which is a set of parameters that define the visual presentation of the character unit; Character units that have the same style attribute set and are consecutive in the target text string are merged to obtain one or more character unit groups; The output position of each character unit on the target canvas is determined based on the preset drawing base point and the sequence order of each character unit in the target text string. The drawing base point is the spatial coordinate of the starting point of the character unit drawing. Based on the output position and the style attribute set of the character unit corresponding to the output position, the character unit is drawn with the character unit group as the smallest unit to obtain the character image corresponding to the target text string.

[0007] Through the above embodiments, the system splits the text string to be drawn into multiple independent character units, each carrying an independent set of style attributes. Character units with the same style and consecutive positions are merged into character unit groups. The output position is calculated according to the order of each independent character unit, ensuring the accuracy of the layout. Finally, during drawing, this method renders using "character unit groups" as the smallest unit. By "splitting into individual characters" to ensure editing flexibility and low overhead, and by "merging into groups" to ensure high rendering efficiency, the technical solution can achieve both fast response and maintain high rendering performance when dealing with rich text with frequently changing styles. This effectively alleviates the problems of high computational overhead and high system latency caused by frequent reconstruction of rendering segments in traditional methods, improving the user experience in interactive applications.

[0008] In some embodiments, the step of determining the output position of each character unit on the target canvas based on a preset drawing base point and the sequence order of each character unit in the target text string specifically includes: The output position of the first character unit in the sequence is determined based on the preset drawing base point, and the output position is the precise spatial coordinate of the character unit drawn on the target canvas; Based on preset character spacing and baseline alignment rules, the horizontal and vertical coordinates of the current character unit to be processed are calculated according to the output position and style attribute set of the previous character unit. The horizontal and vertical coordinates are combined to obtain the output position of the current character unit on the target canvas.

[0009] Through the above embodiments, the system directly determines the position of the first character unit in the target text string sequence by a preset drawing base point. For each subsequent character unit, the calculation of its position strictly depends on the output position and style attributes of its immediate preceding character unit, ensuring that the characters can be arranged coherently and orderly on the canvas according to their logical order in the original string.

[0010] In some embodiments, the step of calculating the horizontal and vertical coordinates of the current character unit to be processed based on the preset character spacing and baseline alignment rules, according to the output position and style attribute set of the previous character unit, specifically includes: The rendering width of the previous character unit is calculated based on the style attribute set. The rendering width is the actual horizontal space occupied by the font and font size corresponding to the character unit on the target canvas. The initial horizontal coordinates of the current character unit are obtained by summing the horizontal component of the output position of the previous character unit, the rendering width, and the preset character spacing. A horizontal adjustment value for adjusting the preset character spacing is generated based on the rendering overlap width between the current character unit and the previous character unit. The rendering overlap width is calculated based on the style attribute set. Add the initial horizontal coordinate to the horizontal adjustment value to obtain the horizontal coordinate of the current character unit; Obtain the font measurement information of the current character unit based on the style attribute set of the current character unit; The baseline offset is calculated based on the preset baseline alignment rules and the font measurement information. The baseline offset is the distance that needs to be moved in the vertical direction to achieve vertical alignment of different character units according to the rules. The vertical component of the preset drawing base point is adjusted according to the baseline offset to obtain the vertical coordinates of the current character unit.

[0011] Through the above embodiments, the system improves typesetting quality by introducing a dynamic fine-tuning mechanism. Horizontally, it automatically adjusts character spacing by calculating the "rendering overlap width" between characters, achieving professional-grade character spacing. Vertically, it calculates the "baseline offset" based on the font measurement information of each character, ensuring precise alignment of characters of different sizes and styles. This results in a more visually balanced and aesthetically pleasing final text layout, leading to a better reading experience.

[0012] In some embodiments, the step of generating a horizontal adjustment value for adjusting the preset character spacing based on the rendering overlap width between the current character unit and the previous character unit specifically includes: Based on the output position and style attribute set of the previous character unit, determine the first bounding box of the previous character unit. The first bounding box is a rectangular area that defines the previous character unit on the target canvas. The second bounding box of the current character unit is determined based on the initial horizontal coordinates, the vertical coordinates, and the style attribute set of the current character unit; By performing geometric intersection detection on the first bounding box and the second bounding box, the rendering overlap width of the two bounding boxes in the horizontal direction is calculated. The rendering overlap width is determined as the horizontal adjustment value.

[0013] Through the above embodiments, the system determines precise rendering bounding boxes for adjacent characters and quantifies their visual overlap by calculating the geometric intersection width of the two bounding boxes in the horizontal direction. This overlap value is directly used as a spacing adjustment value, thereby universally optimizing character spacing and improving the overall visual quality of the text.

[0014] In some embodiments, the step of drawing the character unit with the character unit group as the smallest unit according to the output position and the style attribute set of the character unit corresponding to the output position to obtain the character image corresponding to the target text string specifically includes: The initial character image corresponding to each character unit group is generated by calling the single character rendering function of the preset underlying graphics interface. The initial character image includes the original rendered image of all characters in a single character unit group without post-processing visual effects. The initial character image is post-processed according to preset visual effect parameters to generate an enhanced character image corresponding to each character unit group; The enhanced character images corresponding to all character unit groups are synthesized on the target canvas to obtain the character image corresponding to the target text string.

[0015] Through the above embodiments, the system employs a two-stage rendering pipeline, separating basic character drawing from visual effects processing. First, an "initial character image" containing only raw pixels is generated. Then, post-processing is applied based on parameters to add effects such as shadows and strokes, generating an "enhanced character image." This enhances the system's flexibility and scalability, making it simple and efficient to add or modify complex text visual effects, easily achieving rich artistic font expression.

[0016] In some embodiments, the step of drawing the character unit with the character unit group as the smallest unit according to the output position and the style attribute set of the character unit corresponding to the output position to obtain the character image corresponding to the target text string specifically includes: Generate a corresponding cache key for each character unit group, wherein the cache key is an identifier that can uniquely identify the character unit group; If the character unit group corresponding to the cache key does not exist in the enhanced image cache pool, a new enhanced character image is generated based on the graphical interface and preset visual effect parameters; The newly enhanced character image and the corresponding cache key are stored in the enhanced image cache pool; The final enhanced character image is obtained from the enhanced image cache pool using the cache key corresponding to each character unit group; The final enhanced character images corresponding to all character unit groups are synthesized on the target canvas to obtain the character image corresponding to the target text string.

[0017] Through the above embodiments, the system generates a unique "cache key" for each character group combining content and style. Before rendering, the system checks if the corresponding image exists in the cache; if it does, it is reused directly, avoiding redundant rendering calculations. For documents containing a large number of repetitive styles, this mechanism can greatly reduce redundant calculations, significantly speed up rendering, and make the system response smoother.

[0018] In some embodiments, before the step of determining the output position of each character unit on the target canvas based on a preset drawing base point and the sequence order of each character unit in the target text string, the method further includes: Based on the style attribute set of each character unit group and the preset layout syntax rules, generate the layout anchor point corresponding to each character unit group; A layout dependency graph is constructed using the layout anchor points as nodes and the attachment relationships between anchor points as directed edges. The layout dependency graph is then topologically sorted to generate an anchor point parsing sequence. Based on the anchor point parsing sequence, the spatial coordinates corresponding to each layout anchor point are calculated sequentially to obtain the group drawing base point corresponding to each character unit group.

[0019] Through the above embodiments, the system elevates text layout from linear arrangement to complex two-dimensional layout. By introducing "layout anchor points" and their "attachment relationships" to construct a layout dependency graph, and then generating a conflict-free parsing sequence through topological sorting, the system can solve for the element positions under all complex constraints. This enables the system to support advanced typesetting functions such as text wrapping and multi-column alignment, making it a powerful layout engine.

[0020] Secondly, this application provides a text printing processing system, which includes: one or more processors and a memory; The memory is coupled to the one or more processors. The memory is used to store computer program code, which includes computer instructions. The one or more processors call the computer instructions so that the text printing processing system can implement the print text drawing method based on single-character attribute splitting provided in the above embodiment, which will not be described in detail here.

[0021] Thirdly, this application provides a computer-readable storage medium including instructions that, when executed on a text printing processing system, enable the text printing processing system to implement a text drawing method based on single-character attribute splitting provided in the above embodiments, which will not be elaborated here.

[0022] Fourthly, this application provides a computer program product that, when run on a text printing processing system, enables the text printing processing system to implement a method for drawing printed text based on single-character attribute splitting provided in the above embodiments, which will not be elaborated here.

[0023] One or more technical solutions provided in the embodiments of this application have at least the following technical effects or advantages: 1. By completely breaking down text into independent "character units," the system gains unprecedented editing flexibility, making style modifications to any single character lightweight and efficient. Through an intelligent "merging" step, units with identical and contiguous attributes are recombined into drawing groups. This "divide and then merge" strategy alleviates the performance bottleneck caused by frequent data structure reconstruction in traditional methods when handling fragmented text, balancing the conflict between dynamic response speed and batch rendering efficiency.

[0024] 2. Instead of relying on a fixed character spacing table in the font file, it employs a dynamic adjustment mechanism based on real-time geometric calculations. By creating virtual "boundaries" for the characters to be drawn and calculating their actual overlap width on the canvas, the system can automatically and precisely fine-tune character spacing to achieve a visually perfectly balanced typography effect. This approach, which transforms typographic aesthetics into efficient geometric calculations, is not only highly universal but also produces professional-grade visual quality far exceeding conventional methods.

[0025] 3. It elevates text layout from a simple linear arrangement to a two-dimensional layout system capable of handling complex page-level dependencies. By introducing the concepts of "layout anchors" and "attachment relationships," and utilizing computer science algorithms such as "dependency graphs" and "topological sorting," it can resolve complex spatial constraints such as text wrapping and multi-column alignment. This is equivalent to building a small constraint solver within the rendering engine, making it possible to procedurally generate professional, non-linear, complex layouts, providing applications with powerful desktop publishing-level layout capabilities. Attached Figure Description

[0026] Figure 1 This is a flowchart illustrating a method for drawing printed text based on single-character attribute decomposition in an embodiment of this application; Figure 2 This is another flowchart illustrating a method for drawing printed text based on single-character attribute decomposition in an embodiment of this application; Figure 3 This is a schematic diagram of the physical device structure of a text printing processing system in an embodiment of this application. Detailed Implementation

[0027] The terminology used in the following embodiments of this application is for the purpose of describing particular embodiments only and is not intended to be limiting of this application. As used in the specification and appended claims of this application, the singular expressions “a,” “an,” “the,” “the,” “the,” and “this” are intended to include the plural expressions as well, unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used in this application refers to any or all possible combinations including one or more of the listed items.

[0028] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as implying or suggesting relative importance or implicitly indicating the number of indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature, and in the description of the embodiments of this application, unless otherwise stated, "multiple" means two or more.

[0029] For ease of understanding, the method provided in this implementation is described in process. Please refer to [link / reference]. Figure 1 This is a flowchart illustrating a method for drawing printed text based on single-character attribute splitting in an embodiment of this application.

[0030] S101. Split the target text string to be drawn into multiple independent character units.

[0031] The target text string is the original text content that needs to be drawn, such as an article or a title; the character unit refers to a single character split from the target text string, such as Chinese characters, letters, numbers, punctuation marks, etc.; the style attribute set refers to the combination of parameters used to define the visual effects of the character unit, including font, font size, color, bold, italic, underline, etc.

[0032] This step is performed in the initial stage of drawing the target text. When the text printing system receives the instruction to draw the target text, it first performs this splitting operation. It is suitable for various scenarios requiring personalized text style settings and precise drawing, such as setting different styles for different characters in typesetting software, or handling multiple users modifying text styles in collaborative editing.

[0033] Specifically, the text printing processing system first obtains the target text string to be drawn, and then splits it into multiple individual character units according to the natural separation of characters (such as each character as an independent unit). Each character unit is assigned a corresponding set of style attributes, which details the visual presentation method of the character unit, and each parameter in the set of style attributes has a corresponding set of style attributes to ensure that the style can be accurately restored during subsequent drawing. For example, for the target text string "abC", the split character units are "a", "b", and "C". If the set of style attributes for "a" is "Song typeface, size 12, black".

[0034] Optionally, the system traverses the target text string, identifies each character one by one and extracts it as an independent character unit; creates a default set of style attributes for each extracted character unit, which includes basic parameters such as preset font and font size; checks whether there are style setting instructions for specific characters, and if so, modifies the set of style attributes of the corresponding character unit according to the instructions.

[0035] Optionally, use string processing functions to split the target text string according to character encoding to obtain multiple character units; parse the style attributes of each character from the style description information of the text to generate corresponding sets of style attributes; establish a mapping relationship between the character units and the sets of style attributes to ensure that each character unit has a unique corresponding set of style attributes.

[0036] It can be understood that other methods can also be used to implement the splitting of the target text string and the assignment of the set of style attributes. For example, character splitting can be combined with regular expressions, etc., which are not limited here.

[0037] S102. Merge the character units with the same set of style attributes and consecutive positions in the target text string to obtain one or more groups of character units.

[0038] Specifically, the text printing processing system checks all the character units obtained after splitting, compares the sets of style attributes of each character unit and their positions in the target text string. When it is found that the sets of style attributes of multiple character units are exactly the same and they are arranged consecutively in the string, these character units are merged into a group of character units. For example, if the sets of style attributes of the character units "a" and "b" are both "Regular script, size 14, red" and they appear consecutively in the target text string, they are merged into a group of character units "ab". Through this merging operation, the number of processing units during subsequent drawing can be reduced, and the drawing efficiency can be improved.

[0039] S103. Determine the output position of each character unit on the target canvas based on the preset drawing base point and the sequence order of each character unit in the target text string.

[0040] Among them, the preset drawing base point refers to the pre-set spatial coordinates used to determine the starting position of the character unit drawing, usually with a certain point on the target canvas (such as the upper left corner) as a reference; the sequence order refers to the original order of the character units in the target text string; the output position refers to the specific spatial coordinates on the target canvas where the character unit is drawn, which determines the final display position of the character unit; the target canvas refers to the virtual canvas or the virtual space corresponding to the physical medium (such as paper) used to draw the character image corresponding to the target text string.

[0041] Specifically, the text printing system first obtains a preset drawing base point, which serves as the starting reference for determining the output position of each character unit. Then, based on the sequence order of each character unit in the target text string, starting from the first character unit, and using the preset drawing base point as a foundation, combined with the arrangement rules between character units (such as character spacing, alignment, etc.), the output position of each character unit on the target canvas is calculated sequentially. For example, if the preset drawing base point is (10, 20), the output position of the first character unit is determined based on this, the output position of the second character unit is calculated based on the output position of the first character unit, character spacing, and other factors, and so on, ensuring that all character units are correctly arranged on the canvas according to their sequence order.

[0042] Optional: Use the preset drawing base point directly as the output position of the first character unit in the sequence; for subsequent character units, based on their sequence order relationship with the previous character unit and the preset character spacing, move the corresponding distance horizontally (or vertically, depending on the layout direction) from the output position of the previous character unit to obtain the output position of the current character unit; if there are special cases such as line breaks, adjust the vertical coordinates of the output position according to the preset line break rules to redetermine the output position of the first character unit of the next line.

[0043] Optionally, a coordinate system is established with the preset drawing base point as the origin, the horizontal direction as the X-axis, and the vertical direction as the Y-axis; according to the sequence order of the character units, a relative offset is assigned to each character unit, which is calculated based on the width of the character, the preset character spacing, etc.; the coordinates of the preset drawing base point are added to the relative offset of each character unit to obtain the corresponding output position.

[0044] It is understandable that other methods can be used to determine the output position, such as combining font measurement information (such as ascent, descent, etc.) for more precise calculations, which are not limited here.

[0045] Furthermore, in some more complex implementations, the aforementioned "preset drawing base point" may not be a fixed point, but rather calculated through more complex layout calculations. Specifically, the system generates layout anchor points (reference points marking the layout position of character unit groups) based on the style attribute set (a set of parameters defining the visual presentation of characters, such as font and font size) and preset layout syntax rules (rules that standardize text layout, such as alignment and indentation). Specifically, the anchor point coordinates are calculated by extracting group attributes and combining them with layout rules. Then, a layout dependency graph is constructed with layout anchor points as nodes and the attachment relationships (positional dependencies) between anchor points as directed edges. The graph is then topologically sorted (a reasonable sorting method for dependencies) to generate an anchor point parsing sequence (the order in which anchor points are processed). Specifically, the graph is constructed and sorted to obtain the sequence by analyzing dependencies. Finally, the spatial coordinates (two-dimensional coordinates on the canvas) of each layout anchor point are calculated sequentially according to the anchor point parsing sequence to obtain the group drawing base point of the corresponding character unit group (the starting reference point for drawing characters within the group). Specifically, the coordinates are calculated according to the sequence and converted into preset drawing base points.

[0046] In terms of implementation, generating layout anchor points can be achieved by parsing group attributes to determine the layout category and then calling the corresponding rules for calculation, or by reading the rule file and combining it with the group bounding box for calculation. Dependency graph construction and sorting can be achieved by recording dependencies and using an adjacency list for construction and sorting using the Kahn algorithm, or by specifying relationships through user interaction and then sorting using Depth-First Search (DFS). Coordinate calculation and base point determination can be achieved by assigning initial coordinates to the first anchor point according to the sequence and calculating subsequent coordinates based on the attachment relationships, or by directly using it as the base point, or by creating a coordinate calculation task and combining it with style attributes for precise calculation and then adjusting it as the base point. It is understood that other methods can also be used to implement these steps, and this is not limited here.

[0047] S104. Based on the output position and the style attribute set of the character unit corresponding to the output position, draw the character unit with the character unit group as the smallest unit to obtain the character image corresponding to the target text string.

[0048] Among them, the character image refers to the visual image corresponding to the target text string obtained through drawing operations, which contains the visual presentation of all character units.

[0049] Specifically, the text printing processing system uses the previously merged character unit groups as the smallest processing unit. For each character unit group, it calls the underlying graphics drawing interface to perform drawing operations based on the output positions of each character unit within the group and their corresponding style attribute sets. During the drawing process, each character unit is drawn sequentially on its corresponding output position on the target canvas according to the sequence order of the characters within the character unit group. Finally, after all character unit groups are drawn, the complete character image corresponding to the target text string is obtained. For example, for the character unit group "ab", based on the output positions and style attribute sets of "a" and "b", they are drawn sequentially on the canvas to form the image portion of "ab". Combined with the drawing results of other character unit groups, the character image of the entire target text is obtained.

[0050] Optionally, for each character unit group, obtain the output position and corresponding style attribute set of all character units in the group; call the batch drawing function of the underlying graphics library to draw all character units of the character unit group onto the target canvas at once according to the output position and style attribute set; process all character unit groups in sequence, and after completing the drawing, integrate the images on the target canvas to obtain the character image corresponding to the target text string.

[0051] Optionally, a temporary drawing buffer is created for each character unit group; the character units within the group are drawn in the buffer according to their output positions and style attribute sets, forming the corresponding local image of the group; the local images of all character unit groups are superimposed on the target canvas according to their positions on the target canvas, and merged to form the final character image.

[0052] It is understandable that other methods can be used to draw character units, such as combining hardware acceleration drawing technology to improve drawing efficiency, etc., which are not limited here.

[0053] In addition, the system can generate a cache key for each character unit group. A character unit group is a contiguous combination of character units with the same style. The cache key is a unique identifier for the group, generated by processing character content, style attribute sets, etc., and used for subsequent cache management. It is executed during the initial rendering stage and is suitable for scenarios where images need to be reused to improve efficiency. Specifically, it generates a unique identifier by extracting group information and performing hash operations. If there is no corresponding cache key in the enhanced image cache pool (which stores the enhanced image and cache key), a new enhanced character image is generated based on the graphical interface and preset visual effect parameters (such as shadow and stroke settings). This is executed after cache checking and is suitable for initial processing or uncached cases. Specifically, the initial image is rendered first, and then visual effects are added. The new enhanced image and its cache key are then stored in the cache pool to establish a connection for reuse. This is executed after the new image is generated and stored in key-value pairs. Next, the final enhanced image is retrieved from the cache pool using the cache key of each group, including both cached and newly stored images. This is executed after cache storage and retrieved by querying the cache pool. Finally, all the final enhanced images are composited on the target canvas (the virtual space for drawing text) according to the output position to obtain the character image of the target text string. This is executed after all images are retrieved and is suitable for scenarios where the images are integrated into a complete text image. This is accomplished by drawing in sequence or merging layers.

[0054] In terms of implementation, cache keys can be generated by concatenating character content and style attributes into a string and then performing a hash operation, or by assigning codes to each attribute and combining them into a sequence; generating new enhanced images can be done by calling the graphics interface to draw the initial image first and then applying visual effect parameters, or by completing the drawing and adding effects within a temporary drawing context; storing new images and cache keys can be done by creating entries indexed by cache keys and storing them in compressed form, or by cleaning up space and storing them in a hash table; obtaining the final image can be done by traversing the group and querying the cache pool for verification, or by querying in parallel and handling failure cases; compositing character images can be done by initializing the canvas and drawing them sequentially with anti-aliasing, or by creating a layer stack, adjusting the coordinates, and then merging them. These methods can be selected according to actual needs and are not limited here.

[0055] In the above embodiments, the system splits the text string to be drawn into multiple independent character units, and each character unit carries an independent set of style attributes. The character units with the same style and continuous positions are merged into a character unit group, and the output positions of each independent character unit are calculated according to the order, ensuring the accuracy of the layout. Finally, during drawing, the method renders with the "character unit group" as the smallest unit. By "splitting into single characters", the flexibility of editing and low overhead are ensured, and then by "merging into groups", the high efficiency of rendering is guaranteed. This enables the technical solution to achieve fast response and maintain high rendering performance when processing rich text with frequently changing styles, effectively alleviating the problems of large computational overhead and high system latency caused by frequent reconstruction of rendering segments in traditional methods, and improving the user experience in interactive applications.

[0056] The following provides a further and more specific process description of the method provided in this embodiment. Please refer to Figure 2 , which is another process schematic diagram of a method for drawing printed text based on splitting by single-character attributes in an embodiment of the present application.

[0057] S201. Determine the output position of the first character unit in the sequence order based on a preset drawing base point.

[0058] This step is first executed when the system finishes splitting and merging character units and starts calculating the output positions of each character unit.

[0059] Specifically, the text printing processing system first obtains the preset drawing base point, which contains clear horizontal and vertical coordinate information (such as (x0, y0)). Since the first character unit is at the starting position in the sequence order and there is no previous character unit as a reference, the coordinates of the preset drawing base point are directly determined as the output position of the first character unit. For example, if the preset drawing base point is (100, 200), the output position of the first character unit is (100, 200), and this position will be used as the basic starting point for calculating the output positions of subsequent character units, ensuring that the drawing of the entire text string starts from the correct reference point.

[0060] Optionally, the system reads the coordinate values of the preset drawing base point (such as X = 50, Y = 100) from a configuration file or user settings; identifies the first character unit in the target text string sequence order (such as "我" in "我爱编程"); directly assigns the read coordinate of the preset drawing base point to this first character unit as its output position.

[0061] Optionally, receive the drawing starting point specified by the user through the interaction interface (such as a click operation on the canvas), and determine the coordinates of this point as the preset drawing base point; parse the target text string to determine the first character unit in the sequence order; set the coordinates of the preset drawing base point specified by the user as the output position of the first character unit.

[0062] It can be understood that other methods can also be used to determine the output position of the first character unit. For example, after automatically calculating the preset drawing base point according to the page layout, the position of the first character unit can be determined, etc. This is not limited here.

[0063] S202. Calculate the rendering width of the previous character unit according to the style attribute set.

[0064] Among them, the previous character unit refers to the character unit located before the current character unit in the sequence order.

[0065] Specifically, the text printing processing system first obtains the style attribute set corresponding to the previous character unit, and extracts key parameters such as font type and font size from it. Then, according to these parameters, combined with information such as the resolution of the target canvas, calculate the horizontal width occupied by this character unit when actually rendered on the canvas. For example, if the previous character unit is "b" and its style attribute set is "Song typeface, size 12", the system queries the width data of this font in size 12 (or calculates it in real time through the font rendering engine) and obtains its rendering width of 8 pixels. This width will be an important basis for calculating the initial horizontal coordinate of the current character unit.

[0066] Optionally, the system obtains the style attribute set and character content (such as "中") of the previous character unit; uses the character measurement function of the underlying graphics interface to simulate the rendering of this character to obtain the bounding box information of it on the target canvas; extracts the width value in the horizontal direction from the bounding box information, which is the rendering width of this character unit.

[0067] It can be understood that other methods can also be used to calculate the rendering width of the previous character unit. For example, querying through a pre-generated font width look-up table, etc. This is not limited here.

[0068] S203. Accumulate the horizontal component of the output position of the previous character unit, the rendering width, and the preset character spacing to obtain the initial horizontal coordinate of the current character unit.

[0069] Among them, the horizontal component of the output position of the previous character unit refers to the value representing the horizontal direction in the coordinates of the output position of the previous character unit (such as the X-axis coordinate value); the preset character spacing refers to the horizontal distance set by the system in advance to separate two adjacent character units, which is a fixed value (such as 2 pixels); the current character unit refers to the character unit that is currently being processed and whose output position needs to be calculated; the initial horizontal coordinate refers to the preliminary position coordinates of the current character unit in the horizontal direction before horizontal adjustment (such as considering character overlap).

[0070] Specifically, the text printing processing system first obtains the horizontal component of the output position of the previous character unit (for example, if the output position of the previous character unit is (x1, y1), then the horizontal component is x1). Then, this horizontal component is added to the rendering width (w) of the previous character unit and the preset character spacing (s), i.e., xinitial = x1 + w + s. The result is the initial horizontal coordinate of the current character unit. For example, if the horizontal component of the output position of the previous character unit is 100, the rendering width is 8, and the preset character spacing is 2, then the initial horizontal coordinate of the current character unit is 100 + 8 + 2 = 110. This coordinate initially determines the position of the current character unit relative to the previous character unit in the horizontal direction.

[0071] S204. Generate a horizontal adjustment value for adjusting the preset character spacing based on the rendering overlap width between the current character unit and the previous character unit.

[0072] Specifically, the text printing processing system first determines the rendering boundaries (such as bounding boxes) of the current and previous character units based on their style attribute sets. Then, it calculates the width of the horizontal overlap between the two bounding boxes using geometric intersection detection; this width is the rendering overlap width. Since the initial horizontal coordinates are calculated based on a preset character spacing, if overlap exists, it means the preset spacing is insufficient to avoid it. Therefore, the rendering overlap width is used as a horizontal adjustment value to increase the horizontal coordinates of the current character unit, thereby eliminating the overlap. For example, if the rendering overlap width between the current and previous character units is 2 pixels, the horizontal adjustment value is 2 pixels, used to subsequently correct the initial horizontal coordinates.

[0073] Optionally, based on the output position and style attribute set of the previous character unit, calculate its first bounding box on the target canvas (including the horizontal coordinates of the top left and bottom right corners); based on the initial horizontal coordinates, vertical coordinates, and style attribute set of the current character unit, calculate its second bounding box; compare the horizontal coordinate ranges of the two bounding boxes, calculate the width of the overlapping part, and determine this width as the horizontal adjustment value.

[0074] Optionally, the font rendering interface is called to obtain the horizontal outline data of the previous character unit and the current character unit under the corresponding style; the two character units are simulated to be arranged in the initial position, and the horizontal overlap length is calculated by the outline intersection algorithm; the overlap length is used as the horizontal adjustment value.

[0075] S205. Add the initial horizontal coordinate to the horizontal adjustment value to obtain the horizontal coordinate of the current character unit.

[0076] Specifically, the text printing system adds the initial horizontal coordinates obtained in step S203 to the horizontal adjustment value generated in step S204. The result is the horizontal coordinate of the current character unit on the target canvas. For example, if the initial horizontal coordinate is 110 pixels and the horizontal adjustment value is 2 pixels, then the horizontal coordinate of the current character unit is 110 + 2 = 112 pixels. This coordinate eliminates potential overlap between characters and ensures a reasonable horizontal spacing between the current character unit and the previous character unit.

[0077] S206. Calculate the baseline offset based on the preset baseline alignment rules and the font measurement information of the current character unit.

[0078] Among them, the preset baseline alignment rule refers to the rule set by the system in advance to standardize the alignment of different character units in the vertical direction, usually with the baseline (the baseline at the bottom of the character) as the alignment reference; the font measurement information of the current character unit refers to the data describing the vertical characteristics of the font corresponding to the character unit, including the baseline position, ascent (distance from the baseline to the top of the character), descent (distance from the baseline to the bottom of the character), etc.; the baseline offset refers to the distance that the current character unit needs to move relative to the preset drawing base point in order to achieve vertical alignment of different character units according to the rules.

[0079] Specifically, the text printing processing system first obtains the preset baseline alignment rules (such as all characters being aligned to the baseline), and then extracts font measurement information from the style attribute set of the current character unit, focusing on the position of the baseline relative to the top or bottom of the character. According to the alignment rules, it calculates the offset distance between the baseline of the current character unit and the baseline corresponding to the vertical component of the preset drawing base point; this distance is the baseline offset. For example, if the vertical component of the preset drawing base point corresponds to the baseline position of a 12-point font, and the current character unit is a 14-point font, its baseline is 1 pixel lower than the baseline of the 12-point font; then the baseline offset is 1 pixel, used to adjust the vertical position of the current character unit to ensure baseline alignment.

[0080] Optionally, the system obtains the font file path from the style attribute set of the current character unit, parses the font file to obtain font measurement information (such as baseline position and ascent value); reads the reference baseline position specified in the preset baseline alignment rules (such as the baseline based on the first character unit); calculates the vertical difference between the baseline of the current character unit and the reference baseline, and determines the difference as the baseline offset.

[0081] S207. Calculate the vertical coordinates of the current character unit based on the baseline offset and the vertical component of the preset drawing base point.

[0082] Specifically, the text printing processing system uses the vertical component of a preset drawing base point as a reference, combined with the baseline offset, to obtain the final vertical coordinates of the current character unit on the target canvas through addition (or subtraction, depending on the coordinate system and offset definition). For example, if the vertical component of the preset drawing base point is 200 pixels and the baseline offset is 1 pixel (meaning the current character unit's baseline needs to be 1 pixel lower than the reference baseline), then the vertical coordinate of the current character unit is 200 + 1 = 201 pixels. This coordinate ensures that the current character unit remains consistent with other character units in the vertical direction according to the baseline alignment rules.

[0083] S208. Combine the horizontal and vertical coordinates to obtain the output position of the current character unit on the target canvas.

[0084] Specifically, the text printing processing system combines the horizontal coordinates obtained in step S205 and the vertical coordinates obtained in step S207 to form a two-dimensional coordinate point, which is the output position of the current character unit on the target canvas. For example, if the horizontal coordinate is 112 pixels and the vertical coordinate is 201 pixels, then the output position is (112, 201). This position precisely defines the starting point for drawing the current character unit on the canvas, ensuring that the character can be rendered according to the expected layout.

[0085] S209. Generate the initial character image corresponding to each character unit group by calling the character rendering function of the preset underlying graphics interface.

[0086] Among them, the preset low-level graphics interface refers to the low-level program interface (such as OpenGL, DirectX, etc.) that is pre-configured by the system to implement graphics drawing functions, providing basic graphics rendering capabilities for upper-level applications; the character rendering function refers to the function in the preset low-level graphics interface that can render characters individually or in batches, and can generate corresponding character images based on character content and style attribute sets.

[0087] Specifically, the text printing system first iterates through all character unit groups. For each character unit group, it obtains the content of all character units within the group, the corresponding style attribute set (such as font, font size, color, etc.), and the output position. Then, it calls the character rendering function in the preset underlying graphics interface to render the character units in the group into image elements in batches according to the style attribute set and output position corresponding to each character unit group, thus obtaining the initial character image corresponding to each character unit group.

[0088] S210. Based on the preset visual effect parameters, perform post-processing on the initial character image to generate the corresponding enhanced character image for each character unit group.

[0089] Among them, the preset visual effect parameters refer to the set of parameters that the system pre-sets for beautifying the initial character image, including shadow parameters (such as shadow color, blur radius, offset), stroke parameters (such as stroke color, width), transparency, gradient effects, etc.

[0090] Specifically, the text printing processing system first obtains preset visual effect parameters, and then performs post-processing on the initial character image of each character unit group according to the requirements of the visual effect parameters. For example, if the visual effect parameters include "shadow color is gray, blur radius is 2 pixels, offset is (1,1)", the system will add a shadow effect that matches the parameters to the initial character image; if it includes "stroke color is red, width is 1 pixel", a red stroke will be added to the character edges. After these processes, the initial character image is transformed into an enhanced character image containing preset visual effects. For example, the initial image of the character unit group "ab" is black Song typeface "ab", and after post-processing, an enhanced character image "ab" with gray shadow and red stroke is generated.

[0091] S211. Combine the enhanced character images corresponding to all character unit groups on the target canvas to obtain the character image corresponding to the target text string.

[0092] Specifically, the text printing processing system first determines the size and attributes of the target canvas (such as resolution and background color). Then, according to the output positions of the character units in each character unit group, it sequentially draws the corresponding enhanced character images onto the corresponding positions on the target canvas. During the drawing process, the system ensures that the positional relationship between each enhanced character image is consistent with the sequence order of the character units in the target text string, avoiding image overlap or misalignment. For example, the enhanced image for the character unit group "ab" corresponds to output positions (10, 20) to (20, 30), and the enhanced image for the character unit group "cd" corresponds to output positions (22, 20) to (32, 30). The system draws both onto the target canvas according to these positions, ultimately combining them into a complete character image of "abcd".

[0093] The text printing processing system of this invention is applied to electronic devices. Figure 3 A schematic diagram of the architecture of an electronic device suitable for implementing embodiments of the present invention is shown.

[0094] It should be noted that, Figure 3 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of use of the embodiments of the present invention.

[0095] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by instructions (computer programs), or by instructions (computer programs) controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor. The electronic device of this embodiment includes a storage medium and a processor, wherein the storage medium stores multiple instructions that can be loaded by the processor to execute any step of the method provided in the embodiments of the present invention.

[0096] Specifically, the storage medium and the processor are electrically connected directly or indirectly to enable data transmission or interaction. For example, these components can be electrically connected to each other via one or more signal lines. The storage medium stores computer-executable instructions that implement data access control methods, including at least one software functional module that can be stored in the storage medium in the form of software or firmware. The processor executes various functional applications and data processing by running the software program and module stored in the storage medium. The storage medium can be, but is not limited to, Random Access Memory (RAM), Read-Only Memory (ROM), Programmable Read-Only Memory (PROM), Erasable Programmable Read-Only Memory (EPROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), etc. The storage medium stores the program, and the processor executes the program after receiving the execution instructions.

[0097] Furthermore, the software programs and modules within the aforementioned storage medium may also include an operating system, which may include various software components and / or drivers for managing system tasks (e.g., memory management, storage device control, power management, etc.) and can communicate with various hardware or software components to provide an operating environment for other software components. The processor may be an integrated circuit chip with signal processing capabilities. The aforementioned processor may be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc., which can implement or execute the methods, steps, and logic flowcharts disclosed in this embodiment. The general-purpose processor may be a microprocessor or any conventional processor.

[0098] Since the instructions stored in the storage medium can execute the steps in any of the methods provided in the embodiments of the present invention, the beneficial effects of any of the methods provided in the embodiments of the present invention can be achieved, as detailed in the preceding embodiments, and will not be repeated here.

[0099] The above description is merely a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A method for drawing printable text based on single-character attribute decomposition, applied to a text printing processing system, characterized in that, The method includes: The target text string to be drawn is split into multiple independent character units, each of which corresponds to a style attribute set, which is a set of parameters that define the visual presentation of the character unit; Character units that have the same style attribute set and are consecutive in the target text string are merged to obtain one or more character unit groups; The output position of each character unit on the target canvas is determined based on the preset drawing base point and the sequence order of each character unit in the target text string. The drawing base point is the spatial coordinate of the starting point of the character unit drawing. Based on the output position and the style attribute set of the character unit corresponding to the output position, the character unit is drawn with the character unit group as the smallest unit to obtain the character image corresponding to the target text string.

2. The method according to claim 1, characterized in that, The step of determining the output position of each character unit on the target canvas based on a preset drawing base point and the sequence order of each character unit in the target text string specifically includes: The output position of the first character unit in the sequence is determined based on the preset drawing base point, and the output position is the precise spatial coordinate of the character unit on the target canvas; Based on preset character spacing and baseline alignment rules, the horizontal and vertical coordinates of the current character unit to be processed are calculated according to the output position and style attribute set of the previous character unit. The horizontal and vertical coordinates are combined to obtain the output position of the current character unit on the target canvas.

3. The method according to claim 2, characterized in that, The step of calculating the horizontal and vertical coordinates of the current character unit to be processed based on the preset character spacing and baseline alignment rules, according to the output position and style attribute set of the previous character unit, specifically includes: The rendering width of the previous character unit is calculated based on the style attribute set. The rendering width is the actual horizontal space occupied by the font and font size corresponding to the character unit on the target canvas. The initial horizontal coordinates of the current character unit are obtained by summing the horizontal component of the output position of the previous character unit, the rendering width, and the preset character spacing. A horizontal adjustment value for adjusting the preset character spacing is generated based on the rendering overlap width between the current character unit and the previous character unit. The rendering overlap width is calculated based on the style attribute set. Add the initial horizontal coordinate to the horizontal adjustment value to obtain the horizontal coordinate of the current character unit; Obtain the font measurement information of the current character unit based on the style attribute set of the current character unit; The baseline offset is calculated based on the preset baseline alignment rules and the font measurement information. The baseline offset is the distance that needs to be moved in the vertical direction to achieve vertical alignment of different character units according to the rules. The vertical coordinates of the current character unit are calculated based on the baseline offset and the vertical component of the preset drawing base point.

4. The method according to claim 3, characterized in that, The step of generating a horizontal adjustment value for adjusting the preset character spacing based on the rendering overlap width between the current character unit and the previous character unit specifically includes: Based on the output position and style attribute set of the previous character unit, determine the first bounding box of the previous character unit. The first bounding box is a rectangular area that defines the previous character unit on the target canvas. The second bounding box of the current character unit is determined based on the initial horizontal coordinates, the vertical coordinates, and the style attribute set of the current character unit; By performing geometric intersection detection on the first bounding box and the second bounding box, the rendering overlap width of the two bounding boxes in the horizontal direction is calculated. The rendering overlap width is determined as the horizontal adjustment value.

5. The method according to claim 1, characterized in that, The step of drawing the character unit with the character unit group as the smallest unit based on the output position and the style attribute set of the character unit corresponding to the output position to obtain the character image corresponding to the target text string specifically includes: The initial character image corresponding to each character unit group is generated by calling the character rendering function of the preset underlying graphics interface. The initial character image includes the original rendered image of all characters in a single character unit group without post-processing visual effects. All character units in the same character unit group are drawn as a rendering batch. The initial character image is post-processed according to preset visual effect parameters to generate an enhanced character image corresponding to each character unit group; The enhanced character images corresponding to all character unit groups are synthesized on the target canvas to obtain the character image corresponding to the target text string.

6. The method according to claim 5, characterized in that, The step of drawing the character unit with the character unit group as the smallest unit based on the output position and the style attribute set of the character unit corresponding to the output position to obtain the character image corresponding to the target text string specifically includes: Generate a corresponding cache key for each character unit group, wherein the cache key is an identifier that can uniquely identify the character unit group; If the character unit group corresponding to the cache key does not exist in the enhanced image cache pool, a new enhanced character image is generated based on the graphical interface and preset visual effect parameters; The newly enhanced character image and the corresponding cache key are stored in the enhanced image cache pool; The final enhanced character image is obtained from the enhanced image cache pool using the cache key corresponding to each character unit group; The final enhanced character images corresponding to all character unit groups are synthesized on the target canvas to obtain the character image corresponding to the target text string.

7. The method according to claim 1, characterized in that, Before the step of determining the output position of each character unit on the target canvas based on a preset drawing base point and the sequence order of each character unit in the target text string, the method further includes: Based on the style attribute set of each character unit group and the preset layout syntax rules, generate the layout anchor point corresponding to each character unit group; A layout dependency graph is constructed using the layout anchor points as nodes and the attachment relationships between anchor points as directed edges. The layout dependency graph is then topologically sorted to generate an anchor point parsing sequence. Based on the anchor point parsing sequence, the spatial coordinates corresponding to each layout anchor point are calculated sequentially to obtain the group drawing base point corresponding to each character unit group.

8. A text printing processing system, characterized in that, The text printing processing system includes: one or more processors and memory; The memory is coupled to the one or more processors, the memory being used to store computer program code, the computer program code including computer instructions, the one or more processors invoking the computer instructions to cause the text printing processing system to perform the method as described in any one of claims 1-7.

9. A computer-readable storage medium comprising instructions, characterized in that, When the instructions are executed on the text printing processing system, the text printing processing system performs the method as described in any one of claims 1-7.

10. A computer program product, characterized in that, When the computer program product is run on a text printing processing system, the text printing processing system performs the method as described in any one of claims 1-7.

Citation Information

Patent Citations

  • Method and system for drawing WordArt effect

    CN105957136A

  • Text processing method and device, equipment and medium

    CN113033147A

  • Character processing method and device

    CN113705156A

  • Word art rendering method and device and medium

    CN116932955A

  • Arbitrary size content item generation

    US20150227504A1