Vector font rendering methods, devices, equipment, and storage media
By extracting control points of Bézier curves to construct triangular units and performing rasterization on the GPU, the performance bottleneck caused by complex preprocessing in existing technologies is solved, achieving efficient vector font rendering and improving rendering efficiency and real-time performance.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-12
- Publication Date
- 2026-04-03
AI Technical Summary
Existing vector font rendering technology requires complex preprocessing steps, resulting in frequent data transfer between the CPU and GPU, which limits rendering performance. This is especially true in application scenarios where a large number of characters are dynamically rendered or font parameters are changed in real time, making it impossible to fully utilize the parallel computing advantages of the GPU.
By extracting Bézier curve control points from vector font files, constructing triangle units and organizing vertex data, generating GPU vertex buffer data, and performing triangle rasterization directly on the GPU, the preprocessing process is simplified and complex distance field pre-calculation is avoided.
It improves the efficiency and real-time performance of vector font rendering, simplifies the preprocessing steps, and fully utilizes the parallel computing power of the GPU to achieve efficient glyph rendering.
Smart Images

Figure CN120953431B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing technology, and in particular to a vector font rendering method, apparatus, device, and storage medium. Background Technology
[0002] In the fields of computer graphics and text rendering, vector fonts are widely used due to their ability to scale infinitely while maintaining clarity. Traditional vector font rendering methods typically require extensive preprocessing of the font data before rendering, including contour analysis, curve discretization, and distance field pre-calculation, to convert the vector data into an intermediate format suitable for GPU processing.
[0003] In existing technologies, these preprocessing steps are typically performed on the CPU, which not only increases the complexity of the rendering pipeline but also leads to frequent data transfers between the CPU and GPU, limiting overall rendering performance. Especially in applications requiring dynamic rendering of large numbers of characters or real-time changes in font parameters, the preprocessing step becomes a performance bottleneck, failing to fully leverage the parallel computing advantages of modern GPUs. Summary of the Invention
[0004] The main objective of this invention is to solve the technical problems of existing vector font rendering technology, which requires complex preprocessing steps and has low GPU utilization efficiency.
[0005] This invention provides a vector font rendering method, the vector font rendering method comprising:
[0006] Based on the specified character encoding and font size parameters, extract the Bézier curve control points of the glyphs from the vector font file to obtain a set of glyph outline control points;
[0007] The starting point of the outline of the set of character outline control points is used as the fan-shaped vertex to construct a triangle unit, and the vertex data of the triangle unit is organized to obtain GPU vertex buffer data.
[0008] The GPU vertex buffer data is transferred to the GPU for triangle rasterization to generate pixel fragments that cover the target rendering area. The wrapping value of each pixel is calculated based on the position of each pixel fragment and the corresponding Bézier curve control point.
[0009] Pixel filling is determined based on the surrounding values, and the pixels inside the character are identified and their colors are assigned according to the determination results to obtain the character rendering image data.
[0010] The present invention also provides a vector font rendering apparatus, the vector font rendering apparatus comprising:
[0011] The glyph extraction unit is used to extract the Bézier curve control points of glyphs from the vector font file according to the specified character encoding and font size parameters, and obtain the glyph outline control point set;
[0012] A triangle construction unit is used to construct a triangle unit by taking the starting point of the outline control point set of the character shape as the fan-shaped vertex, and to organize the vertex data of the triangle unit to obtain GPU vertex buffer data.
[0013] The raster calculation unit is used to transfer the GPU vertex buffer data to the GPU for triangle rasterization processing, generate pixel fragments covering the target rendering area, and calculate the surrounding value corresponding to each pixel based on the position of each pixel fragment and the corresponding Bézier curve control point.
[0014] A pixel filling unit is used to determine pixel filling based on the surrounding value, identify pixels inside the character shape based on the determination result and assign color values to obtain character shape rendering image data.
[0015] The present invention also provides a vector font rendering apparatus, comprising: a memory and at least one processor, wherein the memory stores instructions, and the memory and the at least one processor are interconnected via a circuit; the at least one processor invokes the instructions in the memory to cause the vector font rendering apparatus to perform the steps of the vector font rendering method described above.
[0016] The present invention also provides a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the steps of the vector font rendering method described above.
[0017] The aforementioned vector font rendering method, apparatus, device, and storage medium extract the Bézier curve control points of the glyphs from the vector font file based on character encoding and font size parameters to obtain a set of glyph contour control points. The starting points of the glyph contour control point set are used as fan-shaped vertices to construct triangular units, and vertex data is organized within these triangular units to obtain GPU vertex buffer data. This GPU vertex buffer data is then transferred to the GPU for triangular rasterization to generate pixel fragments. Pixel wrapping values are calculated based on the pixel fragment positions and Bézier curve control points. Pixel filling is determined based on these wrapping values, identifying pixels within the glyphs and assigning color values to them, thus obtaining the glyph rendering image data. This invention simplifies the preprocessing workflow by directly generating GPU vertex data using fan-shaped triangulation, avoiding complex distance field pre-calculation and improving rendering efficiency and real-time performance.
[0018] Other features and advantages of the invention will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention are realized and obtained in accordance with the structures particularly pointed out in the description, claims and drawings.
[0019] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0020] Figure 1 This is a schematic diagram of the first embodiment of the vector font rendering method in this invention;
[0021] Figure 2 This is a schematic diagram of a second embodiment of the vector font rendering method in this invention;
[0022] Figure 3 This is a schematic diagram of one embodiment of the vector font rendering device in this invention;
[0023] Figure 4 This is a schematic diagram of one embodiment of a vector font rendering device according to an embodiment of the present invention. Detailed Implementation
[0024] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0025] The terms "comprising" and "having," and any variations thereof, used in the embodiments of this invention are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the steps or units listed, but may optionally include other steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or devices.
[0026] To facilitate understanding of this embodiment, a vector font rendering method disclosed in this invention will first be described in detail. For example... Figure 1 As shown, this method includes the following steps:
[0027] 101. Based on the specified character encoding and font size parameters, extract the Bézier curve control points of the glyphs from the vector font file to obtain the set of glyph outline control points;
[0028] In this embodiment, the step of extracting the Bézier curve control points of the glyphs from the vector font file according to the specified character encoding and font size parameters to obtain the glyph outline control point set includes: performing a glyph index lookup on the vector font file according to the character encoding to obtain the corresponding glyph index identifier; reading the outline data of the vector font file according to the glyph index identifier to obtain the glyph outline data; extracting the Bézier curve control points in the outline path according to the glyph outline data, and performing coordinate scaling transformation on the Bézier curve control points according to the font size parameters to obtain the glyph outline control point set.
[0029] Specifically, the vector font rendering system can extract and process glyph data based on the FreeType library. In this embodiment, the system first calls the FT_Init_FreeType function to initialize the FreeType library and create an FT_Library object. Then, it loads the vector font file through the FT_New_Face function, specifies the character size, and then calls FT_Set_Char_Size to specify the pixel size, for example, a height of 64 pixels.
[0030] During the glyph index lookup phase, the system uses FT_Get_Char_Index to obtain the glyph index based on the input Unicode encoding, such as U+0041 corresponding to the character 'A'. Then, it calls FT_Load_Glyph to load the glyph and sets the FT_LOAD_NO_SCALE flag to preserve the original coordinates, thereby obtaining the glyph object and accessing the FT_Outline structure.
[0031] It should be noted that during the contour data processing, the system needs to identify different point types in the contour path. The contour data contains two types of key control points: on-curve points and off-curve points. On-curve points are located on the actual contour path and have a flag value of 0x1; off-curve points are used as Bézier curve control points and have a flag value of 0x0. When consecutive off-curve points are detected, for example, starting from points[0], when consecutive off-curve points[1] are detected, the system combines the previous on-curve point points[2] to form a second-order Bézier curve segment.
[0032] Specifically, the mathematical expression for a second-order Bézier curve is:
[0033] ;
[0034] in, and These are the start and end points (on-curve points) on the contour. The control point (off-curve point) has a value range of [0,1].
[0035] During contour data extraction, the system iterates through the control point sequence of each contour, such as a coordinate array containing x0, y0, x1, x2, y1. By analyzing the flag combinations of adjacent control points, the system automatically identifies and constructs the corresponding Bézier curve segments. Whenever an on-curve point with a flag of 0x1 is encountered, the system uses it as the endpoint of the curve segment; when an off-curve point with a flag of 0x0 is encountered, it is used as a control point in curve construction.
[0036] During the coordinate scaling transformation stage, the system transforms the extracted control point coordinates based on the font size parameters. For example, when a font needs to be converted from design units to a specific pixel size, the system calculates the corresponding scaling ratio and applies it to the coordinate values of each control point. This process ensures accurate rendering of the font at different display sizes.
[0037] Through the above processing flow, the system successfully converts the outline information in the original font file into a standardized set of Bézier curve control points. These control points preserve the geometric features and topological relationships of the original glyphs, providing an accurate and reliable geometric data foundation for subsequent GPU rendering. Finally, the GlyphAcquire(charCode, fontPath) interface is called, returning path data containing complete control point information.
[0038] Furthermore, the step of extracting Bézier curve control points from the contour path based on the character contour data includes: identifying the control point type of the character contour data, distinguishing curve points and control points on the contour path based on point markers, and obtaining a classified control point sequence; constructing a second-order Bézier curve based on the pairing combination of curve points and control points in the classified control point sequence, and obtaining a set of Bézier curve segments; and extracting the coordinates of control points used to control the curve shape from each Bézier curve segment in the set of Bézier curve segments, and obtaining Bézier curve control points.
[0039] Specifically, during the control point type identification process, the system distinguishes different types of control points by parsing the point flags in the glyph contour data. In this embodiment, the system traverses each point in the contour structure and reads its corresponding flag information. When the flag is 0x1, the point is identified as an on-curve point, indicating that the point is located on the actual contour path; when the flag is 0x0, the point is identified as an off-curve point and used as a control point for the Bézier curve. The system classifies and marks all control points according to their order in the contour, generating a sequence of classified control points containing point coordinates and type information.
[0040] It should be noted that during the second-order Bézier curve construction stage, the system constructs the second-order Bézier curve based on the pairing of curve points and control points in the classified control point sequence. Specifically, the system checks the control point sequence sequentially according to the contour order. When an on-curve point is encountered, it is taken as the starting point of the curve segment. The next control point is then checked; if it is an off-curve point, it is taken as the control point of the curve. The third control point is then checked; if it is an on-curve point, it is taken as the ending point of the curve segment, thus completing the construction of a complete second-order Bézier curve segment.
[0041] When dealing with the special case of consecutive off-curve points, such as detecting consecutive off-curve points points[1] starting from points[0], the system uses midpoint interpolation. Specifically, when two consecutive off-curve points are detected, the system calculates the midpoint position between the two points and uses this midpoint as a virtual on-curve point, thus ensuring that each second-order Bézier curve segment has a clear start point, control point, and end point. Through this pairing and combination method, the system decomposes the entire contour path into several independent second-order Bézier curve segments, forming a set of Bézier curve segments.
[0042] During the organization of the Bézier curve segment set, the system assigns a unique identifier to each constructed curve segment and records its positional relationship within the original contour. Each Bézier curve segment contains complete information on three key control points, including the coordinate data of the start point, control points, and end point. These curve segments are arranged according to the topological order of the contour, ensuring the complete preservation of the glyph's geometric features.
[0043] In the control point coordinate extraction stage, the system processes each Bézier curve segment in the set of Bézier curve segments to extract the coordinates of the control points used to control the curve shape. For second-order Bézier curves, the control points in the middle truly affect the curve shape, determining the degree and direction of curvature. The system traverses the set of Bézier curve segments, extracting the x and y coordinate values of the control points from each segment and storing this coordinate information in a standardized data structure.
[0044] Specifically, during the data extraction process, the system identifies the off-curve points marked with 0x0 in each Bézier curve segment and extracts their coordinate information as control points of the Bézier curve. For example, for contour data containing coordinate arrays x0, y0, x1, x2, y1, the system identifies the coordinates of the control points used to control the curve shape and organizes them into a data format that is convenient for subsequent GPU processing.
[0045] Through the above processing steps, the system successfully converts complex glyph contour data into a set of Bézier curve segments by classifying control point sequences, and extracts key Bézier curve control points from them. The final set of control points contains all the geometric information needed to reconstruct the complete glyph contour.
[0046] 102. Construct triangular units by using the starting points of the character outline control point set as fan-shaped vertices, and organize the vertex data of the triangular units to obtain GPU vertex buffer data;
[0047] In this embodiment, the step of constructing triangular units by using the starting points of the character contour control point set as fan-shaped vertices and organizing the vertex data of the triangular units to obtain GPU vertex buffer data includes: grouping the character contour control point set into contour groups; dividing the Bézier curve control points into independent contour groups according to the contour closure boundary to obtain a contour group set; using the starting point of each contour group in the contour group set as the fan-shaped center, connecting adjacent control points within the contour group in a fan-shaped manner to construct triangular units with the fan-shaped center as vertices to obtain a triangular unit sequence; calculating parameter values and normal vectors according to the Bézier curve positions corresponding to the vertices of each triangular unit in the triangular unit sequence to obtain triangular unit vertex attributes; and arranging the triangular unit vertex attributes according to the GPU buffer format requirements, organizing the triangular units into a contiguous storage structure according to the rendering order to obtain GPU vertex buffer data.
[0048] Specifically, in the contour grouping stage, the system analyzes the set of control points for the character contours and identifies independent contour boundaries within the character. In this embodiment, complex characters often contain multiple closed contours; for example, the letter 'O' contains two independent closed boundaries: an outer contour and an inner contour. The system analyzes the connection relationships and closure characteristics of the Bézier curve control points to divide the entire set of control points according to the contour boundaries. Specifically, the system identifies the start and end points of each closed contour. When a contour path forms a closed loop, all Bézier curve control points within that loop are grouped into an independent contour group. Through this grouping method, the system obtains a set of contour groups containing multiple independent contour groups, with each contour group corresponding to a closed region within the character.
[0049] It should be noted that in the sector triangulation stage, the system adopts a sector connection strategy centered on the starting point of the contour. For each contour group in the contour group set, the system first determines the coordinates of the starting point of the contour group and sets it as the center of the sector. Subsequently, the system traverses the adjacent control points within the contour group according to the topological order of the contours, connecting the center of the sector with each pair of adjacent control points to form a triangular structure with the center of the sector as the common vertex.
[0050] Specifically, for a contour group containing n control points, the system generates (n-1) triangular units. For example, when the contour group contains control points P0, P1, P2, ..., Pn, the system uses P0 as the center of a sector and connects P0-P1-P2, P0-P2-P3, ..., P0-Pn-1-Pn sequentially to construct a series of triangular units. Each triangular unit contains three vertices: the center vertex of the sector and two adjacent contour control points. This sector-shaped connection method ensures that the internal region of the character is completely covered while maintaining the geometric features of the contour. By performing the same processing flow on all contour groups, the system obtains a complete sequence of triangular units.
[0051] During the vertex attribute calculation phase of the triangle unit, the system calculates the corresponding Bézier curve parameter values and normal vector information for each vertex of the triangle unit. For each triangle in the triangle unit sequence, the system first determines the positional relationship of its three vertices on the original Bézier curve. Specifically, the system calculates the Bézier curve parameter t value corresponding to each vertex, which describes the relative position of the vertex on the curve. Simultaneously, the system calculates the normal vector N based on the tangent direction of the Bézier curve, which is used for subsequent distance field calculations and rendering processing.
[0052] Specifically, during parameter value calculation, the system uses numerical methods to solve for the curve parameters corresponding to each vertex. For vertices located on Bézier curves, the system determines their precise parameter value t through an iterative algorithm. For non-curve vertices such as the center of a sector, the system assigns corresponding parameter identifiers for subsequent identification. The calculation of the normal vector is based on the tangent direction of the Bézier curve at that point and is defined by a vector perpendicular to the tangent. These parameter values and normal vector information are integrated into the vertex attributes of the triangle unit, forming a complete data structure containing geometric coordinates, curve parameters, and normal vectors.
[0053] During the GPU buffer data organization phase, the system rearranges and organizes the vertex attributes of triangle units according to the data format requirements of the GPU rendering pipeline. Specifically, the system arranges the vertex data of each triangle unit according to the standard format of the GPUvertex buffer, including the contiguous storage of attribute information such as vertex coordinates, texture coordinates, and normal vectors. The system also considers GPU memory alignment requirements to ensure efficient access to data in video memory.
[0054] Furthermore, the system sorts the triangle units according to the rendering order, organizing related triangle units into a contiguous storage structure. This organization method is beneficial for GPU parallel processing and cache optimization. Finally, the system generates GPU vertex buffer data conforming to the OpenGL vertex buffer object (VBO) format, providing efficient data input for subsequent GPU rendering stages. Through the above processing flow, the system successfully converts glyph contour control points into triangular mesh data that can be directly processed by the GPU.
[0055] 103. The GPU vertex buffer data is transferred to the GPU for triangle rasterization processing to generate pixel fragments covering the target rendering area, and the wrap value corresponding to each pixel is calculated based on the position of each pixel fragment and the corresponding Bézier curve control point.
[0056] In this embodiment, the transmission of GPU vertex buffer data is implemented through the standard OpenGL rendering pipeline. The system first transmits the prepared GPU vertex buffer data to the GPU memory via the bus interface and binds it to the vertex buffer of the GPU rendering pipeline. Specifically, the system calls the corresponding graphics API functions to upload the data structure containing the vertex attributes of triangle units to the GPU memory space, ensuring that the GPU can directly access this geometric data.
[0057] It's important to note that during the triangle rasterization stage, the GPU performs standard graphics rendering pipeline operations on the transmitted vertex data. The system utilizes the GPU's parallel processing capabilities to convert each triangle unit into a discrete pixel mesh covering the target rendering area. In this process, the GPU's rasterization units determine the coverage area of each triangle in screen space and generate corresponding pixel fragments for each pixel location within the coverage area. These pixel fragments contain the pixel's screen coordinates, depth information, and relevant parameters obtained from vertex attribute interpolation.
[0058] Specifically, during pixel fragment generation, the GPU rasterizer scans the boundary of each triangle unit to determine which pixel locations are covered by that triangle. For each pixel location within the target rendering area, the system checks whether it is located inside any triangle unit. When a pixel location is covered by a triangle, the GPU creates a pixel fragment for that location and calculates various attribute values for that pixel fragment using barycentric coordinate interpolation.
[0059] During the vertex attribute interpolation stage, the system utilizes the GPU's interpolation hardware to calculate the attributes of pixel fragments. For each generated pixel fragment, the GPU performs linear interpolation on the attributes of the three vertices of the triangle based on the pixel's centroid coordinates within the triangle. These attributes include data calculated during the vertex data organization stage, such as Bézier curve parameters and normal vector information. Through interpolation calculations, each pixel fragment obtains curve parameter information corresponding to its position.
[0060] During the wraparound numerical calculation phase, the system utilizes the positional information of pixel fragments and the control point information of Bézier curves obtained through interpolation to calculate the corresponding wraparound value for each pixel fragment. Specifically, the system analyzes the positional relationship of the pixel fragment relative to the glyph outline and determines the wraparound contribution value of that pixel using appropriate geometric algorithms. This calculation process fully leverages the parallel computing capabilities of the GPU, enabling simultaneous wraparound numerical calculations for a large number of pixel fragments.
[0061] Furthermore, the GPU maintains the association between each pixel fragment and its corresponding Bézier curve control points during processing. Using the curve parameter information passed in previous stages, the system can accurately determine which Bézier curve control points each pixel fragment should reference for wrapping value calculations. Ultimately, each pixel fragment obtains a wrapping value representing its positional relationship relative to the glyph outline. Through the aforementioned GPU parallel processing flow, the system achieves efficient conversion from geometric data to pixel-level wrapping information.
[0062] 104. Pixel filling is determined based on the surrounding values. Based on the determination results, pixels inside the character are identified and color values are assigned to obtain character rendering image data.
[0063] In this embodiment, the step of determining pixel filling based on the surrounding value, identifying pixels inside the character shape based on the determination result, and assigning color values to obtain character shape rendering image data includes: determining the parity of the surrounding value through modulo-2 operation to obtain a parity determination result, and identifying pixels inside the character shape based on the parity determination result; calculating the Euclidean distance from the pixels inside the character shape to the nearest Bézier curve to obtain a pixel distance value; calculating the pixel transparency coefficient based on the pixel distance value using a smoothing function, and assigning color values to the corresponding pixel positions based on the pixel transparency coefficient to obtain character shape rendering image data.
[0064] In this embodiment, the pixel filling determination process is based on a wrapping rule algorithm, which determines the filling state of each pixel by analyzing its positional relationship relative to the glyph outline. The system first performs a modulo-2 operation on the wrapping value of each pixel fragment; the specific calculation formula is as follows:
[0065] wind count modulo 2 ≠ 0;
[0066] Here, `wind_count` represents the wrapping value of a pixel. When the modulo-2 operation result is not equal to zero, it indicates that the pixel is located inside the character; when the result is equal to zero, it indicates that the pixel is located outside the character. This parity determination method effectively solves the problem of filling multiple contours in complex characters, ensuring accurate identification of the internal regions of the character.
[0067] It should be noted that during the pixel recognition process within the glyph, the system traverses all pixel fragments within the target rendering area and applies the aforementioned parity determination rule to the wrapping value of each pixel. Through this parallel determination method, the GPU can simultaneously process the fill state calculations of a large number of pixels, significantly improving rendering efficiency. For fragments determined to be internal pixels, the system marks them as pixels requiring subsequent color assignment; for external pixels, they are either discarded or set to transparent.
[0068] In the distance field calculation phase, the system calculates the Euclidean distance from each recognized pixel within a glyph to the nearest Bézier curve. Specifically, the system uses a numerical iterative method to solve for the shortest distance from each pixel to its corresponding Bézier curve. For the pixel position P_model, the system finds the curve parameter t_m,in that minimizes the distance by solving the parametric equation, such that |P_model - B(t)| reaches its minimum value. In the actual calculation, the system uses a numerical method with 8 iterations and a convergence threshold of 0.0001 to ensure calculation accuracy.
[0069] Specifically, the calculation of the distance field involves determining the symbolic distance. The system first calculates the shortest distance point from the pixel to the curve, and then determines the symbolic distance using the following formula:
[0070] ;
[0071] in, Represents pixel coordinates, sd represents the point on the curve closest to the pixel, and N represents the normal vector of the curve at that point. When sd < 0, the pixel is inside the curve; when sd ≥ 0, the pixel is outside the curve. Through this calculation of the symbolic distance field, the system can accurately determine the positional relationship of each pixel relative to the glyph boundary.
[0072] During the anti-aliasing process, the system uses a smoothing function to process the pixel distance values and calculates the corresponding transparency coefficient. Specifically, the system uses the smoothstep function to achieve edge smoothing. When the pixel distance value d meets certain conditions, the system applies the following smoothing function:
[0073] If d < 0.5, then the opacity factor is calculated using smoothstep(0.0, 1.0, d + 0.5). This smoothing method creates a gradient effect at the edges of the glyphs, effectively eliminating jagged edges and improving rendering quality.
[0074] During the color assignment phase, the system blends the calculated transparency coefficient with the preset font color. Specifically, the system uses OpenGL 4.6 pixel shaders to perform color blending calculations, employing the gl_FragCoord coordinate system and RGBA32F format to process color data. The alpha channel stores transparency information, and the RGB channels store color values.
[0075] It should be noted that during the final image data generation process, the system stores the rendering results in a texture buffer using framebuffer texture technology. The system uses the glFramebufferTexture2D function to bind the rendering target and glReadPixels to read the final rendering data. The entire rendering process is completed at a real-time frame rate of 60fps, ensuring the smoothness and real-time performance of the glyph rendering.
[0076] Through the complete pixel fill determination and color assignment process described above, the system successfully converts the surrounding numerical information into the final glyph rendering image data, achieving high-quality vector font GPU rendering effects.
[0077] In this embodiment, the Bézier curve control points of the glyphs are extracted from the vector font file according to the character encoding and font size parameters to obtain a set of glyph contour control points. The starting points of the glyph contour control points set are used as fan-shaped vertices to construct triangular units, and vertex data is organized within these triangular units to obtain GPU vertex buffer data. The GPU vertex buffer data is then transferred to the GPU for triangular rasterization to generate pixel fragments. Pixel wrapping values are calculated based on the pixel fragment positions and Bézier curve control points. Pixel filling is determined based on the wrapping values, identifying pixels within the glyphs and assigning color values to them to obtain the glyph rendering image data. This invention simplifies the preprocessing process by directly generating GPU vertex data using fan-shaped triangulation, avoiding complex distance field pre-calculation and improving rendering efficiency and real-time performance.
[0078] Please see Figure 2 Another embodiment of the vector font rendering method in this application includes:
[0079] 201. Based on the specified character encoding and font size parameters, extract the Bézier curve control points of the glyphs from the vector font file to obtain the set of glyph outline control points;
[0080] 202. Construct triangular units by using the starting points of the character outline control point set as fan-shaped vertices, and organize the vertex data of the triangular units to obtain GPU vertex buffer data;
[0081] In this embodiment, steps 201-202 are similar to steps 101-102 in the first embodiment, and will not be described again here.
[0082] 203. Transfer the GPU vertex buffer data to the GPU memory and bind it to the rendering pipeline to obtain GPU vertex data;
[0083] In this embodiment, the transmission of GPU vertex buffer data is implemented through a standard graphics interface. The system first transmits the prepared vertex buffer data to the GPU memory via the bus interface, allocating corresponding storage areas for the vertex data within the GPU memory space. Specifically, the system calculates the required memory capacity based on the number of triangle units and vertex attribute information, ensuring that the GPU can completely store all vertex geometric data.
[0084] It should be noted that during the data transmission phase, the system uses a batch transmission method to upload the vertex data organized on the CPU to the GPU memory. The transmitted data includes the vertex attributes of the triangle units generated in the previous steps, including vertex coordinates, curve parameters, normal vectors, and other information. This data is organized according to the format required by the GPU to ensure that the GPU can efficiently access and parse the vertex information.
[0085] During the rendering pipeline binding phase, the system binds the vertex data transferred to the GPU memory to the GPU rendering pipeline. Specifically, the system establishes the association between vertex data and GPU processing units, configuring the corresponding data access paths. Through this binding mechanism, each processing stage of the GPU can access vertex data sequentially and perform corresponding geometric transformations and processing operations on it.
[0086] In addition, the system sets the format description information for the vertex data, including the data type, size, and memory layout of each vertex attribute. This format information guides the GPU to correctly parse the vertex data structure, ensuring that subsequent processing stages can accurately obtain the attribute values of the vertices. Through the above transmission and binding process, the original vertex buffer data is successfully converted into vertex data that the GPU can directly process, providing complete geometric data input for the subsequent rasterization processing stage.
[0087] 204. Perform triangular rasterization on the GPU vertex data to generate pixel fragments covering the target rendering area;
[0088] In this embodiment, triangle rasterization is performed by the GPU's rasterization unit. The system utilizes the GPU's parallel processing capabilities to assemble bound vertex data into triangle primitives and then performs rasterization scanning on these triangles. Specifically, the GPU combines every three vertices to form a triangle unit and then determines the coverage area of each triangle within the target rendering region.
[0089] It's important to note that during rasterization, the GPU scans the pixel area covered by each triangle to determine which pixel locations are occupied by that triangle. For each pixel location within the target rendering area, the system checks if it lies inside any triangle. When a pixel location is covered by a triangle, the GPU generates a corresponding pixel fragment for that location.
[0090] Specifically, during pixel fragment generation, the system creates fragment data containing positional information for each pixel location covered by a triangle. These pixel fragments record the pixel's coordinates within the rendering area and the relationship between the pixel and the triangle covering it. Simultaneously, the system reserves attribute storage space for each pixel fragment for subsequent vertex attribute interpolation processing.
[0091] During the processing of the target rendering area, the system determines the effective range of rasterization based on the preset rendering size. For example, when a specific rendering area size is set, the rasterizer will limit the processing range to that area, generating fragments only for pixels covered by triangles within that area. This area limitation ensures the efficiency and accuracy of rasterization processing.
[0092] Through the rasterization process described above, the GPU successfully converts geometric triangle data into pixel-level fragment data. The generated set of pixel fragments covers all pixel positions occupied by triangles within the target rendering area, forming a discrete pixel-level representation of the glyphs, providing the basic data for subsequent pixel attribute interpolation and surrounding numerical calculations.
[0093] 205. Perform vertex attribute interpolation on the pixel fragment to obtain pixel curve parameters, and calculate pixel wrapping values based on the pixel curve parameters and Bézier curve control points to obtain wrapping values;
[0094] In this embodiment, the step of calculating the pixel wrapping value based on the pixel curve parameters and Bézier curve control points to obtain the wrapping value includes: determining the Bézier curve segment corresponding to the pixel fragment based on the pixel curve parameters and Bézier curve control points to obtain a pixel curve mapping table; emitting rays from each pixel position according to the pixel curve mapping table and calculating the intersection points with the corresponding Bézier curve segments to obtain ray intersection point data; performing directional analysis on the ray intersection point data and calculating the intersection contribution value of the corresponding Bézier curve segment based on the directional analysis results; and summing the intersection contribution values of all Bézier curve segments that intersect with the ray to obtain the wrapping value.
[0095] Specifically, in this embodiment, the vertex attribute interpolation process utilizes the GPU's hardware interpolation unit for efficient parallel computation. For each pixel fragment generated during the rasterization stage, the system performs linear interpolation on the attributes of the three vertices of the triangle based on the pixel's centroid coordinates within the triangle. Specifically, the system extracts the position weight of each pixel fragment within its respective triangle and applies these weights to the curve parameter attributes of the vertex. Through this interpolation mechanism, each pixel fragment obtains Bézier curve parameter information corresponding to its spatial position, forming pixel curve parameter data.
[0096] It should be noted that during the pixel curve mapping table establishment process, the system establishes the correspondence between pixels and curve segments based on pixel curve parameters and Bézier curve control point information. Specifically, the system analyzes the curve parameters of each pixel fragment to determine which Bézier curve segments the pixel is associated with. By parsing the pixel's interpolation parameters, the system can trace back to the original Bézier curve segment identifier and position information corresponding to that pixel. This mapping relationship is organized into a pixel curve mapping table, providing a precise geometric reference for subsequent ray casting calculations.
[0097] During the ray casting calculation phase, the system executes the ray casting algorithm for each pixel location based on the pixel curve mapping table. Specifically, the system emits a ray from the center of each pixel in a fixed direction (usually horizontal to the right) and calculates the intersection point of this ray with the corresponding Bézier curve segment of the pixel. In the intersection point calculation process, the system needs to solve the intersection equation of the ray and the second-order Bézier curve, and determine the precise location and number of intersection points using numerical methods.
[0098] Specifically, the system needs to find the intersection points of the ray and the Bézier curve. By simultaneously solving the ray equation and the Bézier curve equation, the system can obtain an equation about the parameter t, and determine the parameter value of the intersection point by solving this equation. Each valid intersection point is recorded in the ray intersection point data, containing the position coordinates of the intersection point and the corresponding curve parameter information.
[0099] During the directional analysis phase, the system performs a detailed geometric analysis of the ray intersection data to determine the contribution of each intersection point to the wraparound value. Specifically, the system examines the tangent direction of the Bézier curve at each intersection point to determine whether the curve crosses the ray from below to above or from above to below. Based on the crossing direction, the system assigns a corresponding contribution value to each intersection point: when the curve crosses the ray from below to above, the contribution value is +1; when the curve crosses the ray from above to below, the contribution value is -1.
[0100] It should be noted that when dealing with complex contours, a ray may intersect with multiple Bézier curve segments. The system analyzes the directionality of each intersection point one by one to ensure that the contribution value of each Bézier curve segment at the intersection point is calculated correctly. This segment-by-segment analysis method ensures that the independent contribution of each contour part in a complex glyph to the wrapping value can be accurately identified and quantified.
[0101] During the wraparound numerical accumulation calculation phase, the system algebraically sums the contribution values of all Bézier curve segments that intersect with the ray. Specifically, the system iterates through all valid intersections in the ray intersection data, extracts the contribution value corresponding to each intersection, and performs an accumulation operation. The final accumulation result is the wraparound value at that pixel position, which reflects the positional relationship of the pixel relative to the entire glyph outline.
[0102] Through the complete calculation process described above, the system successfully converts pixel-level geometric information into numerical wrapping information. Each pixel receives a precise wrapping value, which is used in the subsequent fill determination stage to determine whether the pixel is inside the glyph, thereby achieving accurate glyph rendering results.
[0103] 206. Pixel filling is determined based on the surrounding values. Based on the determination results, pixels inside the character are identified and color values are assigned to obtain character rendering image data.
[0104] In this embodiment, step 206 is similar to step 104 in the first embodiment, and will not be described again here.
[0105] In this embodiment, the Bézier curve control points of the glyphs are extracted from the vector font file according to the character encoding and font size parameters to obtain a set of glyph contour control points. The starting points of the glyph contour control points set are used as fan-shaped vertices to construct triangular units, and vertex data is organized within these triangular units to obtain GPU vertex buffer data. The GPU vertex buffer data is then transferred to the GPU for triangular rasterization to generate pixel fragments. Pixel wrapping values are calculated based on the pixel fragment positions and Bézier curve control points. Pixel filling is determined based on the wrapping values, identifying pixels within the glyphs and assigning color values to them to obtain the glyph rendering image data. This invention simplifies the preprocessing process by directly generating GPU vertex data using fan-shaped triangulation, avoiding complex distance field pre-calculation and improving rendering efficiency and real-time performance.
[0106] The vector font rendering method in the embodiments of the present invention has been described above. The vector font rendering apparatus in the embodiments of the present invention will be described below. Please refer to [link to relevant documentation] for details. Figure 3 One embodiment of the vector font rendering device in this invention includes:
[0107] The character shape extraction unit 301 is used to extract the Bézier curve control points of the character shape from the vector font file according to the specified character encoding and font size parameters, so as to obtain a set of character shape outline control points;
[0108] Triangle construction unit 302 is used to construct triangle units by taking the contour starting point of the set of character contour control points as fan-shaped vertices, and to organize the vertex data of the triangle units to obtain GPU vertex buffer data;
[0109] The raster calculation unit 303 is used to transmit the GPU vertex buffer data to the GPU for triangle rasterization processing, generate pixel fragments covering the target rendering area, and calculate the surrounding value corresponding to each pixel based on the position of each pixel fragment and the corresponding Bézier curve control point.
[0110] The pixel filling unit 304 is used to determine the pixel filling based on the surrounding value, identify the pixels inside the character shape according to the determination result and assign color values to obtain the character shape rendering image data.
[0111] In this embodiment of the invention, the vector font rendering device runs the aforementioned vector font rendering method. The device extracts the Bézier curve control points of the glyphs from the vector font file based on character encoding and font size parameters to obtain a set of glyph contour control points. It then constructs triangular units using the starting points of the glyph contour control point set as fan-shaped vertices, and organizes the vertex data of these triangular units to obtain GPU vertex buffer data. The GPU vertex buffer data is then transmitted to the GPU for triangular rasterization to generate pixel fragments. Pixel wrapping values are calculated based on the pixel fragment positions and Bézier curve control points. Pixel filling is determined based on the wrapping values, identifying pixels within the glyphs and assigning color values to them to obtain the glyph rendering image data. This invention simplifies the preprocessing process by directly generating GPU vertex data using fan-shaped triangulation, avoiding complex distance field pre-calculation and improving rendering efficiency and real-time performance.
[0112] above Figure 3 The vector font rendering device in this embodiment of the invention will be described in detail from the perspective of unitized functional entities. The vector font rendering device in this embodiment of the invention will be described in detail from the perspective of hardware processing.
[0113] Figure 4 This is a schematic diagram of the structure of a vector font rendering device 300 provided in an embodiment of the present invention. The vector font rendering device 300 can vary significantly due to different configurations or performance. It may include one or more central processing units (CPUs) 410 (e.g., one or more processors) and a memory 420, and one or more storage media 430 (e.g., one or more mass storage devices) for storing application programs 333 or data 432. The memory 420 and storage media 430 can be temporary or persistent storage. The program stored in the storage media 430 may include one or more units (not shown in the diagram), each unit may include a series of instruction operations on the vector font rendering device 400. Furthermore, the processor 410 may be configured to communicate with the storage media 430 and execute the series of instruction operations in the storage media 430 on the vector font rendering device 400 to implement the steps of the above-described vector font rendering method.
[0114] The vector font rendering device 400 may also include one or more power supplies 440, one or more wired or wireless network interfaces 450, one or more input / output interfaces 460, and / or one or more operating systems 431, such as Windows Server, Mac OS X, Unix, Linux, FreeBSD, etc. Those skilled in the art will understand that... Figure 4The illustrated vector font rendering device structure does not constitute a limitation on the vector font rendering device provided by the present invention. It may include more or fewer components than illustrated, or combine certain components, or have different component arrangements.
[0115] The present invention also provides a computer-readable storage medium, which can be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium, wherein the computer-readable storage medium stores instructions that, when the instructions are executed on a computer, cause the computer to perform the steps of the vector font rendering method.
[0116] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the system, device, or unit described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0117] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0118] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A vector font rendering method, characterized in that, The vector font rendering method includes: Based on the specified character encoding and font size parameters, extract the Bézier curve control points of the glyphs from the vector font file to obtain a set of glyph outline control points; The set of character outline control points is grouped into outlines. Based on the closed boundary of the outline, the Bézier curve control points are divided into independent outline groups, resulting in an outline group set. Using the starting point of each outline group as the center of a sector, adjacent control points within the outline group are connected in a sector shape to construct triangular units with the sector center as vertices, resulting in a triangular unit sequence. Parameter values and normal vectors are calculated based on the Bézier curve position corresponding to the vertex of each triangular unit in the triangular unit sequence, yielding the triangular unit vertex attributes. According to the GPU buffer format requirements, the triangular unit vertex attributes are arranged into a contiguous storage structure according to the rendering order, resulting in GPU vertex buffer data. The GPU vertex buffer data is transferred to GPU memory and bound to the rendering pipeline to obtain GPU vertex data. The GPU vertex data is then rasterized to generate pixel fragments covering the target rendering area. Vertex attribute interpolation is performed on the pixel fragments to obtain pixel curve parameters. Based on the pixel curve parameters and Bézier curve control points, the corresponding Bézier curve segments are determined to obtain a pixel curve mapping table. Rays are emitted from each pixel position according to the pixel curve mapping table and their intersections with the corresponding Bézier curve segments are calculated to obtain ray intersection data. Directional analysis is performed on the ray intersection data, and the intersection contribution value of the corresponding Bézier curve segments is calculated based on the directional analysis results. The intersection contribution values of all Bézier curve segments that intersect with the ray are accumulated to obtain a surround value. Pixel filling is determined based on the surrounding values, and the pixels inside the character are identified and their colors are assigned according to the determination results to obtain the character rendering image data.
2. The vector font rendering method according to claim 1, characterized in that, The step of extracting Bézier curve control points of glyphs from a vector font file based on specified character encoding and font size parameters to obtain a set of glyph outline control points includes: The vector font file is searched for glyph indexes based on the character encoding to obtain the corresponding glyph index identifiers. The outline data of the vector font file is read according to the glyph index identifier to obtain the glyph outline data; Based on the character outline data, extract the Bézier curve control points in the outline path, and perform coordinate scaling transformation on the Bézier curve control points according to the font size parameters to obtain the character outline control point set.
3. The vector font rendering method according to claim 2, characterized in that, The step of extracting Bézier curve control points from the contour path based on the glyph contour data includes: The control point type is identified in the character outline data. Based on the point marker, the curve points and control points on the outline path are distinguished to obtain a classified control point sequence. A second-order Bézier curve is constructed based on the pairing combination of curve points and control points in the classification control point sequence, resulting in a set of Bézier curve segments. The coordinates of control points used to control the curve shape are extracted from each Bézier curve segment in the set of Bézier curve segments to obtain the Bézier curve control points.
4. The vector font rendering method according to claim 1, characterized in that, The step of determining pixel filling based on the surrounding value, identifying pixels inside the character shape based on the determination result, and assigning color values to obtain the character shape rendering image data includes: The parity of the surrounding values is determined by modulo-2 operation to obtain the parity determination result, and the pixels inside the character are identified based on the parity determination result. Calculate the Euclidean distance from the pixel inside the character to the nearest Bézier curve to obtain the pixel distance value; The pixel transparency coefficient is calculated based on the pixel distance value using a smoothing function, and the corresponding pixel position is assigned a color value based on the pixel transparency coefficient to obtain the character rendering image data.
5. A vector font rendering device, characterized in that, The vector font rendering device includes: The glyph extraction unit is used to extract the Bézier curve control points of glyphs from the vector font file according to the specified character encoding and font size parameters, and obtain the glyph outline control point set; A triangular construction unit is used to group the control points of the glyph contour into contour groups. Based on the contour closure boundary, the Bézier curve control points are divided into independent contour groups, resulting in a contour group set. Using the starting point of each contour group as the center of a sector, adjacent control points within the contour group are connected in a sector shape to construct triangular units with the sector center as vertices, resulting in a triangular unit sequence. Parameter values and normal vectors are calculated based on the Bézier curve position corresponding to the vertex of each triangular unit in the triangular unit sequence to obtain the triangular unit vertex attributes. According to the GPU buffer format requirements, the triangular unit vertex attributes are arranged into a contiguous storage structure according to the rendering order, resulting in GPU vertex buffer data. A raster computation unit is used to transfer the GPU vertex buffer data to the GPU memory and bind it to the rendering pipeline to obtain GPU vertex data; perform triangular rasterization processing on the GPU vertex data to generate pixel fragments covering the target rendering area; perform vertex attribute interpolation on the pixel fragments to obtain pixel curve parameters, and determine the Bézier curve segment corresponding to the pixel fragment based on the pixel curve parameters and Bézier curve control points to obtain a pixel curve mapping table; emit rays from each pixel position according to the pixel curve mapping table and calculate the intersection points with the corresponding Bézier curve segments to obtain ray intersection point data; perform directional analysis on the ray intersection point data, and calculate the intersection contribution value of the corresponding Bézier curve segment based on the directional analysis results; accumulate the intersection contribution values of all Bézier curve segments that intersect with the ray to obtain the surround value; A pixel filling unit is used to determine pixel filling based on the surrounding value, identify pixels inside the character shape based on the determination result and assign color values to obtain character shape rendering image data.
6. A vector font rendering device, characterized in that, The vector font rendering device includes: a memory and at least one processor, wherein the memory stores instructions; The at least one processor invokes the instructions in the memory to cause the vector font rendering device to perform the steps of the vector font rendering method as described in any one of claims 1-4.
7. A computer-readable storage medium storing instructions thereon, characterized in that, When the instruction is executed by the processor, it implements the steps of the vector font rendering method as described in any one of claims 1-4.
Citation Information
Patent Citations
Method for rendering subtitling based on curved profile closed loop domain and pixel mask matrix
CN101465973A
Character rendering system
CN101540054A