Text drawing method and device, storage medium and program product

By pre-calculating the layout information of the static text to be rendered, and using text texture caching mechanism and font subsetting, the problem of low text drawing performance and rendering efficiency in the existing technology is solved, and more efficient text drawing and improvement are achieved Good user experience.

CN119398011AInactive Publication Date: 2025-02-07HANGZHOU DIANZI UNIV +1

Patent Information

Application Number
CN202510006188.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-03
Publication Date
2025-02-07
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Existing graphics galleries have challenges in complex text layouts, performance optimization, and rendering effects, such as performance bottlenecks, inconsistent rendering quality, and difficulty in handling complex text layouts.

Method used

By pre-calculating the layout information of the static text to be rendered, and using text texture caching mechanism and font subsetting to reduce the loading time of font rendering, improving the performance and efficiency of text drawing.

Benefits of technology

It effectively improves the performance and efficiency of text drawing, reduces the computational burden of text rendering, and improves the response speed and user experience of text drawing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119398011A_ABST
    Figure CN119398011A_ABST
Patent Text Reader

Abstract

The invention discloses a text drawing method and device, a storage medium and a program product. The method comprises the steps of obtaining canvas parameters, text parameters and position parameters of a to-be-rendered text; determining layout parameters of the to-be-rendered text according to the canvas parameters, the text parameters and the position parameters; acquiring style parameters corresponding to the text parameters from a text texture cache library and / or a preset font subset library; and according to the layout parameter and the style parameter, performing rendering processing on the to-be-rendered text to obtain a target text. According to the technical scheme, the layout information of the static to-be-rendered text is pre-calculated, and the loading duration of font rendering is reduced through a text texture caching mechanism and font subset, so that the performance and efficiency of text drawing are effectively improved, the calculation burden of text rendering is reduced, and the response speed of text drawing and the user experience are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a text drawing method, device, storage medium and program product. Background Art

[0002] A graphics drawing library is a software library used to create, manipulate, and render graphics, text, or images in computer programs to help developers implement graphics-related functions more efficiently.

[0003] In related technologies, although the graphics drawing library provides text drawing functions, there are still certain challenges in complex text layout, performance optimization and rendering effects. For example, problems may be encountered when rendering text, such as performance bottlenecks, inconsistent rendering quality, and difficulty in handling complex text layouts. In addition, the text drawing optimization method is relatively simple and usually relies on traditional drawing strategies, which cannot fully utilize the advantages of modern hardware and graphics engines.

[0004] Therefore, how to provide a technical solution that can improve the text rendering performance and rendering efficiency in a graphics drawing library is a technical problem that needs to be solved urgently by those skilled in the art. Summary of the invention

[0005] The present application provides a text drawing method, device, storage medium and program product, which effectively improves the performance and efficiency of text drawing, reduces the computational burden of text rendering, and improves the response speed and user experience of text drawing by pre-calculating the layout information of static text to be rendered and reducing the loading time of font rendering through a text texture caching mechanism and font subsetting.

[0006] According to one aspect of the present application, a text drawing method is provided, the method comprising: obtaining canvas parameters, text parameters and position parameters of a text to be rendered; determining layout parameters of the text to be rendered according to the canvas parameters, the text parameters and the position parameters; obtaining style parameters corresponding to the text parameters from a text texture cache library and / or a pre-set font subset library; wherein the text texture cache library is a texture cache set generated for historically rendered text based on a preset cache data structure, the preset cache data structure comprising a text identifier, a texture image and a linked list node; rendering the text to be rendered according to the layout parameters and the style parameters to obtain a target text.

[0007] According to another aspect of the present application, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the text drawing method described in any embodiment of the present application.

[0008] According to another aspect of the present application, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the text drawing method described in any embodiment of the present application when executed.

[0009] According to another aspect of the present application, a computer program product is provided. The computer program product includes a computer program. When the computer program is executed by a processor, the text drawing method described in any embodiment of the present application is implemented.

[0010] The technical solution provided by the present application obtains the canvas parameters, text parameters and position parameters of the text to be rendered; determines the layout parameters of the text to be rendered according to the canvas parameters, text parameters and position parameters; obtains the style parameters corresponding to the text parameters from the text texture cache library and / or the pre-set font subset library; renders the text to be rendered according to the layout parameters and style parameters to obtain the target text. The present technical solution effectively improves the performance and efficiency of text drawing, reduces the computational burden of text rendering, and improves the response speed and user experience of text drawing by pre-calculating the layout information of the static text to be rendered and reducing the loading time of font rendering through the text texture cache mechanism and font subsetting.

[0011] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present application, nor is it intended to limit the scope of the present application. Other features of the present application will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0013] Figure 1 A flowchart of a text drawing method provided in Example 1 of the present application.

[0014] Figure 2 A flowchart of a text drawing method provided in Example 2 of the present application.

[0015] Figure 3 This is a flowchart of a text drawing method provided in Example 3 of the present application.

[0016] Figure 4 It is a structural schematic diagram of a device for implementing a text drawing method in an embodiment of the present application. DETAILED DESCRIPTION

[0017] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.

[0018] It should be noted that the terms "to be rendered", "partially to be rendered", "target", "first", "second", "maximum", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0019] Embodiment 1

[0020] Figure 1 This is a flowchart of a text drawing method provided in the first embodiment of the present application. This embodiment is applicable to the case of drawing text in a graphic drawing library. The method can be executed by a text drawing device. The text drawing device can be implemented in the form of hardware and / or software. The text drawing device can be configured in a device with data processing capabilities. Figure 1 As shown, the method includes the following steps.

[0021] S110 , obtaining canvas parameters, text parameters, and position parameters of the text to be rendered.

[0022] The canvas parameters may be the characteristics and settings related to the canvas on which the text to be rendered is drawn, and determine the spatial range and overall visual environment in which the text to be rendered is presented. The canvas parameters may generally include the width, height, background color, etc. of the canvas. For example, a canvas may have a width of 800 pixels, a height of 600 pixels, and a white background.

[0023] Among them, the text parameters can be the attributes of the text to be rendered, which determine the appearance style of the text, such as the text content, font type, font size, font color, whether it is bold, whether it is italic, etc.

[0024] The position parameter is used to determine the specific position or relative position of the text to be rendered on the canvas, which determines the layout of the text to be rendered on the canvas. It can be expressed by coordinates, usually with horizontal and vertical coordinates. For example, the starting position of the text to be rendered on the canvas is 100 pixels on the horizontal coordinate and 50 pixels on the vertical coordinate.

[0025] Specifically, the canvas parameters, text parameters and position parameters of the text to be rendered may be obtained through the instructions input by the user.

[0026] S120: Determine layout parameters of the text to be rendered according to the canvas parameters, the text parameters, and the position parameters.

[0027] The layout parameters may include the position coordinates, font size, color, alignment, etc. of the text to be rendered. In the present application, the layout information of the static text to be rendered is pre-calculated to accelerate the subsequent text rendering process.

[0028] Specifically, the space that can be occupied by the text to be rendered can be determined according to the size of the canvas, the space that each character in the text to be rendered needs to be determined according to the text parameters, the specific position or relative position of the text to be rendered on the canvas can be determined according to the position parameters, and then the layout position of each character in the text to be rendered on the canvas can be determined according to the space that can be occupied by the text to be rendered, the space that each character in the text to be rendered needs to be occupied, and the specific position or relative position of the text to be rendered on the canvas.

[0029] For example, the layout parameters of the text to be rendered may be horizontally centered and vertically topped, with 5 characters per line and 3 lines in total.

[0030] S130: Acquire style parameters corresponding to the text parameters from a text texture cache library and / or a preset font subset library.

[0031] The text texture cache library is a texture cache set generated for historically rendered text based on a preset cache data structure, and the preset cache data structure includes a text identifier, a texture image, and a linked list node.

[0032] Specifically, when the historical rendering text is first drawn, the size of the text can be measured first through SKPaint.MeasureText; create an SKBitmap that matches the text size, and use SKCanvas to draw the text onto the bitmap; finally, convert the SKBitmap to an SKImage and store it in the text texture cache library; when the same text is drawn subsequently, the texture can be directly obtained from the text texture cache library and drawn without having to re-render the text.

[0033] For example, if the historical rendering text is "Hello" with the style of Song typeface, size 4, and bold, then the textures of "你" and "好" on a transparent canvas can be created separately and stored in the text texture cache library. When "你" or "好" with the same style is drawn subsequently, it can be directly called.

[0034] Among them, when caching the texture in the text texture cache library, the preset cache data structure Dictionary<string, (SKImage, LinkedListNode <string>)> for caching. Where string represents a string identifier, SKImage represents a texture, and LinkedListNode <string>Represents a linked list node.

[0035] The text texture cache library can dynamically adjust the cache clearing and updating strategy according to the screen resolution and the complexity of text drawing to balance memory usage and rendering performance. For example, the text texture cache can be dynamically adjusted by limiting the maximum capacity of the cache. Once the cache reaches this capacity, the infrequently used cache items are cleared through the LRU algorithm. For another example, an expiration time is set for each cache item, and cache items that have not been accessed for a certain period of time are regularly cleared. For another example, when the memory usage approaches a certain threshold, some caches are actively cleared. For another example, different priorities are assigned to different contents in the cache to ensure that more commonly used or more important texts are cached first. For another example, an expiration time is set for the cache item, and cache items that have not been accessed for a certain period of time will be automatically removed. The expired items can be checked in conjunction with a timer or every time the cache is accessed. For another example, the cache capacity can be dynamically adjusted according to the actual memory usage of the application. When the memory is tight, the cache capacity is automatically reduced to release resources. For another example, when the memory usage approaches the threshold, the infrequently used cache is actively cleared.

[0036] When removing a cache item, you can release the image resource by calling SKImage.Dispose() to avoid memory leaks.

[0037] The font subset library can be a pre-set font collection, including some commonly used font styles or fonts customized according to specific needs. During the rendering process, only the font subsets actually needed are loaded and used to reduce the size of the font file and the loading time.

[0038] Optionally, the process of setting the font subset library includes: obtaining at least one target font file; performing subset processing on each of the target font files respectively to obtain a target font subset corresponding to the target font file, and integrating each of the target font subsets into the font subset library.

[0039] Specifically, you can determine in advance the fonts you need to use and obtain their complete font files, usually files in TrueType format or OpenType format; then use third-party tools to subset the font files, such as FontTools, pyftsubset, or Google Fonts Subsetter; finally, integrate the generated target font subsets into the font subset library, and configure and load them when the corresponding fonts are needed.

[0040] In the present application, style parameters corresponding to text parameters can be obtained only from the text texture cache library; style parameters corresponding to text parameters can be obtained only from a pre-set font subset library; style parameters corresponding to text parameters can be obtained first from the text texture cache library, and then from a pre-set font subset library; style parameters corresponding to text parameters can be obtained first from a pre-set font subset library, and then from the text texture cache library.

[0041] Optionally, style parameters corresponding to the text parameters are obtained from a text texture cache library and / or a pre-set font subset library, including: determining whether there is a texture cache corresponding to the text to be rendered in the text texture cache library according to the text parameters; if there is no texture cache corresponding to the text to be rendered, obtaining style parameters corresponding to the text parameters from a pre-set font subset library; or, if there is a texture cache corresponding to the text to be rendered, obtaining style parameters corresponding to the text to be rendered from the text texture cache library, and adjusting the linked list node of the texture cache corresponding to the text to be rendered to the head of the linked list of the text texture cache library; or, if there is a texture cache corresponding to part of the text to be rendered, obtaining style parameters corresponding to the part of the text to be rendered from the text texture cache library, adjusting the linked list node of the texture cache corresponding to the part of the text to be rendered to the head of the linked list of the text texture cache library, and obtaining style parameters corresponding to the remaining text to be rendered from the pre-set font subset library.

[0042] When obtaining the style parameters corresponding to the text to be rendered from the text texture cache library, you can use LinkedList <string>Record the order in which the text is accessed. The newly accessed text will be placed at the head of the linked list, and the text that has not been used for the longest time will be at the tail of the linked list. Specifically, first check whether there is a texture corresponding to the text to be rendered in the text texture cache. If there is, move it to the head of the linked list to indicate that it is recently used. If not, create a new texture and add it to the cache.

[0043] In the present application, repeated rendering of text of the same style is avoided by giving priority to querying and obtaining style parameters corresponding to the text to be rendered from the text texture cache library; then, consideration is given to obtaining style parameters corresponding to the text to be rendered from the pre-set font subset library, and only the actually required font subset is loaded, thereby reducing the loading time of the font file.

[0044] S140: Render the text to be rendered according to the layout parameters and the style parameters to obtain a target text.

[0045] Specifically, a graphics library or a rendering engine may be used to draw the text after layout adjustment and style application onto a canvas.

[0046] In order to make the rendered text look smoother and clearer, the rendering process can use an improved anti-aliasing algorithm, which can be adaptively adjusted according to the font and display resolution to reduce the amount of calculation during rendering and improve the display effect. You can also enable sub-pixel rendering by setting the SKPaint.SubpixelText property to true to improve the smoothness of the font at the edges.

[0047] The embodiment of the present invention provides a text drawing method, which obtains canvas parameters, text parameters and position parameters of the text to be rendered; determines the layout parameters of the text to be rendered according to the canvas parameters, text parameters and position parameters; obtains style parameters corresponding to the text parameters from a text texture cache library and / or a pre-set font subset library; and renders the text to be rendered according to the layout parameters and style parameters to obtain the target text. This technical solution effectively improves the performance and efficiency of text drawing, reduces the computational burden of text rendering, and improves the response speed and user experience of text drawing by pre-calculating the layout information of the static text to be rendered and reducing the loading time of font rendering through a text texture cache mechanism and font subsetting.

[0048] Embodiment 2

[0049] Figure 2 This is a flowchart of a text drawing method provided in the second embodiment of the present application. This embodiment is optimized based on the above embodiment, specifically, the process of determining the layout parameters is refined. Figure 2 As shown, the method of this embodiment specifically includes the following steps.

[0050] S210: Obtain canvas parameters, text parameters, and position parameters of the text to be rendered.

[0051] S220: Determine a first size parameter of the text area according to the canvas parameter.

[0052] The text area may be a text drawing area specified in the canvas.

[0053] For example, the text area can be the entire area of ​​the canvas or a partial area of ​​the canvas. If the text area is the entire area of ​​the canvas, the first size parameter of the text area can be determined by obtaining the size parameter of the canvas; if the text area is a partial area of ​​the canvas, the first size parameter of the text area can be determined by the relative position relationship and proportion relationship between the text area and the canvas area.

[0054] S230: Determine a second size parameter of the text to be rendered according to the text parameter.

[0055] The second size parameter is determined based on when the text to be rendered is displayed in a non-line-breaking form, that is, the size parameter is determined when the text to be rendered is displayed in the form of a line.

[0056] Specifically, the font style information can be written into SKPaint, and the function SkiaSharp.SKPaint.MeasureText can be used to calculate the second size parameter of the text to be rendered, such as width and height.

[0057] For example, a text to be rendered is "Welcome" in boldface size 3, with a height of 5.64 mm and a width of 24 mm.

[0058] S240: Determine an alignment of the text to be rendered according to the position parameter.

[0059] The alignment is the arrangement of the text to be rendered in the text area. For example, the horizontal alignment can be determined based on the abscissa axis, including left alignment, right alignment, and center alignment; the vertical alignment can be determined based on the ordinate axis, including top alignment, bottom alignment, and center alignment.

[0060] In the present application, the horizontal alignment and the vertical alignment of the text to be rendered in the text area may be determined separately.

[0061] S250: Determine layout parameters of the text to be rendered according to the first size parameter, the second size parameter, and the alignment.

[0062] Specifically, the maximum range in which the text to be rendered can be laid out can be determined according to the first size parameter; the second size parameter is used to calculate the actual space occupied by the text to be rendered under the specified font size, line height and character width; finally, according to the determined alignment method, the text to be rendered is laid out to a suitable position in the text area, and the coordinate position of each character is determined.

[0063] Optionally, the first size parameter includes a first width and a first height, and the second size parameter includes a second width and a second height; accordingly, the layout parameters of the text to be rendered are determined according to the first size parameter, the second size parameter and the alignment mode, including: determining a target number of drawing rows according to the first width and the second width; determining a maximum number of drawing rows according to the first height and the second height; determining the layout parameters of the text to be rendered according to the target number of drawing rows, the maximum number of drawing rows and the alignment mode.

[0064] Among them, the second height can be determined by SKPaint.FontSpacing function.

[0065] The target number of lines to be drawn can be calculated using the function (int)System.Math.Celling (second width / first width), that is, the ratio of the second width to the first width is rounded up. For example, when a text to be rendered is displayed in a non-wrapped form, the second width is 20cm, and the first width of the text area is 6cm, then the target number of lines to be drawn = (int)System.Math.Celling (20 / 6) = 4.

[0066] The maximum number of lines to be drawn can be calculated using the function (int)System.Math.Floor(first height / second height), that is, the ratio of the first height to the second height is rounded down. For example, when a text to be rendered is displayed in a non-wrapped form, the second height is 2cm, and the first height of the text area is 11cm, then the maximum number of lines to be drawn = (int)System.Math.Floor(11 / 2) = 5.

[0067] Furthermore, the content and the starting position of each line of the text to be rendered in the text area may be determined according to the alignment of the text to be rendered.

[0068] Exemplarily, the starting position is the lower right corner coordinates of the character bounding box, the origin is the upper left corner of the text area, the vertical direction is the Y axis, and the horizontal direction is the X axis. The starting position of the starting line of the text to be rendered is determined according to the vertical alignment method, including the following three cases.

[0069] 1. The vertical alignment is top alignment: the coordinate value of the starting position of the starting row on the Y axis is the second height.

[0070] 2. The vertical alignment is bottom alignment: if the target number of drawing rows is greater than or equal to the maximum number of drawing rows, the coordinate value of the starting position of the starting row on the Y axis is the second height; if the target number of drawing rows is less than the maximum number of drawing rows, the coordinate value of the starting position of the starting row on the Y axis = first height - second height * (target number of drawing rows - 1).

[0071] 3. The vertical alignment is center alignment: if the target number of drawing rows is greater than or equal to the maximum number of drawing rows, the coordinate value of the starting position of the starting row on the Y axis is the second height; if the target number of drawing rows is less than the maximum number of drawing rows, the coordinate value of the starting position of the starting row on the Y axis = (first height - (target number of drawing rows - 2) * second height) / 2; if the target number of drawing rows is 1, the coordinate value of the starting position of the starting row on the Y axis = (first height + second height) / 2.

[0072] S260: Acquire style parameters corresponding to the text parameters from a text texture cache library and / or a preset font subset library.

[0073] The text texture cache library is a texture cache set generated for historically rendered text based on a preset cache data structure, and the preset cache data structure includes a text identifier, a texture image, and a linked list node.

[0074] S270: Render the text to be rendered according to the layout parameters and the style parameters to obtain a target text.

[0075] The embodiment of the present invention provides a text drawing method, which obtains canvas parameters, text parameters and position parameters of the text to be rendered; determines the first size parameter of the text area according to the canvas parameters; wherein the text area is a specified text drawing area in the canvas; determines the second size parameter of the text to be rendered according to the text parameters; wherein the second size parameter is determined based on the text to be rendered when it is displayed in a non-line-breaking form; determines the alignment of the text to be rendered according to the position parameters; determines the layout parameters of the text to be rendered according to the first size parameter, the second size parameter and the alignment; obtains the style parameters corresponding to the text parameters from a text texture cache library and / or a pre-set font subset library; renders the text to be rendered according to the layout parameters and the style parameters to obtain the target text. This technical solution improves the layout accuracy of the text to be rendered and accelerates the subsequent rendering process by refining the layout parameters of the text to be rendered in the text area.

[0076] Embodiment 3

[0077] Figure 3 This is a flowchart of a text drawing method provided in the second embodiment of the present application. This embodiment is optimized based on the above embodiment, specifically, the rendering process is refined. Figure 3 As shown, the method of this embodiment specifically includes the following steps.

[0078] S310: Obtain canvas parameters, text parameters, and position parameters of the text to be rendered.

[0079] S320: Determine layout parameters of the text to be rendered according to the canvas parameters, the text parameters, and the position parameters.

[0080] S330, acquiring style parameters corresponding to the text parameters from a text texture cache library and / or a preset font subset library;

[0081] The text texture cache library is a texture cache set generated for historically rendered text based on a preset cache data structure, and the preset cache data structure includes a text identifier, a texture image, and a linked list node.

[0082] S340: According to the layout parameters, extract the text content of each line from the text to be rendered, and determine the starting position of each line.

[0083] According to the text area width and font size in the layout parameters, calculate the approximate number of characters that can be accommodated in each line. For example, if the text area width is 500 pixels, the font size is 14 pixels, and the average width of each character is 10 pixels, then about 50 characters can be accommodated. Starting from the beginning of the text to be rendered, check and intercept each character one by one. When the accumulated character width approaches or reaches the width limit of each line, the characters before the current position are intercepted as a line of text content.

[0084] It should be noted that in the text interception process, the influence of special characters and punctuation marks needs to be considered. If a punctuation mark is near the end of a line, it may need to be adjusted according to the typesetting rules. For example, if a comma is near the end of a line, it may need to be put on the same line as the previous word to maintain the coherence of the sentence.

[0085] After determining the starting position of the starting row, the starting Y-axis position of the next row needs to be added with the row spacing.

[0086] S350: Render the text content of each line according to the style parameter and the starting position of each line to obtain the target text.

[0087] Specifically, for each line of text content, first select the appropriate texture or font type according to the style parameters, and then accurately layout the rendered text at the specified position of the text area according to the starting position of each line. All text lines are traversed in sequence, and rendered line by line to obtain the target text.

[0088] Optionally, the text content of each line is rendered according to the style parameters and the starting position of each line to obtain the target text, including: dividing the text content of each line to obtain at least one rendering task; based on a multi-threading mechanism, asynchronously and parallelly processing the at least one rendering task to obtain the target text.

[0089] In the present application, different parts of the text or different text objects are assigned to multiple threads for parallel processing to fully utilize the computing power of a multi-core processor.

[0090] Specifically, the text rendering task can be divided into multiple small tasks, each task processing part of the text; use a multi-threading mechanism to execute these text rendering tasks in parallel, such as Parallel.ForEach or Task.Run; after waiting for all tasks to be completed, merge the rendering results of each task to obtain the target text.

[0091] Loading and rendering text asynchronously in the background ensures the smoothness of the main thread and reduces the response delay of the user interface. For example, when the application starts or when needed, load and initialize the required resources, such as fonts, bitmaps, etc. in advance; for another example, use appropriate data structures to manage loaded resources so that they can be quickly accessed when needed to avoid repeated loading and release.

[0092] The embodiment of the present application provides a text drawing method, which obtains canvas parameters, text parameters and position parameters of the text to be rendered; determines the layout parameters of the text to be rendered according to the canvas parameters, text parameters and position parameters; obtains style parameters corresponding to the text parameters from a text texture cache library and / or a preset font subset library; wherein the text texture cache library is a texture cache set generated for historically rendered text based on a preset cache data structure, and the preset cache data structure includes a text identifier, a texture image and a linked list node; according to the layout parameters, the text content of each line is intercepted from the text to be rendered, and the starting position of each line is determined; according to the style parameters and the starting position of each line, the text content of each line is rendered to obtain the target text. This technical solution improves the rendering efficiency and rendering accuracy of the text by rendering the text to be rendered line by line.

[0093] Embodiment 4

[0094] Figure 4 A schematic diagram of a device 10 that can be used to implement an embodiment of the present application is shown. The device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present application described and / or required herein.

[0095] like Figure 4 As shown, the device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the device 10 can also be stored. The processor 11, ROM 12 and RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0096] A number of components in the device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0097] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as a text drawing method.

[0098] In some embodiments, the text drawing method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the text drawing method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to perform the text drawing method in any other appropriate manner (e.g., by means of firmware).

[0099] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0100] The computer programs for implementing the methods of the present application may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer programs are executed by the processor, the functions / operations specified in the flow charts and / or block diagrams are implemented. The computer programs may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0101] In the context of the present application, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, device, or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0102] To provide interaction with a user, the systems and techniques described herein may be implemented on a device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).

[0103] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0104] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.

[0105] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this application can be executed in parallel, sequentially or in different orders, as long as the expected results of the technical solution of this application can be achieved, and this document is not limited here.

[0106] The above specific implementations do not constitute a limitation on the protection scope of this application. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of this application should be included in the protection scope of this application.< / string> < / string> < / string>

Claims

1. A text drawing method, characterized in that: The method comprises: Get the canvas parameters, text parameters and position parameters of the text to be rendered; Determining layout parameters of the text to be rendered according to the canvas parameters, the text parameters and the position parameters; Acquire style parameters corresponding to the text parameters from a text texture cache library and / or a preset font subset library; wherein the text texture cache library is a texture cache set generated for historically rendered text based on a preset cache data structure, and the preset cache data structure includes a text identifier, a texture image, and a linked list node; The text to be rendered is rendered according to the layout parameters and the style parameters to obtain a target text.

2. The method according to claim 1, characterized in that Determining the layout parameters of the text to be rendered according to the canvas parameters, the text parameters and the position parameters includes: Determine a first size parameter of a text area according to the canvas parameter; wherein the text area is a text drawing area specified in the canvas; Determine a second size parameter of the text to be rendered according to the text parameter; wherein the second size parameter is determined based on when the text to be rendered is displayed in a non-wrapped form; Determining the alignment of the text to be rendered according to the position parameter; Determine layout parameters of the text to be rendered according to the first size parameter, the second size parameter, and the alignment.

3. The method according to claim 2, characterized in that The first size parameter includes a first width and a first height, and the second size parameter includes a second width and a second height; Accordingly, determining the layout parameters of the text to be rendered according to the first size parameter, the second size parameter and the alignment method includes: Determine a target number of drawing rows according to the first width and the second width; Determine a maximum number of drawing rows according to the first height and the second height; Determine the layout parameters of the text to be rendered according to the target number of drawing lines, the maximum number of drawing lines, and the alignment.

4. The method according to claim 1, characterized in that: Rendering the text to be rendered according to the layout parameters and the style parameters to obtain a target text includes: According to the layout parameters, extract the text content of each line from the text to be rendered, and determine the starting position of each line; According to the style parameters and the starting position of each line, the text content of each line is rendered to obtain the target text.

5. The method according to claim 4, characterized in that According to the style parameters and the starting position of each line, the text content of each line is rendered to obtain the target text, including: For each line of text content, segment the text content to obtain at least one rendering task; Based on a multi-thread mechanism, the at least one rendering task is asynchronously processed in parallel to obtain a target text.

6. The method according to claim 1, characterized in that The process of setting the font subset library includes: Obtain at least one target font file; Subsetting the target font files is performed respectively to obtain target font subsets corresponding to the target font files, and the target font subsets are integrated into a font subset library.

7. The method according to claim 1, characterized in that Acquiring style parameters corresponding to the text parameters from a text texture cache library and / or a preset font subset library includes: Determine, according to the text parameters, whether there is a texture cache corresponding to the text to be rendered in the text texture cache library; If there is no texture cache corresponding to the text to be rendered, obtaining style parameters corresponding to the text parameters from a preset font subset library; Alternatively, if there is a texture cache corresponding to the text to be rendered, then the style parameters corresponding to the text to be rendered are obtained from the text texture cache library, and the linked list node of the texture cache corresponding to the text to be rendered is adjusted to the linked list head of the text texture cache library; Alternatively, if there is a texture cache corresponding to part of the text to be rendered, the style parameters corresponding to the part of the text to be rendered are obtained from the text texture cache library, and the linked list node of the texture cache corresponding to the part of the text to be rendered is adjusted to the head of the linked list of the text texture cache library, and the style parameters corresponding to the remaining text to be rendered are obtained from a pre-set font subset library.

8. An electronic device, characterized in that: The device comprises: At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the text drawing method described in any one of claims 1 to 7.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the text drawing method according to any one of claims 1 to 7 when executed.

10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the computer program implements the text drawing method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Text data processing method and apparatus

    CN108460003A

  • Text rendering method and device

    CN113760283A

  • Text rendering method and device, electronic equipment and storage medium

    CN115859910A

  • Character drawing method, system and device based on graph visualization and medium

    CN116778029A

  • Text drawing method and device, computer equipment and storage medium

    CN118260443A

Cited By

  • Dynamic wordart generation method based on SVG hierarchical rendering and Canvas font calculation and related equipment

    CN121349574A