Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present disclosure more clear, the technical solutions of the embodiments of the present disclosure will be described clearly and completely with reference to the drawings in the embodiments of the present disclosure, and it is obvious that the described embodiments are only a part of the embodiments of the present disclosure, not all of the embodiments. The components of the embodiments of the present disclosure, generally described and illustrated in the figures herein, can be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present disclosure, presented in the figures, is not intended to limit the scope of the claimed disclosure, but is merely representative of selected embodiments of the disclosure. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the disclosure without making any creative effort, shall fall within the protection scope of the disclosure.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
The term "and/or" herein merely describes an associative relationship, meaning that three relationships may exist, e.g., a and/or B, may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the term "at least one" herein means any one of a plurality or any combination of at least two of a plurality, for example, including at least one of A, B, C, and may mean including any one or more elements selected from the group consisting of A, B and C.
Research shows that the file size of non-english fonts is generally large, for example, the file size of general chinese fonts is larger than 10 megabytes, and even the file size of some chinese fonts can reach 30 megabytes. When a user displays a font file stored in a server in a page, the font file generally needs to be completely loaded to display a rendering effect of a font corresponding to the font file. However, the characters displayed in the page are usually common characters, and a complete font file needs to be loaded in order to display the common characters. Under the condition that the font file is large, the loading efficiency of the font file is easily influenced, and more loading time is wasted.
Based on the above research, the present disclosure provides a font file generation method, apparatus, computer device, and storage medium. As can be seen from the above description, after the font file to be segmented is obtained, all the characters in the font file to be segmented may be segmented to obtain a plurality of groups of characters. After determining at least one preset font corresponding to each group of characters, a font subfile corresponding to the group of characters may be determined based on the at least one preset font corresponding to the group of characters, and a target font file may be determined based on the font subfile. Therefore, the font file to be segmented with larger file size can be segmented into a plurality of target font files, the loading efficiency of the font files in the webpage can be improved, and the time and the flow for loading the font files are saved.
To facilitate understanding of the present embodiment, a detailed description is first given of a font file generation method disclosed in the embodiments of the present disclosure, and an execution subject of the font file generation method provided in the embodiments of the present disclosure is generally a computer device with certain computing power.
Referring to fig. 1, a flowchart of a font file generation method provided in an embodiment of the present disclosure is shown, where the method includes steps S101 to S107, where:
s101: and acquiring a font file to be segmented, wherein the font file to be segmented comprises font files of all characters under all preset fonts.
Here, the font file to be divided may include characters and glyphs therein. The characters can be understood as characters to be displayed, for example, the characters can be chinese characters, english characters, symbols, and the like. The font can be understood as the display form of the character, for example, the font can be sons body, and also can be Times New Roman and the like.
The preset font can be understood as a preset font, for example, the preset font can be a song style, a regular style, a Times New Roman, or the like. The present disclosure does not specifically limit the type of the predetermined glyph.
In the embodiment of the present disclosure, the number of the preset fonts may be N, where N is a natural number, and the number of the preset fonts is not specifically limited in the present disclosure, so as to be implemented.
In the embodiment of the present disclosure, the font file to be divided may be: a font file containing all characters corresponding to the preset font song, or: and the font file comprises all characters corresponding to the preset font Times New Roman.
S103: and all the characters in the font file to be segmented are segmented to obtain a plurality of groups of characters.
In the embodiment of the present disclosure, all characters in the font file to be segmented may be segmented to obtain a plurality of groups of characters.
In specific implementation, all characters in the font file to be divided can be divided according to a preset dividing method. For example, the preset segmentation method may be a preset method of segmenting according to the character types of all characters in the font file to be segmented to obtain a plurality of groups of characters. Or, the preset segmentation method may also be a method of obtaining a plurality of groups of characters by performing preset segmentation according to the number of characters included in the font file to be segmented.
The preset segmentation method is not particularly limited in the present disclosure, and may be implemented.
S105: and determining at least one preset font corresponding to each group of characters, and determining font subfiles corresponding to the group of characters based on the at least one preset font corresponding to the group of characters.
In the embodiment of the present disclosure, after all characters in a font file to be segmented are segmented to obtain a plurality of groups of characters, at least one preset font corresponding to each group of characters may be determined, for example, the obtained plurality of groups of characters are 3 groups, which are respectively a character group 1, a character group 2, and a character group 3. It is assumed that, for the character group 1, it can be determined that at least one preset glyph corresponding to the character group 1 is: sons and Times New Roman.
Then, a font subfile corresponding to each group of characters can be determined based on at least one preset font corresponding to each group of characters.
For example, for the character group 1 and at least one preset font corresponding to the character group 1: the font subfiles corresponding to the character group 1 can be determined as follows: font subfile 1 and character subfile 2. The font subfile 1 comprises a character group 1 and a preset font sons body, and the font subfile 2 comprises the character group 1 and a preset font Times New Roman.
S107: a target font file is determined based on the font subfile.
In the embodiment of the present disclosure, after the font subfile corresponding to each group of characters is determined, the target font file may be determined based on the font subfile.
As can be seen from the above description, after the font file to be segmented is obtained, all the characters in the font file to be segmented may be segmented to obtain a plurality of groups of characters. After determining at least one preset font corresponding to each group of characters, a font subfile corresponding to the group of characters may be determined based on the at least one preset font corresponding to the group of characters, and a target font file may be determined based on the font subfile. Therefore, the font file to be segmented with larger file size can be segmented into a plurality of target font files, the loading efficiency of the font files in the webpage can be improved, and the time and the flow for loading the font files are saved.
In an alternative embodiment, as shown in fig. 2, for S103: all characters in the font file to be segmented are segmented to obtain a plurality of groups of characters, and the method specifically comprises the following steps:
step S21: acquiring a preset character type to be segmented;
step S22: all characters in the font file to be segmented are segmented according to the preset character types to obtain at least one first target character group, wherein each first target character group corresponds to one preset character type;
step S23: determining the plurality of groups of characters based on the at least one first target group of characters.
As can be seen from the above description, in the embodiment of the present disclosure, the characters may be segmented according to the character types of all the characters in the font file to be segmented, so as to obtain multiple groups of characters. The character type is a preset character type, and the content and the number of the preset character type are not particularly limited in the present disclosure. For example, the preset character type may be a song style, a Times New Roman, or a regular style. In addition, the number of the preset character types may be one or more, and the content and the number of the preset character types are not specifically limited in the present disclosure to meet the actual needs.
In specific implementation, a preset character type to be segmented may be obtained first, and then, the character types of all characters in the font file to be segmented may be segmented according to the preset character type to obtain at least one first target character group.
For example, when the preset character types to be segmented include 3 character types (e.g., english characters, chinese characters, punctuations), the character types of all the characters in the font file to be segmented may be segmented according to the 3 preset character types to obtain 3 first target character groups.
Thereafter, a plurality of sets of characters may be determined based on the determined at least one first target set of characters. For example, in the case where the first target character group is the above-mentioned 3 first target character groups, then each first target character group may be determined as a group of characters. At this time, 3 sets of characters can be determined.
In the above embodiment, the preset character type to be segmented may be obtained first, and then all characters in the font file to be segmented are segmented according to the preset character type, so as to obtain at least one first target character group. And then, based on the mode of determining the multiple groups of characters by the at least one first target character group, the flexible segmentation of all characters in the font file to be segmented can be realized by presetting the character types, and further more diversified multiple groups of characters can be obtained. Meanwhile, multiple groups of characters obtained by segmentation can better meet the actual requirements.
In an optional embodiment, as shown in fig. 3, for the steps S21 to S23, the method of the present disclosure further includes the following steps:
step S31: under the condition that all the characters contain other characters except the at least one first target character group, grouping the other characters according to the preset character number to obtain at least one second target character group;
step S32: said determining the plurality of groups of characters based on the at least one first target group of characters comprises: determining the plurality of groups of characters based on the at least one first target group of characters and the at least one second target group of characters.
In the embodiment of the present disclosure, when all the characters of the font file to be divided include other characters except for the at least one target character set determined in the above steps S21 to S23, the other characters may be grouped according to the preset number of characters to obtain at least one second target character set.
Then, all the characters in the font file to be segmented may be segmented based on the obtained at least one first target character group and at least one second target character group, so as to obtain a plurality of groups of characters.
For example, in the case that all characters in the font file to be divided include other characters (e.g., korean characters) in addition to the 3 preset character types as described above, the other characters (e.g., korean characters) may be grouped by a preset number of characters to obtain at least one second target character group.
In an alternative embodiment, the predetermined number of characters may be determined by the following process:
and acquiring a preset character coding range, and determining the number of the preset characters based on the preset character coding range.
The preset character encoding range may be understood as an encoding range obtained after a certain number of characters are encoded, for example, for a character: the corresponding character coding range (U + 3100-U +312F) can be obtained by the Pinyin alphabet, and at this time, the character coding range (U + 3100-U +312F) can be determined as the preset character coding range.
In the embodiment of the present disclosure, in the case that the preset number of characters is determined based on the preset character encoding range, the number of characters corresponding to the preset character encoding range may be determined as the preset number of characters. For example, in the case where the character encoding range is preset to be (U + 3100-U +312F), the number of characters corresponding to the character encoding range (U + 3100-U +312F) may be determined to be 46, and then the preset number of characters may be determined to be 46.
It should be noted that, the present disclosure does not specifically limit the encoding range of the preset characters, so as to be implemented.
In the foregoing embodiment, when all the characters of the font file to be divided include other characters except for the at least one target character group, the preset character encoding range may be obtained, and the number of the preset characters may be determined based on the preset character encoding range. Then, other characters can be grouped according to the preset character number to obtain at least one second target character group, and multiple groups of characters are determined based on the at least one first target group and the at least one second target character group. Therefore, all characters in the font file to be segmented can be ensured to be segmented, the obtained multiple groups of characters are more accurate, the loading time and the flow of the font file can be further saved, and the loading efficiency of the font file is improved.
In an alternative embodiment, for S105: determining at least one preset font corresponding to each group of characters, and determining font subfiles corresponding to the group of characters based on the at least one preset font corresponding to the group of characters, specifically comprising the following steps:
step S41: acquiring a font mapping file, wherein the font mapping file comprises a mapping relation between each group of characters and a preset font;
step S42: determining the at least one preset font corresponding to each group of the characters based on the font mapping file;
step S43: and extracting a font file matched with the corresponding at least one preset font from the font files contained in the font file to be divided, and determining the font file as a font subfile of the group of characters.
In the embodiment of the present disclosure, the font mapping file includes a mapping relationship between each group of characters and at least one preset font corresponding to the group of characters, and in specific implementation, the font mapping file may be determined by determining a mapping relationship between a character code of each group of characters and each preset font.
Then, at least one preset font corresponding to each group of characters can be determined based on the font mapping file, and a font file matched with the at least one preset font corresponding to each group of characters is extracted from font files contained in the font file to be divided. At this point, the matching font file may be determined as a font subfile for the set of characters.
For example, after the font mapping file is obtained, under the condition that it is determined that a group of characters exists as the character group 1 based on the font mapping file and that a preset font corresponding to the character group 1 is determined as the song body, a font file matched with the preset font song body may be extracted from font files included in the font files to be divided, and the matched font file is determined as a font subfile of the character group 1.
In the foregoing embodiment, the font mapping file may be obtained first, and then at least one preset font corresponding to each group of characters may be determined based on the font mapping file. And then, extracting a font file matched with the at least one corresponding preset font from font files contained in the font file to be divided, and determining the font file as a font subfile of the group of characters. Therefore, the font file to be segmented can be segmented, and font subfiles corresponding to a plurality of groups of characters are obtained. Meanwhile, the accuracy of the obtained font subfiles can be improved.
In an alternative embodiment, as shown in fig. 4, for S107: determining a target font file based on the font subfile, specifically comprising the following steps:
step S51: generating a storage address of the font subfile in a preset storage space;
step S52: and generating a cascading style CSS table by using the storage address and the font sub-file, and determining the cascading style CSS table as the target font file.
In an optional embodiment, after determining the font subfile corresponding to the group of characters based on at least one preset font corresponding to the group of characters, the font subfile is stored in the preset storage space. Then, the storage address of the font subfile in the preset storage space may be recorded. The preset storage space may be a static random access memory register, or the preset storage space may also be any other memory.
In the embodiment of the present disclosure, when the target font file is determined based on the font subfile, a storage address of the font subfile in a preset storage space may be generated first, and then the cascading style CSS table may be generated by using the storage address and the font subfile corresponding to the storage address. The cascading style CSS table can be used for indicating the style of each element in the webpage.
In this embodiment of the present disclosure, the cascading style CSS table may be used to display characters included in the font subfile and a preset font corresponding to the characters.
In the embodiment of the present disclosure, after the cascading style CSS table is generated, the cascading style CSS table may be determined as a target font file corresponding to the group of characters.
In the embodiment of the present disclosure, after the target font file is determined, the target font file may be loaded in the web page using the font-face rule of the cascading style CSS table, and then the characters in the target font file and the fonts corresponding to the characters may be displayed in the web page.
The implementation process of loading the target font file in the web page using the font-face rule of the cascading style CSS table may be the process shown in fig. 5. As shown in fig. 5, in the process of loading the font-face rule using the cascading style CSS table, the display form of the set of characters in the web page may be determined by determining the preset font (i.e., "the name of the font" as shown in fig. 5), the storage address of the font subfile (i.e., "the address of the font storage" as shown in fig. 5), the display form of the set of characters (i.e., "font-style", "font-display", "font-weight" as shown in fig. 5), the preset character encoding range (i.e., "unicode-range" as shown in fig. 5), and other information.
In the foregoing embodiment, after obtaining the font subfile corresponding to each group of characters, a storage location of the font subfile in a preset storage space may be generated, and a cascading style CSS table may be generated by using the storage location and the font subfile. The cascading style CSS table may then be determined as the target font file for the set of characters. Therefore, the cascading style CSS table corresponding to each group of characters can be generated by using the font subfile corresponding to each group of characters and the storage address of the font subfile, and each group of characters obtained by segmentation can be practically applied to a webpage.
The font file generation method provided by the embodiment of the present disclosure can also be described in detail in combination with the flowchart.
For example, as shown in fig. 6, after the font file to be divided is obtained, all the characters in the font file to be divided may be grouped. In specific implementation, as shown in fig. 6, all characters in the font file to be divided may be grouped according to preset character types to be divided (for example, types of english characters, punctuations, and the like), and then, according to the preset number of characters, other characters, except for the character corresponding to the preset character type, in all characters included in the font file to be divided may be grouped to obtain a plurality of groups of characters.
Then, a font subfile corresponding to each group of characters can be determined, and the font subfile is stored in a preset storage space. And simultaneously, recording the storage address of the font subfile. Finally, a cascading style CSS table may be generated based on the storage address of the font subfile and the font subfile, where the cascading style CSS table is the target font file in the embodiment of the present disclosure.
It will be understood by those skilled in the art that in the method of the present invention, the order of writing the steps does not imply a strict order of execution and any limitations on the implementation, and the specific order of execution of the steps should be determined by their function and possible inherent logic.
Based on the same inventive concept, the embodiment of the present disclosure further provides a font file generating apparatus corresponding to the font file generating method, and because the principle of the apparatus in the embodiment of the present disclosure for solving the problem is similar to the font file generating method in the embodiment of the present disclosure, the implementation of the apparatus may refer to the implementation of the method, and repeated details are not described again.
Referring to fig. 7, a schematic diagram of a font file generating apparatus provided in an embodiment of the present disclosure is shown, where the apparatus includes: an acquisition unit 71, a segmentation unit 72, a first determination unit 73, a second determination unit 74; wherein the content of the first and second substances,
the acquiring unit 71 is configured to acquire a font file to be divided, where the font file to be divided includes font files of all characters under preset fonts;
the segmentation unit 72 is configured to segment all characters in the font file to be segmented to obtain a plurality of groups of characters;
a first determining unit 73, configured to determine at least one preset font corresponding to each group of characters, and determine a font subfile corresponding to the group of characters based on the at least one preset font corresponding to the group of characters;
a second determining unit 74 for determining a target font file based on the font subfile.
As can be seen from the above description, after the font file to be segmented is obtained, all the characters in the font file to be segmented may be segmented to obtain a plurality of groups of characters. After determining at least one preset font corresponding to each group of characters, a font subfile corresponding to the group of characters may be determined based on the at least one preset font corresponding to the group of characters, and a target font file may be determined based on the font subfile. Therefore, the font file to be segmented with larger file size can be segmented into a plurality of target font files, the loading efficiency of the font files in the webpage can be improved, and the time and the flow for loading the font files are saved.
In a possible implementation, the segmentation unit is further configured to: acquiring a preset character type to be segmented; all characters in the font file to be segmented are segmented according to the preset character types to obtain at least one first target character group, wherein each first target character group corresponds to one preset character type; determining the plurality of groups of characters based on the at least one first target group of characters.
In a possible implementation, the segmentation unit is further configured to: under the condition that all the characters contain other characters except the at least one first target character group, grouping the other characters according to the preset character number to obtain at least one second target character group; said determining the plurality of groups of characters based on the at least one first target group of characters comprises: determining the plurality of groups of characters based on the at least one first target group of characters and the at least one second target group of characters.
In a possible implementation, the segmentation unit is further configured to: and acquiring a preset character coding range, and determining the number of the preset characters based on the preset character coding range.
In a possible implementation, the first determining unit is further configured to: acquiring a font mapping file, wherein the font mapping file comprises a mapping relation between each group of characters and a preset font; determining the at least one preset font corresponding to each group of the characters based on the font mapping file; and extracting a font file matched with the corresponding at least one preset font from the font files contained in the font file to be divided, and determining the font file as a font subfile of the group of characters.
In a possible implementation, the second determining unit is further configured to: generating a storage address of the font subfile in a preset storage space; and generating a cascading style CSS table by using the storage address and the font sub-file, and determining the cascading style CSS table as the target font file.
In a possible implementation, the second determining unit is further configured to: after determining the font subfile corresponding to the group of characters based on at least one preset font corresponding to the group of characters, storing the font subfile into the preset storage space.
The description of the processing flow of each module in the device and the interaction flow between the modules may refer to the related description in the above method embodiments, and will not be described in detail here.
Corresponding to the font file generating method in fig. 1, an embodiment of the present disclosure further provides a computer device 800, and as shown in fig. 8, a schematic structural diagram of the computer device 800 provided in the embodiment of the present disclosure includes:
a processor 81, a memory 82, and a bus 83; the memory 82 is used for storing execution instructions and includes a memory 821 and an external memory 822; the memory 821 herein is also referred to as an internal memory, and is configured to temporarily store operation data in the processor 81 and data exchanged with the external memory 822 such as a hard disk, the processor 81 exchanges data with the external memory 822 through the memory 821, and when the computer apparatus 800 operates, the processor 81 communicates with the memory 82 through the bus 83, so that the processor 81 executes the following instructions:
acquiring a font file to be segmented, wherein the font file to be segmented comprises font files of all characters under all preset fonts;
all characters in the font file to be segmented are segmented to obtain a plurality of groups of characters;
determining at least one preset font corresponding to each group of characters, and determining font subfiles corresponding to the group of characters based on the at least one preset font corresponding to the group of characters;
a target font file is determined based on the font subfile.
The embodiments of the present disclosure also provide a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the computer program performs the steps of the font file generation method in the foregoing method embodiments. The storage medium may be a volatile or non-volatile computer-readable storage medium.
The embodiments of the present disclosure also provide a computer program product, where the computer program product carries a program code, and instructions included in the program code may be used to execute the steps of the font file generating method in the foregoing method embodiments, which may be referred to specifically in the foregoing method embodiments, and are not described herein again.
The computer program product may be implemented by hardware, software or a combination thereof. In an alternative embodiment, the computer program product is embodied in a computer storage medium, and in another alternative embodiment, the computer program product is embodied in a Software product, such as a Software Development Kit (SDK), or the like.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the system and the apparatus described above may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again. In the several embodiments provided in the present disclosure, it should be understood that the disclosed system, apparatus, and method may be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one logical division, and there may be other divisions when actually implemented, and for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of devices or units through some communication interfaces, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present disclosure may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a non-volatile computer-readable storage medium executable by a processor. Based on such understanding, the technical solution of the present disclosure may be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present disclosure. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
Finally, it should be noted that: the above-mentioned embodiments are merely specific embodiments of the present disclosure, which are used to illustrate the technical solutions of the present disclosure, but not to limit the technical solutions, and the scope of the present disclosure is not limited thereto, and although the present disclosure is described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: any person skilled in the art can modify or easily conceive of the technical solutions described in the foregoing embodiments or equivalent technical features thereof within the technical scope of the present disclosure; such modifications, changes or substitutions do not depart from the spirit and scope of the embodiments of the present disclosure, and should be construed as being included therein. Therefore, the protection scope of the present disclosure shall be subject to the protection scope of the claims.