Font file processing method, computer equipment, computer readable storage medium and computer program product
By subsetting the font file on the browser side, removing whitespace and duplicate characters, and generating a target font file containing glyph information of the target text characters, the problem of slow rendering speed caused by large font file size is solved, and faster character rendering is achieved.
Patent Information
- Application Number
- CN202411168519.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-23
- Publication Date
- 2024-11-22
AI Technical Summary
Large font file sizes result in slower character rendering speeds in browsers.
The original text is preprocessed using a browser-based font subsettization tool to remove whitespace and duplicate characters. The target font file is then read and created, containing the glyph information of each character in the target text.
The size of font files has been reduced, and character rendering speed has been improved.
Smart Images

Figure CN119005122A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a font file processing method, apparatus, computer equipment, computer-readable storage medium, and computer program product. Background Art
[0002] Font files are files used to define the appearance and typographical style of characters. A font file contains the shape, spacing, thickness and other information defined by the font designer for each character in the font. Browsers usually render characters by loading and parsing font files to display them.
[0003] However, since a font file contains relevant information of all characters under a corresponding font, the file size of the font file is usually large, which causes a slow rendering speed of the browser for the characters. Summary of the invention
[0004] Based on this, it is necessary to provide a font file processing method, computer device, computer readable storage medium and computer program product that can improve the rendering speed of characters in order to address the above-mentioned technical problem of slow rendering speed of characters.
[0005] In a first aspect, the present application provides a font file processing method, comprising:
[0006] Obtaining, through a browser, an original text to be rendered and an original font file used to render the original text;
[0007] Invoking a font subsetting tool constructed for the browser in the browser, performing font subsetting processing on the original font file according to the original text, and obtaining a target font file of the original text under the font corresponding to the original font file; specifically comprising:
[0008] Preprocessing the original text to obtain a target text that does not contain blank characters and repeated characters;
[0009] Reading the glyph information of each text character in the target text from the original font file; the glyph information of each text character at least includes the glyph data of each text character and the horizontal layout parameters of each text character;
[0010] Based on the glyph information of each text character, a target font file of the original text in the font corresponding to the original font file is created.
[0011] In one of the embodiments, the original font file at least includes an original mapping relationship table, an original glyph data table, and an original horizontal layout table, wherein the original mapping relationship table is used to record the mapping relationship between each font character under the font corresponding to the original font file and the glyph identifier of each font character, and the mapping relationship between each font character and the original storage address of the glyph data of each font character in the original glyph data table;
[0012] The step of reading the font information of each text character in the target text from the original font file includes:
[0013] Based on the original mapping relationship table, determining the glyph identifier of each text character and the original storage address corresponding to each text character;
[0014] According to the original storage address corresponding to each text character, the glyph data corresponding to each text character is read from the original glyph data table, and, according to the glyph identifier of each text character, the horizontal layout parameters corresponding to each text character are read from the original horizontal layout table.
[0015] In one embodiment, the original mapping relationship table includes a first original mapping relationship table and a second original mapping relationship table; the first original mapping relationship table is used to record the mapping relationship between the character encoding of each font character and the glyph identifier of each font character, and the second original mapping relationship table is used to record the mapping relationship between the glyph identifier of each font character and the original storage address of each font character;
[0016] The determining, based on the original mapping relationship table, the glyph identifier of each text character and the original storage address corresponding to each text character comprises:
[0017] Determining the character encoding of each text character in the target text;
[0018] According to the character codes of the text characters, searching the first original mapping relationship table to obtain the glyph identifiers of the text characters;
[0019] According to the glyph identifiers of the text characters, the second original mapping table is searched to obtain the original storage addresses corresponding to the text characters.
[0020] In one of the embodiments, the glyph information of each text character at least includes a glyph identifier of each text character;
[0021] The step of creating a target font file for the original text in a font corresponding to the original font file based on the glyph information of each text character comprises:
[0022] Based on the glyph information of each text character, creating a target glyph data table, a target horizontal layout table and a target mapping relationship table corresponding to the target text;
[0023] Creating a target font file for the original text in the font corresponding to the original font file based on the target glyph data table, the target horizontal layout table and the target mapping relationship table;
[0024] Among them, the target mapping relationship table is used to record the mapping relationship between each text character and the glyph identifier of each text character, and the mapping relationship between each text character and the target storage address of the glyph data of each text character in the target glyph data table; the target glyph data table corresponds to the target storage address of each text character; the target horizontal layout table corresponds to the glyph identifier of each text character.
[0025] In one embodiment, the step of creating a target glyph data table, a target horizontal layout table, and a target mapping relationship table corresponding to the target text based on the glyph information of each text character includes:
[0026] Creating the target glyph data table based on the glyph data of each text character;
[0027] Determine, based on the number of the text characters, the array length of the array used to record the horizontal layout parameters of the text characters, and create the target horizontal layout table according to the glyph identifiers of the text characters, the horizontal layout parameters of the text characters, and the array length;
[0028] The target mapping relationship table is created based on the mapping relationship between the text characters and the glyph identifiers of the text characters, and the mapping relationship between the text characters and the target storage addresses of the text characters.
[0029] In one embodiment, the creating a target font file of the original text in the font corresponding to the original font file based on the target glyph data table, the target horizontal layout table and the target mapping relationship table includes:
[0030] Determine an address type parameter based on the data type of the target storage address of each text character in the target mapping relationship table, and determine a glyph quantity parameter based on the quantity of each text character;
[0031] The target font data table, the target horizontal layout table, the target mapping relationship table, the address type parameter and the glyph quantity parameter are combined to obtain the target font file of the original text in the font corresponding to the target font file.
[0032] In one embodiment, the step of reading the font information of each text character in the target text from the original font file includes:
[0033] Determining the character encoding of each text character in the target text;
[0034] sorting the character codes of the text characters;
[0035] The character codes are traversed in the sorting order of the character codes, and the glyph information of the text characters corresponding to the traversed character codes is read from the original font file.
[0036] In one embodiment, after obtaining the target font file of the original text in the font corresponding to the original font file, the method further includes:
[0037] The target font file is loaded through the browser, and each character in the original text is rendered based on the target font file to obtain a target character of each character in the original text in the target font;
[0038] The browser displays each target character to display the original text.
[0039] In a second aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0040] Obtaining, through a browser, an original text to be rendered and an original font file used to render the original text;
[0041] Invoking a font subsetting tool constructed for the browser in the browser, performing font subsetting processing on the original font file according to the original text, and obtaining a target font file of the original text under the font corresponding to the original font file; specifically comprising:
[0042] Preprocessing the original text to obtain a target text that does not contain blank characters and repeated characters;
[0043] Reading the glyph information of each text character in the target text from the original font file; the glyph information of each text character at least includes the glyph data of each text character and the horizontal layout parameters of each text character;
[0044] Based on the glyph information of each text character, a target font file of the original text in the font corresponding to the original font file is created.
[0045] In a third aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented:
[0046] Obtaining, through a browser, an original text to be rendered and an original font file used to render the original text;
[0047] Invoking a font subsetting tool constructed for the browser in the browser, performing font subsetting processing on the original font file according to the original text, and obtaining a target font file of the original text under the font corresponding to the original font file; specifically comprising:
[0048] Preprocessing the original text to obtain a target text that does not contain blank characters and repeated characters;
[0049] Reading the glyph information of each text character in the target text from the original font file; the glyph information of each text character at least includes the glyph data of each text character and the horizontal layout parameters of each text character;
[0050] Based on the glyph information of each text character, a target font file of the original text in the font corresponding to the original font file is created.
[0051] In a fourth aspect, the present application further provides a computer program product, including a computer program, which implements the following steps when executed by a processor:
[0052] Obtaining, through a browser, an original text to be rendered and an original font file used to render the original text;
[0053] Invoking a font subsetting tool constructed for the browser in the browser, performing font subsetting processing on the original font file according to the original text, and obtaining a target font file of the original text under the font corresponding to the original font file; specifically comprising:
[0054] Preprocessing the original text to obtain a target text that does not contain blank characters and repeated characters;
[0055] Reading the glyph information of each text character in the target text from the original font file; the glyph information of each text character at least includes the glyph data of each text character and the horizontal layout parameters of each text character;
[0056] Based on the glyph information of each text character, a target font file of the original text in the font corresponding to the original font file is created.
[0057] The above-mentioned font file processing method, computer device, computer-readable storage medium and computer program product first obtain the original text to be rendered and the original font file used to render the original text through the browser; then call the font subsetting tool built for the browser in the browser, perform font subsetting processing on the original font file according to the original text, and obtain the target font file of the original text under the font corresponding to the original font file; specifically include: preprocessing the original text to obtain the target text that does not contain blank characters and repeated characters; reading the glyph information of each text character in the target text from the original font file; the glyph information of each text character at least includes the glyph data of each text character and the horizontal layout parameters of each text character; based on the glyph information of each text character, create the target font file of the original text under the font corresponding to the original font file. In this way, by preprocessing the original text, a target text that does not contain blank characters and repeated characters can be obtained. By reading the glyph data and horizontal layout parameters corresponding to each text character in the target text from the original text file, a target font file of the original text in the font corresponding to the original font file can be created. Since the glyph information contained in the target font file only involves each text character in the target text, that is, the non-blank and non-repeated characters in the original text, the file size of the target font file is reduced compared to the original font file, and the rendering speed of the original text can be accelerated based on the target font file. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions 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 related drawings can be obtained based on these drawings without paying creative work.
[0059] FIG1 is a schematic flow chart of a method for processing file fonts in one embodiment;
[0060] FIG2 is a flowchart of steps of performing font subset processing on an original font file according to an original text to obtain a target font file of the original text in a font corresponding to the original font file in one embodiment;
[0061] FIG3 is a flow chart of the steps of reading the glyph information of each text character in the target text from the original font file in one embodiment;
[0062] FIG4 is a flow chart of the steps of determining the glyph identifier of each text character and the original storage address corresponding to each text character based on the original mapping relationship table in one embodiment;
[0063] FIG5 is a flowchart of steps for creating a target font file of an original text in a font corresponding to an original font file based on the glyph information of each text character in one embodiment;
[0064] 6 is a flowchart of steps for creating a target font data table, a target horizontal layout table, and a target mapping relationship table corresponding to a target text based on font information of each text character in one embodiment;
[0065] FIG7 is a flow chart of a method for processing file fonts in another embodiment;
[0066] FIG8 is a flow chart of a font subsetting method based on a font subsetting library for a browser in one embodiment;
[0067] FIG9 is a schematic diagram of the association relationship between various tables in a font file in one embodiment;
[0068] FIG10 is a flow chart of a font subsetting method based on a font subsetting library for a browser in another embodiment;
[0069] FIG11 is a structural block diagram of a file font processing device in one embodiment;
[0070] FIG. 12 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0071] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0072] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0073] In one embodiment, as shown in FIG1 , a method for processing file fonts is provided. This embodiment uses the method applied to a terminal as an example for illustration. It is understandable that the method can also be applied to a server, and can also be applied to a system including a terminal and a server, and is implemented through the interaction between the terminal and the server; wherein the terminal can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, etc., and the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services. In this embodiment, the method includes the following steps:
[0074] Step S102: obtaining, through a browser, the original text to be rendered and the original font file used for rendering the original text.
[0075] The browser is a browser running on a terminal. If the method is applied to a server, the server is a background server running the browser.
[0076] The original text is the text to be rendered uploaded by the user through the browser running on the terminal.
[0077] The original font file is a font file uploaded by the user through a browser running on the terminal and used to render the original text.
[0078] In a specific application, the original font file is a complete font file of a corresponding font, and the complete font file includes information such as the shape, size, spacing, thickness, etc. of each character in the corresponding font.
[0079] Specifically, the user uploads the original file to be rendered and the original font file used to render the original file through the browser running on the terminal; the terminal receives the original file and the original font file through the browser.
[0080] Step S104, calling a font subsetting tool constructed for the browser in the browser, performing font subsetting processing on the original font file according to the original text, and obtaining a target font file of the original text under the font corresponding to the original font file.
[0081] Among them, font subsetting tools refer to applications or program products that can perform font subsetting on font files; font subsetting tools built for browsers refer to font subsetting tools developed for browsers and using browsers as their operating environment.
[0082] Among them, font subsetting refers to the process of extracting font files corresponding to some characters from a font file; since the extracted font files are only for some characters rather than all characters under the corresponding font, font subsetting can reduce the file size of the font file.
[0083] In practical applications, on the one hand, since the operating environment of the font subsetting tool provided by the present application is a browser, that is, the font subsetting tool needs to be called by the browser, on the other hand, the format of the font file is usually a binary format; therefore, the compilation file of the font subsetting tool provided by the present application selects a first compilation file, wherein the first file is a binary instruction format file called by a first programming language that can be used for web pages and website construction, and the source code of the font subsetting tool provided by the present application selects a second programming language, wherein the second programming language is a programming language that can be compiled into the above-mentioned first compilation file.
[0084] Furthermore, since browsers usually use JavaScript to build web pages and websites, the compilation file of the font subsetting tool is a binary instruction format file that can be called by JavaScript, such as WebAssembly, and the programming language of the source code of the font subsetting tool is a programming language that can be compiled into WebAssembly, such as C, C++, and Rust.
[0085] Specifically, the terminal calls a font subsetting tool in a browser, performs font subsetting on the original font file according to the original text, and extracts a target font file from the original font file that only contains relevant information corresponding to each character in the original font file, so as to reduce the file size of the font file used to render the original text.
[0086] It is easy to understand that the target font file only contains part of the information in the original font file compared to the original font file. Therefore, if the browser renders the original text based on the target font file, the rendering speed of the characters can be improved.
[0087] In this embodiment, as shown in FIG. 2 , the above step S104 performs font subset processing on the original font file according to the original text to obtain a target font file of the original text under the font corresponding to the original font file, specifically including the following steps:
[0088] Step S202, preprocessing the original text to obtain a target text that does not contain blank characters and repeated characters.
[0089] Specifically, the terminal uses a font subsetting tool to perform preprocessing of removing blank characters and preprocessing of removing repeated characters on the original text, thereby obtaining a target text that does not contain blank characters and repeated characters.
[0090] Step S204: reading the font information of each text character in the target text from the original font file.
[0091] The glyph information of each text character represents the shape, spacing, thickness and other information of each text character; the glyph information of each text character at least includes the glyph data of each text character and the horizontal layout parameters of each text character.
[0092] The glyph data refers to the glyph vector data of the character, that is, the vector outline data of the glyph of the character, which defines the geometric shape and structure of the character.
[0093] The horizontal layout parameters include at least the upper height, lower height, line spacing, maximum advance width, minimum left support, minimum right support and other parameters of the character shape, which define the spacing and thickness of the characters.
[0094] In a specific application, the glyph information further includes information such as the character identifier of the character in the font file.
[0095] Specifically, the terminal uses a font subsetting tool to find and read out the glyph information corresponding to each text character in the target text from the original font file.
[0096] Step S206: Create a target font file for the original text under the font corresponding to the original font file based on the glyph information of each text character.
[0097] Specifically, the terminal uses a font subsetting tool to create a target font file for the original text under the font corresponding to the original font file based on the read glyph information of each text character, so as to render the original text based on the target font file and render each character in the original text as the font corresponding to the original font file.
[0098] It should be noted that there are currently some font subsetting tools, such as Fontmin, which can also achieve font subsetting. However, first, its running environment is the corresponding server. Therefore, if there are a large number of user requests for font subsetting, the pressure on the server will increase, thus affecting the performance of the server in font subsetting. Second, since its running environment is the server, it is also necessary to return the font file after font subsetting to the user, which may increase network latency and further affect the performance of the server in font subsetting. Third, Fontmin does not have the ability to deduplicate characters. Suppose the text to be rendered is "你好好" (Ni Hao Hao), then Fontmin will index the character "好" (Hao) twice in the font file. Fourth, Fontmin cannot directly read and operate on binary data and needs to be converted before reading and operating, so there will be performance loss.
[0099] However, the font subsetting tool provided by the present application, compared with Fontmin, first, the font subsetting tool provided by the present application runs on the browser. Therefore, users can directly achieve font subsetting on the browser, without network latency and server pressure. Second, the font subsetting tool provided by the present application has the ability to deduplicate characters, so unnecessary indexing steps are avoided, the performance is better, and the speed of font subsetting is faster. Third, the font subsetting tool provided by the present application can directly read and operate on binary data without performance loss, further improving the speed of font subsetting.
[0100] In the above-mentioned font file processing method, the terminal first obtains the original text to be rendered and the original font file used to render the original text through the browser; then, the terminal calls the font subsetting tool built for the browser in the browser, and performs font subsetting processing on the original font file according to the original text, so as to obtain the target font file of the original text under the font corresponding to the original font file; specifically, it includes: the terminal pre-processes the original text based on the font subsetting tool to obtain the target text that does not contain blank characters and repeated characters; the terminal reads the glyph information of each text character in the target text from the original font file based on the font subsetting tool; the glyph information of each text character at least includes the glyph data of each text character and the horizontal layout parameters of each text character; the terminal creates the target font file of the original text under the font corresponding to the original font file based on the glyph information of each text character based on the font subsetting tool. In this way, by preprocessing the original text, the terminal can obtain a target text that does not contain blank characters and repeated characters. By reading the glyph data and horizontal layout parameters corresponding to each text character in the target text from the original text file, the terminal can create a target font file for the original text in the font corresponding to the original font file. Since the glyph information contained in the target font file only involves each text character in the target text, that is, the non-blank and non-repeated characters in the original text, the file size of the target font file is reduced compared to the original font file, and the rendering speed of the original text can be accelerated based on the target font file.
[0101] In an exemplary embodiment, the original font file at least includes an original mapping relationship table, an original glyph data table, and an original horizontal layout table.
[0102] Among them, the original mapping relationship table is used to record the mapping relationship between each font character under the font corresponding to the original font file and the glyph identifier of each font character, and the mapping relationship between each font character and the original storage address of the glyph data of each font character in the original glyph data table.
[0103] The original font data table is used to record the font data of each font character.
[0104] The original horizontal layout table is used to record the horizontal layout parameters of each font character.
[0105] The glyph identifier is a unique identifier of the glyph of a character in a font file.
[0106] The original storage address is the storage address of the font data of the font character in the original font data table.
[0107] As shown in FIG. 3 , the above step S204, reading the font information of each text character in the target text from the original font file, specifically includes the following steps:
[0108] Step S302: determining the glyph identifier of each text character and the original storage address corresponding to each text character based on the original mapping relationship table.
[0109] Step S304, reading the glyph data corresponding to each text character from the original glyph data table according to the original storage address corresponding to each text character, and reading the horizontal layout parameters corresponding to each text character from the original horizontal layout table according to the glyph identifier of each text character.
[0110] Specifically, the terminal uses the font subsetting tool to first search for the mapping relationship between each font character recorded in the original mapping relationship table and the glyph identifier of each font character to obtain the glyph identifier of each text character, and to search for the mapping relationship between each font character recorded in the original mapping relationship table and the original storage address of the glyph data of each font character to obtain the original storage address corresponding to each text character. Then, based on the obtained original storage address corresponding to each text character, the glyph data corresponding to the original storage address corresponding to each text character in the original glyph data table is searched and read as the glyph data of each text character, and based on the obtained character identifier of each text character, the horizontal layout parameters corresponding to the character identifier of each text character in the original horizontal layout table are searched and read as the horizontal layout parameters of each text character.
[0111] This embodiment is described by taking the font corresponding to the original font file as TrueType as an example. The original font file of TrueType includes a glyf table recording the glyph data of all font characters under TrueType, and an htmx table recording the horizontal layout parameters of all font characters under TrueType, that is, the original glyph data table is the glyf table, and the original horizontal layout table is the htmx table. Therefore, the font subset tool determines the glyph identifier and the corresponding original storage address of each text character according to the original target mapping table, and reads the glyph data corresponding to the original storage address corresponding to each text character from the glyf table as the glyph data of each text character, and reads the horizontal layout parameters corresponding to the glyph identifier of each text character from the htmx table as the horizontal layout parameters of each text character.
[0112] In this embodiment, the terminal can determine the glyph identifier of each text character and the original storage address corresponding to the glyph data of each text character in the original glyph data table based on the original mapping relationship table, so that the glyph data of each text character can be read from the original glyph data table based on the original storage address corresponding to each text character, and the horizontal layout parameters of each text character can be read from the original horizontal layout table based on the glyph identifier of each text character, thereby obtaining the glyph information representing the shape, spacing, thickness and other information of each text character.
[0113] In an exemplary embodiment, the original mapping relationship table includes a first original mapping relationship table and a second original mapping relationship table.
[0114] The first original mapping relationship table is used to record the mapping relationship between the character code of each font character and the glyph identifier of each font character, and the second original mapping relationship table is used to record the mapping relationship between the glyph identifier of each font character and the original storage address of each font character.
[0115] Among them, character encoding is the identification code corresponding to characters in the computer field; in specific applications, character encoding is Unicode encoding represented by Unicode array.
[0116] As shown in FIG. 4 , the above step S302, based on the original mapping relationship table, determines the glyph identifier of each text character and the original storage address corresponding to each text character, specifically includes the following steps:
[0117] Step S402, determining the character code of each text character in the target text.
[0118] Step S404: search the first original mapping table according to the character code of each text character to obtain the glyph identifier of each text character.
[0119] Step S406: search the second original mapping table according to the glyph identifier of each text character to obtain the original storage address corresponding to each text character.
[0120] Specifically, the terminal uses a font subsetting tool to first convert each text character into a corresponding character encoding, such as a Unicode encoding; then, based on the character encoding of each text character, search for a first original mapping relationship table that records the mapping relationship between the character encoding of each font character and the glyph identifier of each font character, and obtain the glyph identifier corresponding to the character encoding of each text character in the first original mapping relationship table as the glyph identifier of each text character; then, based on the glyph identifier of each text character, search for a second original mapping relationship table that records the mapping relationship between the glyph identifier of each font character and the original storage address of each font character, and obtain the original storage address corresponding to the glyph identifier of each text character in the second original mapping relationship table as the original storage address corresponding to each text character.
[0121] The present embodiment is described by taking the font corresponding to the original font file as TrueType as an example. The original font file of TrueType includes a cmap table recording the mapping relationship between the character encoding Unicode encoding and the glyfID of all font characters under TrueType, and a loca table recording the mapping relationship between the glyfID of all font characters and the original storage address, that is, the first original mapping relationship table is the cmap table, and the second original mapping relationship table is the loca table. Therefore, the font subsetting tool reads the glyfID corresponding to the character encoding Unicode encoding of each text character from the cmap table according to the character encoding Unicode encoding of each text character as the glyfID of each text character, and then reads the original storage address corresponding to the glyfID of each text character from the loca table as the original storage address corresponding to each text character.
[0122] In this embodiment, the terminal can determine the glyph identifier of each text character based on the first original mapping relationship table, and can determine the original storage address corresponding to the glyph data of each text character in the original glyph data table based on the second original mapping relationship table, thereby facilitating the subsequent acquisition of the glyph information of each text character from the original glyph data table and the original horizontal layout table.
[0123] In an exemplary embodiment, the glyph information of each text character at least further includes the glyph identifier of each text character.
[0124] As shown in FIG. 5 , the above step S206, based on the glyph information of each text character, creates a target font file of the original text in the font corresponding to the original font file, specifically including the following steps:
[0125] Step S502: based on the glyph information of each text character, create a target glyph data table, a target horizontal layout table and a target mapping relationship table corresponding to the target text.
[0126] Step S504: creating a target font file of the original text in the font corresponding to the original font file based on the target glyph data table, the target horizontal layout table and the target mapping relationship table.
[0127] The target mapping relationship table is used to record the mapping relationship between each text character and the glyph identifier of each text character, and the mapping relationship between each text character and the target storage address of the glyph data of each text character in the target glyph data table.
[0128] The target storage address is the storage address of the font data of the font character in the target font data table.
[0129] Among them, the target glyph data table corresponds to the target storage address of each text character; it is easy to understand that since the target storage address is the storage address of the glyph data of the font character in the target glyph data table, the target glyph data table corresponds to the target storage address of each text character, specifically referring to that the glyph data of each text character is stored in the target glyph data table according to the target storage address of each text character.
[0130] The target horizontal layout table corresponds to the glyph identifier of each text character, specifically, the horizontal layout parameters of each text character are stored in the target horizontal layout table based on the glyph identifier of each text character.
[0131] Specifically, the terminal uses a font subsetting tool to first create a target glyph data table and a target horizontal layout table corresponding to the target text based on the glyph information of each text character read from the original font file, and then create a target mapping relationship table based on the target storage address of the glyph data of each text character in the target glyph data table and the glyph identifier of each text character; then, based on the newly created target glyph data table, target horizontal layout table and target mapping relationship table, further create a target font file for the original text in the font corresponding to the original font file.
[0132] This embodiment is explained by taking the font corresponding to the original font file as TrueType as an example. The font subsetting tool creates a new glyf table based on the glyph data of each text character extracted from the original TrueType font file, creates a new htmx table based on the horizontal layout parameters of each text character extracted from the original font file, and then creates a new cmap table and a new loca table based on the glyph identifier of each text character extracted from the original font file and the target storage address of the glyph data of each text character in the new glyf table.
[0133] In this embodiment, the terminal can create a target font file that only targets each non-blank and non-repeating character (i.e., each text character) in the original text based on the glyph information read from the original font file; compared with the original font file, the target font file contains only a part of the information in the original font file, so the file size is reduced, thereby speeding up the rendering speed of the original text.
[0134] In an exemplary embodiment, as shown in FIG. 6 , the above step S502, based on the glyph information of each text character, creates a target glyph data table, a target horizontal layout table and a target mapping relationship table corresponding to the target text, specifically including the following steps:
[0135] Step S602: Create a target glyph data table based on the glyph data of each text character.
[0136] Step S604, based on the number of each text character, determine the array length of the array used to record the horizontal layout parameters of each text character, and create a target horizontal layout table according to the glyph identifier of each text character, the horizontal layout parameters of each text character and the array length.
[0137] Step S606: Create a target mapping relationship table based on the mapping relationship between each text character and the glyph identifier of each text character, and the mapping relationship between each text character and the target storage address of each text character.
[0138] The horizontal layout parameters are stored in the target horizontal layout table in the form of an array.
[0139] Among them, the target mapping relationship table includes a first target mapping relationship table for recording the mapping relationship between each text character and the glyph identifier of each text character, and a second target mapping relationship table for recording the mapping relationship between the glyph identifier of each text character and the target storage address of each text character.
[0140] Specifically, the terminal uses a font subsetting tool to first create a new table for storing glyph data of each text character, thereby obtaining a target glyph data table, and, based on the number of each text character, determine the array length of an array for recording horizontal layout parameters of each text character, and create a new array according to the array length, and then use the glyph identifier of each text character as the corresponding array element identifier and the horizontal layout parameter of each text character as the corresponding array element value to store the horizontal layout parameter of each text character in the array, and store the array in a new table, thereby obtaining a target horizontal layout table; then, create a new table for recording the mapping relationship between each text character and the glyph identifier of each text character, thereby obtaining a first target mapping relationship table, and create a new table for recording the mapping relationship between the glyph identifier of each text character and the target storage address of each text character, thereby obtaining a second target mapping relationship table.
[0141] The length of the array is the number of characters in each text plus 1.
[0142] This embodiment is explained by taking the font corresponding to the original font file as TrueType as an example. The font subsetting tool creates a new glyf table based on the glyph data of each text character extracted from the original TrueType font file, creates a new htmx table based on the horizontal layout parameters of each text character extracted from the original font file, and then creates a new cmap table based on the mapping relationship between each text character and the glyph identifier of each text character extracted from the original font file, and creates a new loca table based on the mapping relationship between the glyph identifier of each text character extracted from the original font file and the target storage address of the glyph data of each text character in the new glyf table.
[0143] In a specific application, the font subsetting tool can also create a new array length parameter table for recording the array length, and create a target horizontal layout table according to the glyph identifier of each text character, the horizontal layout parameter of each text character and the array length parameter table.
[0144] In practical applications, the creation of the array length parameter table is achieved by copying; specifically, the original font file includes an original array length parameter table, in which the original array length corresponding to the original horizontal layout parameter table is recorded. The font subsetting tool can also copy the original array length parameter table, and update the original array length recorded in the original array length parameter table to an array length determined based on the number of each text character, thereby obtaining a target array length parameter table.
[0145] Take the case where the font corresponding to the original font file is TrueType as an example. The original TrueType font file also includes a horizontal title data table hhea, which records the parameter numOfLongHorMetrics representing the array length, that is, the hhea table is an array length parameter table. The font subsetting tool copies the hhea table in the original font file to obtain a new hhea table, and based on the array length determined by the number of each text character, updates the numOfLongHorMetrics parameter in the new hhea table, and then creates a new htmx table based on the glyph identifier of each text character, the horizontal layout parameter of each text character, and the numOfLongHorMetrics parameter in the new hhea table.
[0146] In this embodiment, the terminal can create a target glyph data table, a target horizontal layout parameter table and a target mapping relationship table only for each non-blank and non-repeated character (i.e., each text character) in the original text based on the glyph data, horizontal layout parameters and glyph identifier of each text character read from the original font file; the target glyph data table, the target horizontal layout parameter table and the target mapping relationship table contain only a part of the information in the original font file, compared with the corresponding original glyph data table, original horizontal layout parameter table and original mapping relationship table in the original font file, so the file size is reduced, thereby speeding up the rendering speed of the original text.
[0147] In an exemplary embodiment, the above step S504 creates a target font file for the original text in the font corresponding to the original font file based on the target glyph data table, the target horizontal layout table and the target mapping relationship table, and specifically includes the following contents: determining an address type parameter based on the data type of the target storage address of each text character in the target mapping relationship table, and determining a glyph quantity parameter based on the number of each text character; combining the target glyph data table, the target horizontal layout table, the target mapping relationship table, the address type parameter and the glyph quantity parameter to obtain the target font file for the original text in the font corresponding to the target font file.
[0148] The data type of the target storage address is used to characterize the data format of the target storage address; in a specific application, the data type includes a long integer type (long) and a short integer type (short).
[0149] The address type parameter includes a first address type parameter corresponding to a long integer and a second address type parameter corresponding to a short integer.
[0150] The glyph number parameter is the number of glyphs of each text character, that is, the number of each text character, and is used to represent the memory occupied by the target font file.
[0151] Specifically, the terminal uses a font subsetting tool to first determine whether the data type of the target storage address of each text character in the target mapping relationship table is a long integer or a short integer, and determines the corresponding address type parameter based on the data type of the target storage address, as well as determines the number of each text character, and then determines the glyph quantity parameter; then, the terminal combines the newly obtained target glyph data table, the newly obtained target horizontal layout table, the newly obtained target mapping relationship table, the newly determined address type parameter and the newly determined glyph quantity parameter to obtain the target font file of the original text under the font corresponding to the target font file, and obtains the target font file of the original text under the font corresponding to the target font file.
[0152] In specific applications, the font subsetting tool can also create a new target address type parameter table to record address type parameters, and a new target glyph quantity parameter table to record glyph quantity parameters, and obtain the target font file by combining the target glyph data table, target horizontal layout table, target mapping relationship table, target address type parameter table and target glyph quantity parameter table.
[0153] In practical applications, the creation of the target address type parameter table and the target glyph quantity parameter table can be achieved by copying; specifically, the original font file includes an original address type parameter table and an original glyph quantity parameter table, the original address type parameter table records the original address type parameters corresponding to the original font file, and the original glyph quantity parameter table records the original glyph quantity parameters corresponding to the original font file. The font subsetting tool can also copy the original address type parameter table and the original glyph quantity parameter table, and update the original address type parameters recorded in the original address type parameter table to address type parameters determined based on the data type of the target storage address of each text character, thereby obtaining the target address type parameter table, and update the original glyph quantity parameters recorded in the original glyph quantity parameter table to glyph quantity parameters determined based on the number of each text character, thereby obtaining the target glyph quantity parameter table.
[0154] This embodiment is explained by taking the case where the font corresponding to the original font file is TrueType as an example. The original font file of TrueType further includes a font header table head, which records a parameter indexToLocFormat representing the data type of the storage address of the glyph data. The font subsetting tool copies the head table in the original font file to obtain a new head table, and updates the indexToLocFormat parameter in the new head table based on the data type of the storage address recorded in the new glyf table; and the original font file of TrueType further includes a maximum requirement table maxp, which records a parameter numGlyphs representing the number of glyphs. The font subsetting tool copies the maxp table in the original font file to obtain a new maxp table, and updates the numGlyphs parameter in the new maxp table based on the number of each text character (i.e., the number of glyph data read from the original font file).
[0155] In specific applications, the original font file also includes some record tables whose recorded contents will not change during the font subsetting process. When the font subsetting tool creates the target font file, it can also directly copy these record tables and combine the newly created tables, the updated tables, and the record tables whose recorded contents have not changed to obtain the target font file.
[0156] Taking the case where the font corresponding to the original font file is TrueType as an example, the original TrueType font file also includes a font name table name, which is used to record the corresponding font name. Since the font name does not change during the font subsetting process, the font subsetting tool can directly copy the name table in the original TrueType font file to obtain a new name table, and combine the new cmap table, new glyf, new htmx table, new hhea table, new head table, new maxp table and new maxp table, etc. to obtain a new font file.
[0157] In this embodiment, the terminal can obtain the target font file of the original text in the font corresponding to the target font file by combining the newly created tables and the newly determined parameters.
[0158] In an exemplary embodiment, the above step S204, reading the glyph information of each text character in the target text from the original font file, specifically includes the following contents: determining the character encoding of each text character in the target text; sorting the character encoding of each text character; traversing each character encoding in the sorting order of each character encoding, and reading the glyph information of the text character corresponding to the traversed character encoding from the original font file.
[0159] Specifically, the terminal uses the font subsetting tool to first convert each text character into a corresponding Unicode code, and sort the array Unicode code of each text character to obtain the sorting order of each character code; then, it traverses each character code according to the sorting order of each character code, and reads the corresponding text character's glyph information from the original font file, so as to read the glyph information of each text character in turn.
[0160] In practical applications, the font subsetting tool can improve reading efficiency by reading glyph information in sequence according to the sorting order of each character encoding, especially reading the glyph identifier corresponding to each text character.
[0161] In this embodiment, the terminal can improve reading efficiency by reading the glyph information in sequence according to the sorting order of each character code.
[0162] In an exemplary embodiment, after obtaining the target font file of the original text in the font corresponding to the original font file in the above step S104, the following contents are specifically included: loading the target font file through a browser, and rendering each character in the original text based on the target font file to obtain the target characters of each character in the original text under the target font; displaying each target character through a browser to display the original text.
[0163] Specifically, after obtaining the target font file, the terminal loads the target font file through the browser, and renders each character in the original text based on the target font file to obtain the target characters corresponding to each character in the original text under the target font, and then displays each target character through the browser to display the original text.
[0164] In this embodiment, the terminal obtains a target font file with a reduced file size through the corresponding file, and can improve the rendering speed of the original text.
[0165] In an exemplary embodiment, the original text is the text uploaded by the user through the browser, and the original font file is the font file uploaded by the user through the browser.
[0166] After obtaining the target font file of the original text in the font corresponding to the original font file in the above step S104, the following contents are specifically included: upon receiving a download request initiated by the user for the target font file, the target font file is sent to the terminal from which the user sends the download request.
[0167] Specifically, the font subsetting tool supports users to download target font files; when a terminal or server receives a download request initiated by a user for a target font file, the terminal or server sends the target font file to the terminal where the user sends the download request, so that the user can save the target font file locally.
[0168] In practical applications, the target font file obtained by subsetting this time can also be used as the original font file for the next subsetting.
[0169] In an exemplary embodiment, as shown in FIG. 7 , another font file processing method is provided, which is described by taking the method applied to a terminal as an example, and includes the following steps:
[0170] Step S702: obtaining, through a browser, the original text to be rendered and the original font file used to render the original text.
[0171] Step S704, calling a font subsetting tool built for the browser in the browser to pre-process the original text to obtain a target text that does not contain blank characters and repeated characters.
[0172] Step S706, determining the character code of each text character in the target text by using a font subsetting tool.
[0173] Step S708: using a font subsetting tool, searching the first original mapping table in the original font file according to the character encoding of each text character, to obtain the glyph identifier of each text character.
[0174] Step S710, using a font subsetting tool, searching a second original mapping table in the original font file according to the glyph identifier of each text character, and obtaining an original storage address corresponding to each text character.
[0175] Step S712, through the font subsetting tool, according to the original storage address corresponding to each text character, the glyph data corresponding to each text character is read from the original glyph data table in the original font file, and, according to the glyph identifier of each text character, the horizontal layout parameters corresponding to each text character are read from the original horizontal layout table in the original font file.
[0176] Step S714: Create a target glyph data table based on the glyph data of each text character by using a font subsetting tool.
[0177] Step S716, using the font subsetting tool, based on the number of each text character, determine the array length of the array used to record the horizontal layout parameters of each text character, and create a target horizontal layout table according to the glyph identifier of each text character, the horizontal layout parameters of each text character and the array length.
[0178] Step S718, using a font subsetting tool, creates a first target mapping relationship table based on the mapping relationship between each text character and the target storage address of the glyph data of each text character in the target glyph data table, and creates a second target mapping relationship table based on the mapping relationship between each text character and the glyph identifier of each text character.
[0179] Step S720, using a font subsetting tool, based on the target glyph data table, the target horizontal layout table and the target mapping relationship table, a target font file is created for the original text in the font corresponding to the original font file.
[0180] Step S722, load the target font file through the browser, render each character in the original text based on the target font file, obtain the target characters of each character in the original text under the target font, and display each target character to display the original text.
[0181] In this embodiment, first, the terminal can determine the glyph identifier of each text character based on the first original mapping relationship table, and can determine the original storage address corresponding to the glyph data of each text character in the original glyph data table based on the second original mapping relationship table, and can read the glyph data of each text character from the original glyph data table based on the original storage address corresponding to each text character, and can read the horizontal layout parameters of each text character from the original horizontal layout table based on the glyph identifier of each text character to obtain the glyph information representing the shape, spacing, thickness and other information of each text character. Second, based on the glyph information read from the original font file, the terminal can create a target font file only for each non-blank and non-repeated character (i.e., each text character) in the original text; compared with the original font file, the target font file contains only a part of the information in the original font file, so the file size is reduced, and the rendering speed of the original text can be accelerated. Third, the terminal can increase the rendering speed of the original text through the corresponding target font file with reduced file size.
[0182] In order to more clearly illustrate the font file processing method provided by the embodiment of the present application, the font file processing method is specifically described below with a specific embodiment, but it should be understood that the embodiment of the present application is not limited thereto. In one exemplary embodiment, the present application also provides a font subsetting method based on a font subsetting library for a browser, which specifically includes the following contents:
[0183] This embodiment provides a font subsetting library for a browser. The source code of the font subsetting library is Rust source code. This embodiment packages and compiles the Rust source code into a compiled file in WebAssembly format for JavaScript code calling on the browser.
[0184] As shown in FIG8 , a flow chart of the font subsetting method based on the font subsetting library for the browser provided in this embodiment is shown, which is mainly divided into four steps: inputting text and font files, indexing glyphs through characters, selecting glyphs, and creating new font files.
[0185] The font subsetting method provided in this embodiment is further described below.
[0186] Taking the TrueType font as an example, the TrueType font file includes multiple tables, and each table has an association relationship. By sorting out the association relationship between each table, a schematic diagram of the association relationship as shown in FIG9 is obtained.
[0187] Specifically, the first mapping relationship table is the cmap table in the TrueType font file, which records the mapping relationship between the character encoding Unicode encoding and the glyph identifier glyfID. The second mapping relationship table is the loca table in the TrueType font file, which records the mapping relationship between the glyph identifier glyfID and the storage address of the glyph data. The glyph data table is the glyf table in the TrueType font file, which stores the glyph data. The horizontal layout parameter table is the htmx table in the TrueType font file, which records the horizontal layout parameters of the glyph according to the glyph identifier glyfID. The font header table is the head table in the TrueType font file, which records the address type parameter indexToLocFormat representing the data type of the storage address of the glyph data. The maximum demand table is the maxp table in the TrueType font file, which records the glyph number parameter numGlyphs representing the number of glyphs. The horizontal title data table is the hhea table in the TrueType font file, which records the array length parameter numOfLongHorMetrics for specifying the array length of the horizontal layout parameters.
[0188] Based on the association relationship shown in FIG9 , the font subsetting library provided by the present application implements font subsetting through the following steps:
[0189] (1) Receive the local font file uploaded by the user in the browser and the text to be rendered;
[0190] (2) Remove blank characters from the text, deduplicate characters in the text, and then sort the unicode encoding of each character.
[0191] (3) Traverse the sorted character code unicode codes, and retrieve the glyph identifier glyfID corresponding to the character code unicode code from the first mapping relationship table cmap according to the character code unicode code.
[0192] (4) According to the glyph identifier glyfID, a storage location corresponding to the glyph identifier glyfID is determined in the second mapping relationship table loca.
[0193] (5) According to the storage location, the corresponding glyph data is retrieved from the glyph data table glyf.
[0194] (6) According to the glyph identifier glyfID, the corresponding horizontal layout parameters are retrieved from the horizontal layout parameter table htmx.
[0195] (7) A new glyph data table glyf, a new first mapping relationship table cmap and a new second mapping relationship table loca are created using the retrieved glyph data.
[0196] (8) Copy the font header table head, and set the address type parameter indexToLocFormat in the new font header table head according to the data type of the storage location in the new second mapping relationship table loca.
[0197] (9) Copy the original maximum demand table maxp, and set the glyph number parameter numGlyphs in the new maximum demand table maxp according to the number of glyphs in the new glyph data table glyf.
[0198] (10) Copy the original horizontal title data table hhea, and set the array length parameter numOfLongHorMetrics in the new horizontal title data table hhea according to the number of glyphs in the new glyph data table glyf.
[0199] (11) Create a new horizontal layout parameter table htmx based on the horizontal layout parameters taken from the horizontal layout parameter table htmx and the array length parameter numOfLongHorMetrics in the new horizontal title data table hhea.
[0200] (12) Copy other tables.
[0201] (13) Based on the new table, create a new font file to implement font subsetting.
[0202] (14) The browser renders the text to be rendered based on the new font file, and the user can download the new font file.
[0203] FIG. 10 is a schematic diagram showing a flow chart of a font subsetting method based on a font subsetting library for a browser provided in this embodiment.
[0204] In this embodiment, the font subsetting library can be directly called by the browser side, so there is no need to upload the font file to the server side corresponding to the font subsetting tool, nor is there any need for the server side corresponding to the font subsetting tool to return the font file, thereby reducing the performance reduction of font subsetting caused by network latency and server pressure.
[0205] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0206] Based on the same inventive concept, the embodiment of the present application also provides a font file processing device for implementing the font file processing method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more font file processing device embodiments provided below can refer to the limitations of the font file processing method above, and will not be repeated here.
[0207] In an exemplary embodiment, as shown in FIG. 11 , a font file processing device is provided, including: an information acquisition module 1102 and a font subset module 1104, wherein:
[0208] The information acquisition module 1102 is used to acquire the original text to be rendered and the original font file used to render the original text through the browser.
[0209] The font subsetting module 1104 is used to call a font subsetting tool built for the browser in the browser, perform font subsetting processing on the original font file according to the original text, and obtain a target font file of the original text under the font corresponding to the original font file.
[0210] The font subsetting module 1104 is also used to pre-process the original text to obtain a target text that does not contain blank characters and repeated characters; read the glyph information of each text character in the target text from the original font file; the glyph information of each text character includes at least the glyph data of each text character and the horizontal layout parameters of each text character; based on the glyph information of each text character, create a target font file for the original text under the font corresponding to the original font file.
[0211] In an exemplary embodiment, the original font file includes at least an original mapping relationship table, an original glyph data table and an original horizontal layout table. The original mapping relationship table is used to record the mapping relationship between each font character under the font corresponding to the original font file and the glyph identifier of each font character, and the mapping relationship between each font character and the original storage address of the glyph data of each font character in the original glyph data table.
[0212] The font subsetting module 1104 is also used to determine the glyph identifier of each text character and the original storage address corresponding to each text character based on the original mapping relationship table; read the glyph data corresponding to each text character from the original glyph data table according to the original storage address corresponding to each text character, and read the horizontal layout parameters corresponding to each text character from the original horizontal layout table according to the glyph identifier of each text character.
[0213] In an exemplary embodiment, the original mapping relationship table includes a first original mapping relationship table and a second original mapping relationship table; the first original mapping relationship table is used to record the mapping relationship between the character encoding of each font character and the glyph identifier of each font character, and the second original mapping relationship table is used to record the mapping relationship between the glyph identifier of each font character and the original storage address of each font character.
[0214] The font subsetting module 1104 is also used to determine the character encoding of each text character in the target text; according to the character encoding of each text character, search the first original mapping relationship table to obtain the glyph identifier of each text character; according to the glyph identifier of each text character, search the second original mapping relationship table to obtain the original storage address corresponding to each text character.
[0215] In an exemplary embodiment, the glyph information of each text character at least includes the glyph identifier of each text character. The font subset module 1104 is further used to create a target glyph data table, a target horizontal layout table and a target mapping relationship table corresponding to the target text based on the glyph information of each text character; based on the target glyph data table, the target horizontal layout table and the target mapping relationship table, create a target font file of the original text under the font corresponding to the original font file; wherein the target mapping relationship table is used to record the mapping relationship between each text character and the glyph identifier of each text character, and the mapping relationship between each text character and the target storage address of the glyph data of each text character in the target glyph data table; the target glyph data table corresponds to the target storage address of each text character; and the target horizontal layout table corresponds to the glyph identifier of each text character.
[0216] In one of the embodiments, the font subsetting module 1104 is further used to create a target glyph data table based on the glyph data of each text character; determine the array length of the array used to record the horizontal layout parameters of each text character based on the number of each text character, and create a target horizontal layout table according to the glyph identifier of each text character, the horizontal layout parameters of each text character and the array length; create a target mapping relationship table based on the mapping relationship between each text character and the glyph identifier of each text character, and the mapping relationship between each text character and the target storage address of each text character.
[0217] In one of the embodiments, the font subsetting module 1104 is further used to determine an address type parameter based on the data type of the target storage address of each text character in the target mapping relationship table, and to determine a glyph quantity parameter based on the number of each text character; and to combine the target glyph data table, the target horizontal layout table, the target mapping relationship table, the address type parameter and the glyph quantity parameter to obtain a target font file of the original text under the font corresponding to the target font file.
[0218] In one of the embodiments, the font subsetting module 1104 is also used to determine the character encoding of each text character in the target text; sort the character encoding of each text character; traverse each character encoding in the sorting order of each character encoding, and read the glyph information of the text character corresponding to the traversed character encoding from the original font file.
[0219] In one of the embodiments, the font subsetting module 1104 is also used to load the target font file through the browser, and render each character in the original text based on the target font file to obtain the target characters of each character in the original text under the target font; and display each target character through the browser to display the original text.
[0220] Each module in the above-mentioned font file processing device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0221] In an exemplary embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be shown in FIG12. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit, and an input device. The processor, the memory, and the input / output interface are connected via a system bus, and the communication interface, the display unit, and the input device are connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner may be implemented through WIFI, a mobile cellular network, near field communication (NFC) or other technologies. When the computer program is executed by the processor, a font file processing method is implemented. The display unit of the computer device is used to form a visually visible picture, which may be a display screen, a projection device, or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device shell, or an external keyboard, touchpad or mouse.
[0222] Those skilled in the art will understand that the structure shown in FIG. 12 is merely a block diagram of a partial structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.
[0223] In an exemplary embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above-mentioned method embodiments when executing the computer program.
[0224] In an exemplary embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0225] In an exemplary embodiment, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps in the above method embodiments are implemented.
[0226] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.
[0227] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0228] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A font file processing method, characterized in that: The method comprises: Obtaining, through a browser, an original text to be rendered and an original font file used to render the original text; Invoking a font subsetting tool constructed for the browser in the browser, performing font subsetting processing on the original font file according to the original text, and obtaining a target font file of the original text under the font corresponding to the original font file; specifically comprising: Preprocessing the original text to obtain a target text that does not contain blank characters and repeated characters; Reading the glyph information of each text character in the target text from the original font file; the glyph information of each text character at least includes the glyph data of each text character and the horizontal layout parameters of each text character; Based on the glyph information of each text character, a target font file of the original text in the font corresponding to the original font file is created.
2. The method according to claim 1, characterized in that The original font file at least includes an original mapping relationship table, an original glyph data table and an original horizontal layout table, wherein the original mapping relationship table is used to record the mapping relationship between each font character under the font corresponding to the original font file and the glyph identifier of each font character, and the mapping relationship between each font character and the original storage address of the glyph data of each font character in the original glyph data table; The step of reading the font information of each text character in the target text from the original font file includes: Based on the original mapping relationship table, determining the glyph identifier of each text character and the original storage address corresponding to each text character; According to the original storage address corresponding to each text character, the glyph data corresponding to each text character is read from the original glyph data table, and, according to the glyph identifier of each text character, the horizontal layout parameters corresponding to each text character are read from the original horizontal layout table.
3. The method according to claim 2, characterized in that The original mapping relationship table includes a first original mapping relationship table and a second original mapping relationship table; the first original mapping relationship table is used to record the mapping relationship between the character code of each font character and the glyph identifier of each font character, and the second original mapping relationship table is used to record the mapping relationship between the glyph identifier of each font character and the original storage address of each font character; The determining, based on the original mapping relationship table, the glyph identifier of each text character and the original storage address corresponding to each text character comprises: Determining the character encoding of each text character in the target text; According to the character codes of the text characters, searching the first original mapping relationship table to obtain the glyph identifiers of the text characters; According to the glyph identifiers of the text characters, the second original mapping table is searched to obtain the original storage addresses corresponding to the text characters.
4. The method according to claim 1, characterized in that: The glyph information of each text character at least includes the glyph identifier of each text character; The step of creating a target font file for the original text in a font corresponding to the original font file based on the glyph information of each text character comprises: Based on the glyph information of each text character, creating a target glyph data table, a target horizontal layout table and a target mapping relationship table corresponding to the target text; Creating a target font file for the original text in the font corresponding to the original font file based on the target glyph data table, the target horizontal layout table and the target mapping relationship table; Among them, the target mapping relationship table is used to record the mapping relationship between each text character and the glyph identifier of each text character, and the mapping relationship between each text character and the target storage address of the glyph data of each text character in the target glyph data table; the target glyph data table corresponds to the target storage address of each text character; the target horizontal layout table corresponds to the glyph identifier of each text character.
5. The method according to claim 4, characterized in that The step of creating a target font data table, a target horizontal layout table and a target mapping relationship table corresponding to the target text based on the font information of each text character comprises: Creating the target glyph data table based on the glyph data of each text character; Determine, based on the number of the text characters, an array length of an array for recording horizontal layout parameters of the text characters, and create the target horizontal layout table according to the glyph identifiers of the text characters, the horizontal layout parameters of the text characters, and the array length; The target mapping relationship table is created based on the mapping relationship between each text character and the glyph identifier of each text character, and the mapping relationship between each text character and the target storage address of each text character.
6. The method according to claim 4, characterized in that The step of creating a target font file for the original text in a font corresponding to the original font file based on the target glyph data table, the target horizontal layout table, and the target mapping relationship table comprises: Determine an address type parameter based on the data type of the target storage address of each text character in the target mapping relationship table, and determine a glyph quantity parameter based on the quantity of each text character; The target font data table, the target horizontal layout table, the target mapping relationship table, the address type parameter and the glyph quantity parameter are combined to obtain the target font file of the original text in the font corresponding to the target font file.
7. The method according to any one of claims 1 to 6, characterized in that: The step of reading the font information of each text character in the target text from the original font file includes: Determining the character encoding of each text character in the target text; sorting the character codes of the text characters; The character codes are traversed in the sorting order of the character codes, and the glyph information of the text characters corresponding to the traversed character codes is read from the original font file.
8. The method according to any one of claims 1 to 6, characterized in that: After obtaining the target font file of the original text in the font corresponding to the original font file, the method further includes: The target font file is loaded through the browser, and each character in the original text is rendered based on the target font file to obtain a target character of each character in the original text in the target font; The browser displays each target character to display the original text.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 8 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.
11. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.
Citation Information
Cited By
Text drawing method and device, storage medium and program product
CN119398011A
