Method for writing OpenMap punctiform symbols into TrueType characters
By processing the attribute and path information of map symbols at the underlying data structure level, it provides a method for writing TrueType characters to OpenMap dot symbols, which solves the problems of insufficient sharing accuracy and single method in the prior art, and realizes accurate, fast sharing and high-quality data conversion of map symbol resources.
Patent Information
- Application Number
- CN202411849386.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-16
- Publication Date
- 2025-05-16
AI Technical Summary
The existing geographical information symbol system is difficult to realize symbol data sharing, resulting in low sharing and reusability of map symbol resources, resulting in data redundancy and unnecessary cost.
By directly processing the attribute information and path coordinate information of symbols at the underlying data structure level, an OpenMap dot symbol is provided to write TrueType characters, thereby achieving accurate and fast sharing of map symbol resources.
The OpenMap dot symbol is implemented to write TrueType characters with high precision, which is suitable for sharing operations of other symbol data structures, ensures the sharing quality, and directly processes symbol information at the bottom, realizing effective mapping and conversion.
Smart Images

Figure CN120011463A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the field of geographic information system and computer map making, and in particular to a method for writing OpenMap dot symbols into TrueType characters. Background Art
[0002] It is often difficult to share symbol data between existing geographic information symbol systems, which greatly reduces the sharing and reusability of map symbol resources, and brings huge data redundancy and unnecessary costs to GIS data production, transmission, storage, etc. Geographic information sharing technology, especially map symbol sharing technology, is an important method to solve this problem. However, most of the existing map symbol sharing technologies map at the object level of data, such as the path type and drawing mode of the symbol, which makes it difficult to achieve symbol sharing.
[0003] To solve the above problems, a new map symbol sharing method is needed, which is required to be able to directly process the symbol's attribute information and path coordinate information at the underlying data structure level, so as to achieve mapping and transformation. Summary of the invention
[0004] Purpose of the invention: To solve the problem of cross-platform map symbol sharing and the problems of insufficient precision and single method in existing map symbol sharing, the present invention provides a method for writing OpenMap point symbols into TrueType characters to achieve accurate and fast sharing of map symbol resources.
[0005] The technical solution for implementing the present invention is: a method for writing TrueType characters into OpenMap dot symbols, the method comprising the following steps:
[0006] Reading an OpenMap point symbol from a symbol library, and obtaining a graphic and basic information of the OpenMap point symbol; the basic information includes the number of contours, bounding box information, the number of coordinate points, and path coordinates of the OpenMap point symbol;
[0007] Constructing a dot symbol cache stream, scaling the dot symbol according to the drawing range of the TrueType character, defining the index position of the OpenMap dot symbol, and writing the index position and the basic information after scaling and updating into the dot symbol cache stream;
[0008] Creating a character cache stream according to the information stored in the dot symbol cache stream, and re-encoding the character elements in the character cache stream respectively; the character elements are a necessary table of character composition, including HHEA, MAXP, OS, HMTX, CMAP, LOCA, GLYF, NAME, and POST;
[0009] Create a font container and save the re-encoded character buffer stream into a complete font file.
[0010] Furthermore, the process of reading OpenMap point symbols is to first deserialize the symbol library file to obtain the point symbols stored in the file, and then determine the type of each primitive in the point symbol in turn, and the primitive type includes stroke primitives and fill primitives.
[0011] Furthermore, the stroke primitive includes two parameters: a path set and stroke information; the fill primitive includes two parameters: a path set and a path color; and the path coordinates of the primitive are stored in the path set parameters.
[0012] Furthermore, the graphic type of the OpenMap point symbol is consistent with the TrueType character, which is a filled type; for the filled primitive, the graphic is directly obtained; for the stroke primitive, the node coordinates of the stroke primitive need to be converted into the node coordinates corresponding to the filled primitive, and then the graphic is obtained.
[0013] Furthermore, the specific steps of converting the node coordinates of the stroke primitive into the node coordinates corresponding to the fill primitive are:
[0014] Calculate the center of gravity coordinates, inward contraction ratio and outward expansion ratio of the polygon according to the polygon node coordinate array parsed from the path set and the line width attribute in the stroke information;
[0015] Clear the cached coordinates of the original node coordinate array, write the calculated outer polygon coordinates into the node coordinate array in a clockwise direction, and write the inner polygon coordinates into the node coordinate array in a counterclockwise direction to obtain a new node coordinate array of the filled primitive type.
[0016] Furthermore, the scaling of the point symbol recalculates the center coordinates and the scaling ratio of the OpenMap point symbol after writing the TrueType character according to the TrueType character drawing range and the bounding box information of the OpenMap point symbol.
[0017] Furthermore, the TrueType character drawing range defaults to 1000px*1000px.
[0018] Furthermore, the creation of the character cache stream requires re-encoding the character elements, and the re-encoded elements are updated in the cache stream in sequence, in the order of HEAD, HHEA, MAXP, HMTX, CMAP, LOCA, GLYF, NAME, POST, GASP, and OS.
[0019] Furthermore, the creation of the font container is to create a font file through the Sfntly library, define metadata information of the font container, associate the character cache stream with the font file, and finally save the font file.
[0020] Furthermore, the metadata information of the font container includes the stream length, storage field, storage bit number and unique machine identification code of each character element.
[0021] The present invention has the following beneficial effects: the method disclosed in the present invention for writing an OpenMap dot symbol into a TrueType character realizes the conversion process of two different data in the form of a cache stream by re-parsing, transforming and encoding, and can write the OpenMap dot symbol into a TrueType character with high precision. The present invention is also applicable to the sharing operation of the data structure of other symbols, wherein the writing part into the TrueType character stream can be regarded as a repeatable and universal operation, which can ensure a relatively high sharing quality, and can directly process the attribute information and path coordinate information of the symbol at the underlying data structure level, thereby realizing mapping and conversion. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 It is a flow chart of a method for writing TrueType characters into OpenMap dot symbols of the present invention;
[0023] Figure 2 It is a schematic diagram of the data model of the OpenMap point symbol in the present invention;
[0024] Figure 3 It is a flow chart of reading and parsing OpenMap point symbols in the present invention;
[0025] Figure 4 It is a schematic diagram of the coordinate conversion of the stroke primitive nodes in the present invention;
[0026] Figure 5 It is a schematic diagram of all the components of writing dot symbol data into a TrueType character stream in the present invention.
[0027] Figure 6 It is a schematic diagram of the symbol conversion effect in the present invention. DETAILED DESCRIPTION
[0028] The present invention is further explained below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the following specific embodiments are only used to illustrate the present invention and are not used to limit the scope of the present invention. After reading the present invention, various equivalent forms of modifications to the present invention by those skilled in the art all fall within the scope defined by the claims attached to this application.
[0029] The flowchart of the method for writing a TrueType character into an OpenMap dot symbol disclosed in the present invention is as follows: Figure 1 As shown, the following steps are included:
[0030] Reading an OpenMap point symbol from a symbol library, and obtaining a graphic and basic information of the OpenMap point symbol; the basic information includes the number of contours, bounding box information, the number of coordinate points, and path coordinates of the OpenMap point symbol;
[0031] Constructing a dot symbol cache stream, scaling the dot symbol according to the drawing range of the TrueType character, defining the index position of the OpenMap dot symbol, and writing the index position and the basic information after scaling and updating into the dot symbol cache stream;
[0032] Creating a character cache stream according to the information stored in the dot symbol cache stream, and re-encoding the character elements in the character cache stream respectively; the character elements are a necessary table of character composition, including HHEA, MAXP, OS, HMTX, CMAP, LOCA, GLYF, NAME, and POST;
[0033] Create a font container and save the re-encoded character buffer stream into a complete font file.
[0034] Figure 2 The basic data model of OpenMap point symbols is shown. In this model structure, OpenMap point symbols are mainly composed of stroke primitives and fill primitives, both of which contain the basic path coordinate data of the symbol image. The path coordinate information of the point symbol is obtained by reading the OpenMap point map symbol library. Figure 3 The specific process of reading and parsing is shown.
[0035] In this embodiment, the implementation steps of the reading and parsing process are:
[0036] First, read the point symbols in the symbol library. Taking the .MSD format symbol library file as an example, the file can be deserialized through the C++ Serializable method to obtain the point symbols stored in the file.
[0037] Second, the type of each primitive in the dot symbol is determined accordingly. The primitive types include stroke primitives and fill primitives. Stroke primitives refer to primitives that use strokes to describe the strokes. This type contains two parameters: path set (m_PathList) and stroke information (m_LineStroke). Among them, m_PathList stores the position coordinate information of the current primitive, and m_LineStroke stores the specific parameters related to the current primitive and the stroke, including stroke category, width, vertical offset, color, style, end, texture address, and texture scaling ratio.
[0038] The stroke primitive needs to parse the coordinates of m_PathList according to the m_LineStroke parameter. The parsing process is assisted by the open source underlying rendering library AGG. The configuration attributes required by AGG are calculated through the maximum and minimum coordinates of the bounding box of the overall dot symbol. The bounding box refers to the minimum rectangular range containing the symbol. The configuration attributes include translation, scaling, rotation angle, etc. The node coordinates are obtained by traversing the is_stop function of AGG in sequence.
[0039] Filled primitives are closed primitives that are described by fill color and path. This type of primitive contains two parameters: path collection (m_PathList) and path color (m_PathColor). m_PathList stores the position coordinate information of the current primitive, and m_PathColor records the color of the current primitive. The path collection parsing process of the filled primitive is the same as that of the stroke primitive.
[0040] Third, since the stroke primitive only contains the line node coordinates of the graphics drawing, and what is drawn in the TrueType character is a filled type of graphics, it is necessary to convert the node coordinates of the stroke primitive into the node coordinates corresponding to the filled primitive.
[0041] Figure 4 The conversion process of converting the node coordinates of the stroke primitive into the node coordinates corresponding to the fill primitive is demonstrated. In this conversion process, the centroid method is used to solve the inner polygon and outer polygon of the polygon.
[0042] First, according to the polygon node coordinate array parsed from m_PathList and the line width attribute in the m_LineStroke parameter, the center of gravity coordinates, indentation ratio and expansion ratio of the polygon are calculated. The center of gravity coordinates are calculated according to the general polygon center of gravity formula. The indentation ratio refers to the ratio of the distance from the current node coordinates to the origin with the center of gravity coordinates as the origin to the distance minus half the stroke width. The stroke coordinates of each node after indentation can be calculated through this ratio; the expansion ratio refers to the ratio of the distance from the current node coordinates to the origin with the center of gravity coordinates as the origin to the distance plus half the stroke width. The stroke coordinates of each node after expansion can be calculated through this ratio.
[0043] The formula for the center of gravity coordinates is:
[0044]
[0045]
[0046] Where S represents the area of a single triangle that makes up the polygon, and T represents the sum of the horizontal / vertical coordinates of the triangle.
[0047] The shrink / expand ratio formula is:
[0048]
[0049] Where (x1, y1) and (x1, y1) represent the current node coordinates and the center of gravity coordinates respectively, and w represents the line width.
[0050] Then, clear the cached coordinates of the original node coordinate array, and update the original node coordinate array in sequence by following the principle of "outer first, inner second", that is, writing the node coordinates of the outer polygon in a clockwise direction, and writing the node coordinates of the inner polygon in a counterclockwise direction. Take the starting point coordinates of the outer polygon as an example, and write the node coordinate array in a clockwise relationship until the end point coordinates; at the end of the end point coordinates of the outer polygon, continue to add the end point coordinates of the inner polygon, and then write other node coordinates in a counterclockwise relationship until the starting point coordinates of the inner polygon.
[0051] After obtaining the node coordinate array, the dot symbol needs to be scaled according to the drawing range of the TrueType character (1000px*1000px), and converted into a binary value according to the corresponding index position and written into the dot symbol cache stream. The scaling process specifically includes: first, the dot symbol is translated to the center point of the drawing range. All dot symbols are centered at the coordinate origin (0px, 0px) by default, and now need to be translated to the center point of the drawing range (500px, 500px); secondly, the maximum and minimum values of the horizontal and vertical coordinates are obtained according to the coordinate array, and the bounding box of the current dot symbol is calculated. The bounding box refers to the minimum circumscribed rectangle of the symbol, and the length and width of the rectangle represent the length and width of the current dot symbol respectively; finally, the scaling ratio is calculated according to the length of the bounding box, and the formula is expressed as:
[0052] Ratio=max(w,h) / 1000
[0053] Ratio represents the scaling ratio, w and h represent the width and height of the bounding box of the original symbol, both in px.
[0054] Table 1 shows the storage information index of the dot symbol cache stream in this embodiment.
[0055]
[0056] Table 1
[0057] Figure 5 The basic components of TrueType characters are shown. Therefore, based on the dot symbol cache stream, each basic character element is updated in sequence according to the dot symbol information to be written, and a character cache stream for generating TrueType fonts is constructed. The index information of each character element in the character cache stream in this embodiment is shown in Table 2, and the update order is HEAD, HHEA, MAXP, HMTX, CMAP, LOCA, GLYF, NAME, POST, GASP, OS.
[0058]
[0059] Table 2
[0060] HEAD updates the minimum X-direction coordinate at index position 36-37; updates the minimum Y-direction coordinate at index position 38-39; updates the maximum X-direction coordinate at index position 40-41, and updates the maximum Y-direction coordinate at index position 42-43. Similarly, all index positions are the relative offset after updating the contour coordinate data plus the corresponding value. HHEA updates the maximum range information at index position 16-17. MAXP updates the maximum number of contour coordinate nodes at index position 6-7; updates the maximum number of contours at index position 8-9. HMTX updates the font index information at index position 12-13; LOCA updates the length of the dot symbol cache stream at the offset position; GLYF directly inserts the dot symbol cache stream data prepared above at the index start position; NAME updates the length of GLYF after the update for offset; POST updates the position after the update of NAME for offset; GASP offsets according to the position after the update of NAME.
[0061] The MAXP part contains the number of characters, the number of contours, and the number of coordinate points of the TrueType character; to re-encode it, first obtain the index and length of MAXP in the character cache stream, and update the corresponding information of MAXP at the index position according to the number of dot symbols, the number of contours, and the number of coordinate points written.
[0062] The OS part contains the maximum character index of the TrueType character; to re-encode it, the index and length of the OS in the character buffer stream are first obtained, and the corresponding information of the OS is updated at the index position according to the number of dot symbols written.
[0063] The HMTX part contains the horizontal index of the TrueType character; to re-encode it, first obtain the index and length of HMTX in the character buffer stream, and update the corresponding information of HMTX at the index position according to the bounding box range of the written dot symbol.
[0064] The CMAP part contains the actual index of the TrueType character, that is, the minimum and maximum values of the TrueType character contour in the X direction; to re-encode it, first obtain the index and length of CMAP in the character cache stream, and update the corresponding information of CMAP at the index position according to the bounding box range of the written dot symbol.
[0065] The LOCA part contains the positions of all contours in the TrueType character in the character cache stream; to re-encode it, first obtain the index and length of LOCA in the character cache stream, and update the corresponding information of LOCA at the index position according to the contour coordinate length of the written dot symbol.
[0066] The GLYF section contains the actual coordinates of all the outlines in a TrueType character, and all characters are assembled based on these coordinates; for its re-encoding, first obtain the index and length of the GLYF in the character cache stream, and update the corresponding information of the GLYF at the index position according to the outline coordinate length of the written dot symbol.
[0067] The NAME section contains the symbol names of TrueType characters; for its re-encoding, first obtain the index and length of the NAME in the character cache stream, and update the corresponding information of the NAME at the index position.
[0068] The POST section contains the pre-printing information of TrueType characters; for its re-encoding, first obtain the index of the NAME in the character cache stream, calculate the increment of the index after all the above changes, and update the corresponding information of the POST.
[0069] Rewrite the index values in the corresponding table 2 according to the offset positions and lengths updated by all the above elements; finally, update the check value in the OS section. After writing all the dot symbol information, update the metadata information, where the stream length is the difference between the initial byte stream length and the byte stream length after writing the symbol information; the storage fields refer to all the above storage elements and their specific positions in the byte stream; the storage bit number represents the number of bits occupied by a single piece of information, with a default value of 2; the unique machine identification code is generated by the Windows system and is used to record the font creation source. Thus, the complete process of writing OpenMap dot symbols into TrueType characters ends.
[0070] Create a font file through the Sfntly library, associate the above character cache stream with the font file, and finally save the font file to export and complete the creation of the font file. As Figure 6 shown in the figure is a schematic diagram of the effect after an OpenMap dot symbol "pavilion" is written into a TrueType character according to the process introduced above.
[0071] In the figure, the "pavilion" symbol is written into the TrueType character file in sequence according to the outlines of the component symbols. On the left side of the figure is the pavilion symbol in the OpenMap symbol library, which consists of 43 sub-graphic elements. These 43 sub-graphic elements are all filled graphic elements. By sequentially obtaining the node coordinate arrays of all the graphic elements and writing the 43 node coordinate arrays into the TrueType byte stream in sequence according to the stored index relationship table, and finally saving the byte stream to a local file. As Figure 6 shown on the right side, after installing the local file, the effects of each graphic element in TrueType can be previewed in the computer font library.
Claims
1. A method for writing OpenMap dot symbols into TrueType characters, characterized in that: The steps include: Reading an OpenMap point symbol from a symbol library, and obtaining a graphic and basic information of the OpenMap point symbol; the basic information includes the number of contours, bounding box information, the number of coordinate points, and path coordinates of the OpenMap point symbol; Constructing a dot symbol cache stream, scaling the dot symbol according to the drawing range of the TrueType character, defining the index position of the OpenMap dot symbol, and writing the index position and the basic information after scaling and updating into the dot symbol cache stream; Creating a character cache stream according to the information stored in the dot symbol cache stream, and re-encoding the character elements in the character cache stream respectively; the character elements are a necessary table of character composition, including HHEA, MAXP, OS, HMTX, CMAP, LOCA, GLYF, NAME, and POST; Create a font container and save the re-encoded character buffer stream into a complete font file.
2. The writing method according to claim 1, characterized in that: The process of reading OpenMap point symbols is to first deserialize the symbol library file to obtain the point symbols stored in the file, and then determine the type of each primitive in the point symbol in turn, and the primitive type includes stroke primitives and fill primitives.
3. The writing method according to claim 2, characterized in that: The stroke primitive includes two parameters: path set and stroke information; the fill primitive includes two parameters: path set and path color; the path set parameters store the path coordinates of the primitive.
4. The writing method according to claim 3, characterized in that: The graphic type of the OpenMap dot symbol is consistent with the TrueType character, which is a fill type; for the fill primitive, the graphic is directly obtained; For the stroke primitive, it is necessary to convert the node coordinates of the stroke primitive into the node coordinates corresponding to the fill primitive, and then obtain the graph.
5. The writing method according to claim 4, characterized in that: The specific steps of converting the node coordinates of the stroke primitive into the node coordinates corresponding to the fill primitive are: Calculate the center of gravity coordinates, inward contraction ratio and outward expansion ratio of the polygon according to the polygon node coordinate array parsed from the path set and the line width attribute in the stroke information; Clear the cached coordinates of the original node coordinate array, write the calculated outer polygon coordinates into the node coordinate array in a clockwise direction, and write the inner polygon coordinates into the node coordinate array in a counterclockwise direction to obtain a new node coordinate array of the filled primitive type.
6. The writing method according to claim 1, characterized in that: The scaling of the dot symbol recalculates the center coordinates and the scaling ratio of the OpenMap dot symbol after writing the TrueType character according to the TrueType character drawing range and the bounding box information of the OpenMap dot symbol.
7. The writing method according to claim 1, characterized in that: The TrueType character drawing range defaults to 1000*1000.
8. The writing method according to claim 1, characterized in that: The creation of the character cache stream requires re-encoding the character elements, and the re-encoded elements are updated in the cache stream in sequence, in the order of HEAD, HHEA, MAXP, HMTX, CMAP, LOCA, GLYF, NAME, POST, GASP, and OS.
9. The writing method according to claim 1, characterized in that: The creation of the font container is to create a font file through the Sfntly library, define metadata information of the font container, associate the character cache stream with the font file, and finally save the font file.
10. The writing method according to claim 1, characterized in that: The metadata information of the font container includes the stream length, storage field, storage bit number and unique machine identification code of each character element.