Icon font file processing method and device and storage medium
By extracting the actual style nodes from the icon font file and using a mapping table to accurately delete redundant content, the problems of large icon font file size and slow loading were solved, achieving file optimization and improved loading speed.
Patent Information
- Application Number
- CN202511328508.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-17
- Publication Date
- 2026-02-03
AI Technical Summary
Icon font files are bulky and redundant, resulting in large storage space consumption, long loading time, and manual optimization can easily lead to abnormal icon display.
By extracting the actual style nodes from the project code, matching the target encoding value using a mapping table, and accurately deleting redundant characters and styles in the icon font and style table, a processed file is generated.
Significantly reduce file size, decrease browser loading time and bandwidth consumption, ensure icon functionality, and optimize resource loading speed.
Smart Images

Figure CN121455477A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to a method, apparatus and storage medium for processing icon font files. Background Technology
[0002] In today's digital age, icon font files are widely used in various software projects. An icon font file is a special type of font file that encodes and stores various graphic icons in the form of characters, and its style can be flexibly controlled using style sheets such as CSS.
[0003] However, as software projects grow in size and become more complex, icon font files become increasingly bulky and contain a large number of redundant icons. These redundant icons not only consume a significant amount of storage space, but also require the browser to spend more time and bandwidth during loading, thus increasing the project's resource loading time.
[0004] When faced with redundant icons, traditional manual inspection and optimization require operators to possess certain professional knowledge and skills to remove redundant icons from icon font files and repackage and configure the files. However, manual operation is prone to problems such as accidentally deleting useful icons or making file configuration errors during the optimization process, leading to malfunctions such as abnormal icon display and causing great trouble for project development and maintenance. Summary of the Invention
[0005] This application discloses a method, apparatus, and storage medium for processing icon font files, used to reduce the size of icon font files and style sheet files.
[0006] The first aspect of this application discloses a method for processing icon font files, including: Extract the actual style nodes used in the project code, where each actual style node corresponds to a style definition or reference in the project code; The target encoding value that matches the actual style node is determined from the preset mapping table, which is used to establish the correspondence between style nodes and encoding values in the style sheet file; The icon font file is processed according to the target encoding value and the character encoding values in the icon font file to generate a processed icon font file. The processed icon font file contains only the characters actually used in the project code. The style sheet file is processed based on the actual style nodes and the style nodes in the style sheet file to generate a processed style sheet file. The processed style sheet file contains only the style nodes actually used in the project code.
[0007] Optionally, before determining the target encoding value matching the actual style node from the preset mapping table, the processing method further includes: Based on the stylesheet file, construct a mapping table.
[0008] Optionally, constructing the mapping table based on the stylesheet file includes: Scan the style sheet file and obtain the style nodes in the style sheet file and the corresponding encoded values of the style nodes; A mapping table is constructed based on the style node and the encoding value.
[0009] Optionally, the step of processing the icon font file according to the target encoding value and the character encoding values in the icon font file to generate a processed icon font file includes: Get the character encoding values from the icon font file; The target encoded value and the character encoded value are compared to obtain the first comparison result; Based on the first comparison result, redundant characters in the icon font file are removed to obtain a processed icon font file. The redundant characters are characters not used in the project code.
[0010] Optionally, the step of processing the style sheet file based on the actual style nodes and the style nodes in the style sheet file to generate a processed style sheet file includes: The actual style node is compared with the style node in the style sheet file to obtain a second comparison result; Based on the second comparison result, redundant styles in the style sheet file are removed, and a processed style sheet file is obtained. The redundant styles are style nodes that are not used in the project code.
[0011] Optionally, the extraction of the actual style nodes used in the project code includes: Transform the project code into an AST tree structure; Traverse the AST tree structure and extract the actual style nodes; When it is determined that there are actual style nodes with duplicate identifiers based on the identifiers of the actual style nodes, a merging process is performed.
[0012] Optionally, before extracting the actual style nodes used in the project code, the processing method further includes: The obtained stylesheet file is parsed into a node tree structure.
[0013] A second aspect of this application provides an apparatus for processing icon font files, comprising: The extraction unit extracts the actual style nodes used in the project code, and each actual style node corresponds to a style definition or reference in the project code. The matching unit determines the target encoding value that matches the actual style node from a preset mapping relationship table, wherein the mapping relationship table is used to establish the correspondence between style nodes and encoding values in the style sheet file; The first processing unit processes the icon font file according to the target encoding value and the character encoding values in the icon font file to generate a processed icon font file. The processed icon font file contains only the characters actually used in the project code. The second processing unit processes the style sheet file based on the actual style nodes and the style nodes in the style sheet file to generate a processed style sheet file, which contains only the style nodes actually used in the project code.
[0014] Optionally, the processing apparatus further includes: The building unit constructs a mapping table based on the stylesheet file.
[0015] The parsing unit parses the stylesheet file into a node tree structure.
[0016] A third aspect of this application provides an apparatus for optimizing icon font files, comprising: Processor, memory, input / output units, and bus; The processor is connected to memory, input / output units, and a bus; The memory stores a program, which the processor calls to execute, as in the first aspect and any optional processing method of the first aspect.
[0017] The fourth aspect of this application provides a computer-readable storage medium on which a program is stored, which, when executed on a computer, performs the processing methods of the first aspect and any optional processing methods of the first aspect.
[0018] As can be seen from the above technical solutions, the embodiments of this application have the following advantages: By extracting the actual style nodes used in the project code, which directly reflect the project's real icon requirements, we can accurately locate the icon character styles being used. A mapping table associates style nodes with their encoding values. By matching the encoding values corresponding to the actual style nodes, we can accurately delete unreferenced encoding values and corresponding icon styles from the font file, significantly reducing file size and storage space usage.
[0019] The optimized icon font file size is reduced, significantly decreasing the time and bandwidth consumption for browsers or devices to load the font file, directly optimizing the project's resource loading speed. Map-based association processing ensures that the retained encoding values strictly correspond to the actual style nodes, avoiding anomalies caused by manual encoding deletion and guaranteeing normal icon functionality.
[0020] The optimized stylesheet file retains only the style definitions of used icons and removes unused redundant styles. The streamlined stylesheet more clearly reflects the icon styles that the project actually depends on, reduces the size of the stylesheet file and parsing time, and further improves page loading speed. Attached Figure Description
[0021] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0022] Figure 1 This is a schematic diagram of an embodiment of the method for processing icon font files in this application; Figure 2 This is a schematic diagram of an embodiment of the method for constructing a mapping relationship table in this application; Figure 3 This is a schematic diagram of another embodiment of the icon font file processing method in this application; Figure 4 This is a schematic diagram of an embodiment of the icon font file processing device in this application; Figure 5 This is a schematic diagram of another embodiment of the icon font file processing device in this application. Detailed Implementation
[0023] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application may also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods have been omitted so as not to obscure the description of this application with unnecessary detail.
[0024] It should be understood that, when used in this application specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or a collection thereof.
[0025] It should also be understood that the term “and / or” as used in this application specification and the appended claims means any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0026] As used in this application specification and the appended claims, the term "if" may be interpreted, depending on the context, as "when," "once," "in response to determination," or "in response to detection." Similarly, the phrase "if determined" or "if detected [the described condition or event]" may be interpreted, depending on the context, as meaning "once determined," "in response to determination," "once detected [the described condition or event]," or "in response to detection [the described condition or event]."
[0027] Furthermore, in the description of this application and the appended claims, the terms "first," "second," "third," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0028] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not an embodiment," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0029] Based on this, this application discloses a method, apparatus, and storage medium for processing icon font files, used to reduce the size of icon font files and style sheet files.
[0030] The technical solutions of this application will be clearly and completely described below with reference to the accompanying drawings of the embodiments. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0031] The method of this application can be applied to servers, devices, terminals, or other devices with logical processing capabilities; therefore, this application does not limit its application. For ease of description, the following description uses a system as the executing entity.
[0032] Please see Figure 1This application provides an embodiment of a method for processing icon font files, including: S101. Extract the actual style nodes used in the project code. Each actual style node corresponds to a style definition or reference in the project code. By using specific code parsing tools or scripts, a comprehensive scan of the project code is performed to identify style-related parts of the code, including directly defined styles and styles used by referencing external stylesheet files.
[0033] During the scanning process, for each style definition or reference scenario, the corresponding actual style node is extracted. For example, in an HTML file, if an element uses the referenced style class="my-style", the style node related to my-style is extracted; if the inline style style="color:red;font-size:16px;" is used directly on the element, the actual style node containing the color and font size definitions is extracted.
[0034] S102. Determine the target encoding value that matches the actual style node from the preset mapping relationship table. The mapping relationship table is used to establish the correspondence between style nodes and encoding values in the style sheet file. A mapping table is pre-built, which records in detail the correspondence between style nodes and their encoded values in the stylesheet file. The system can use this mapping table to parse and analyze the stylesheet file, assigning a unique encoded value to each style selector, attribute, etc.
[0035] The extracted actual style nodes are compared and searched against a preset mapping table. The target encoding value that matches each actual style node is found in the mapping table.
[0036] S103. Process the icon font file according to the target encoding value and the character encoding value in the icon font file to generate a processed icon font file. The processed icon font file only contains the characters actually used in the project code. Based on the determined target encoding value, an association is established with the character encoding values in the icon font file. Icon font files typically contain multiple characters, each with a unique encoding value. By matching the target encoding value corresponding to the actual style node with the character encoding values in the icon font file, the characters actually used in the project code are identified.
[0037] Based on the above correlation results, the icon font file is processed. Only the parts corresponding to the characters actually used in the project code are retained, and other unused characters are deleted. For example, if the target encoding value determines that only 5 characters from the icon font file are used in the project code, then the processed icon font file will only contain these 5 characters, thereby reducing the file size.
[0038] S104. Process the style sheet file based on the actual style nodes and the style nodes in the style sheet file to generate a processed style sheet file. The processed style sheet file only contains the style nodes actually used in the project code.
[0039] The extracted actual style nodes are compared with the original style nodes in the stylesheet file. By comparing the selectors, attributes, and other content of the style nodes, the style nodes actually used in the project code are determined.
[0040] Based on the comparison results, the stylesheet file is processed. Only style nodes actually used in the project code are retained, and unused style nodes are deleted. For example, if a stylesheet file defines 20 style classes, but the comparison of actual style nodes reveals that only 8 of them are used in the project code, then the processed stylesheet file will only contain the definitions of these 8 style classes, thus optimizing the stylesheet file.
[0041] In this embodiment, by extracting the style nodes actually used in the project code, which directly reflect the project's actual icon requirements, the system accurately locates the icon character styles being used. A mapping table associates style nodes with their encoding values. By matching the encoding values corresponding to the actual style nodes, unreferenced encoding values and corresponding icon styles in the font file can be precisely deleted, significantly reducing file size and storage space usage.
[0042] Reducing the size of icon font files significantly decreases the time and bandwidth consumption for browsers or devices to load font files, directly optimizing the project's resource loading speed. Mapping-based association processing ensures that the retained encoding values strictly correspond to the actual style nodes, avoiding anomalies caused by manual encoding deletion and guaranteeing normal icon functionality.
[0043] The optimized stylesheet file retains only the style definitions of used icons and removes unused redundant styles. The streamlined stylesheet more clearly reflects the icon styles that the project actually depends on, reduces the size of the stylesheet file and parsing time, and further improves page loading speed.
[0044] In some specific embodiments, the system also needs to construct a mapping table based on the stylesheet file. Please refer to [link / reference]. Figure 2 , Figure 2 An embodiment of the method for constructing a mapping table includes the following steps: S201. Scan the style sheet file and obtain the style nodes and their corresponding encoding values in the style sheet file. The scanned stylesheet files are located in multiple directories within the project, encompassing CSS files, preprocessor files, and more. For each found stylesheet file, its contents are read into memory using file read operations. The reading method can be line-by-line or the entire file content can be read at once, depending on the needs of subsequent processing.
[0045] Choose an appropriate parser to parse the stylesheet content. The parser will parse the stylesheet according to the syntax rules and identify various elements in the stylesheet, such as selectors, attributes, and values.
[0046] A style node is the basic style unit in a stylesheet, consisting of a selector and its corresponding set of style attributes. The parsed stylesheet is traversed, and all style nodes are extracted. A unique encoded value is generated for each style node to facilitate quick lookup, comparison, and processing later. The encoded value can be a number, a string, or a combination of both, or it can be various encoded values such as MD5, SHA-1, etc.
[0047] S202. Construct a mapping table based on the style node and the encoding value.
[0048] Iterate through all extracted style nodes and their corresponding encoded values, storing the style nodes as keys and the encoded values as values in appropriate data structures. These data structures, such as dictionaries and hash tables, provide fast lookup and insertion operations by storing the mapping between style nodes and encoded values.
[0049] For smaller projects or those with high performance requirements, the mapping table can be stored in memory for easy and fast access later. For larger projects or projects that need to maintain mapping relationships long-term, the mapping table can be persistently stored in a file.
[0050] In this embodiment, the encoded value provides a unique identifier for each style node, helping to ensure style consistency. By constructing a mapping table, when a specific style node needs to be found, the encoded value can be used directly as an index for a fast lookup, avoiding line-by-line searches in the style sheet file and improving search efficiency.
[0051] A mapping table can be used to easily detect style reuse. By counting the number of times the style node corresponding to each coded value is referenced, we can analyze which styles are frequently used and which are redundant, thus enabling reasonable style optimization and reuse, and improving code maintainability.
[0052] The following provides a detailed explanation of the processing method for the icon font files provided in this application. Please refer to [link / reference]. Figure 3 , Figure 3 Another embodiment of the method for processing icon font files includes: S301. Convert the project code into an AST tree structure; First, the project code is formatted to be consistent, removing unnecessary spaces and line breaks, and standardizing indentation to ensure consistent code formatting for easier subsequent parsing.
[0053] The preprocessed code is input into the parser, which parses the code according to the corresponding syntax rules, gradually building an AST tree structure. Each node in the AST tree structure represents a syntax element in the code, such as an element node, attribute node, statement node, etc. In this embodiment, each node represents an actual style node, and the nodes form a tree structure through parent-child and sibling relationships.
[0054] S302. Traverse the AST tree structure and extract the actual style nodes; A recursive algorithm is used to traverse the AST tree structure. When an actual style node with the attribute name "class" is scanned, relevant information is recorded. All identified actual style nodes are stored in a set to ensure that the information of each actual style node is complete, including style type, target encoding value, etc.
[0055] S303. When it is determined that there are actual style nodes with duplicate identifiers based on the identifiers of the actual style nodes, a merging process is performed. For actual style nodes with the attribute name "class", the identifier is a string representation of the selector. For example, the identifier for ".button{color:red;}" is ".button".
[0056] The collected set of actual style nodes is traversed, using a dictionary (hash table) to record the actual style node corresponding to each identifier, with the style node as the key and the encoded value as the value. During traversal, for each style node, its corresponding identifier is identified. If the identifier already exists in the dictionary, the current actual style node is added to the corresponding list; otherwise, a new key-value pair is created in the dictionary. For the list of style nodes corresponding to each identifier in the dictionary, if the list length is greater than 1, it indicates that there are style nodes with duplicate identifiers, which need to be merged.
[0057] For multiple style definition nodes with the same selector, their style properties are merged. If there are identical properties, the later style value will override the earlier style value.
[0058] S304. Determine the target encoding value that matches the actual style node from the preset mapping relationship table. The mapping relationship table is used to establish the correspondence between style nodes and encoding values in the style sheet file. This step is similar to step S102 above, and can be referred to the corresponding process in the foregoing method embodiments, which will not be repeated here.
[0059] S305. Obtain the character encoding values from the icon font file; An icon font file is a collection of graphical representations of characters. Each character has a unique encoding value in the file, which is used to identify and locate the character in the system. Using specific font parsing tools or programming libraries, the character mapping table and other related data structures in the icon font file are read and parsed to extract the encoding value corresponding to each character, which is then stored in an appropriate data structure for subsequent processing.
[0060] 306. Compare the target encoding value with the character encoding value to obtain the first comparison result; The target encoding value determined in step 304 is compared one by one with the encoding values of all characters in the icon font file obtained in step 305. During the comparison, for each character encoding value in the font file, it is checked whether it exists in the target encoding value set to determine which character encoding values match the target encoding value and which do not.
[0061] The first comparison result can be a list of boolean values or an array of identifiers marking whether each character matches, which is used to determine which characters are redundant.
[0062] S307. Based on the first comparison result, remove redundant characters from the icon font file and obtain the processed icon font file. The redundant characters are characters not used in the project code. Based on the first comparison result, redundant characters in the icon font file are identified. Redundant characters are those that are not used in the project code and whose encoding values do not match those in the target encoding value set.
[0063] You can modify icon font files using font editing tools or programming libraries. For example, the system will remove redundant characters from the icon font file, resulting in a processed icon font file that only contains the characters actually used in the project.
[0064] S308. Compare the actual style nodes with the style nodes in the style sheet file to obtain the second comparison result; A comprehensive comparison is performed between the identified actual style nodes and the style nodes in the stylesheet file to identify style nodes that exist in the stylesheet file but are not used in the actual project code. This comparison determines which style nodes are actually used in the project code and which are not. The second comparison result is recorded as a list or set of redundant style nodes.
[0065] S309. Based on the second comparison result, remove redundant styles from the style sheet file and obtain the processed style sheet file. The redundant styles are style nodes that are not used in the project code.
[0066] Based on the second comparison result obtained in step 308, the system identifies style nodes in the stylesheet file that are not used by the project code, i.e., redundant styles.
[0067] Editing the stylesheet file removes redundant style nodes. You can use text processing tools or dedicated CSS parsing libraries to modify the stylesheet file's content. For example, the system will remove redundant styles from the stylesheet file, resulting in a processed stylesheet file. By removing redundant style nodes, you ultimately obtain a processed stylesheet file containing only the styles actually used in the project.
[0068] In this embodiment, by accurately identifying and statistically analyzing the actual usage of style nodes, style reuse and unified management can be better achieved. Merging duplicate style nodes can eliminate redundant style code in the project, reduce the size of stylesheets, and improve page loading performance. The AST tree structure is a general code representation; after converting project code into an AST tree structure and extracting style nodes, it can be easily integrated with other code analysis tools, build tools, etc., to achieve more complex style processing and analysis tasks.
[0069] Unused redundant characters and styles not only consume storage space but also consume memory and processor resources at runtime. By removing redundant characters and styles from the icon font file and stylesheet file, the size of these two files was significantly reduced. Smaller file sizes mean faster download speeds and less network bandwidth usage, which has a positive impact on the performance of websites or applications.
[0070] In some specific implementations, the system also needs to parse the stylesheet file into a node tree structure.
[0071] Style rules in stylesheet files typically have a nested and hierarchical structure. Parsing a stylesheet file into a node tree structure clearly shows the hierarchical relationship between style rules. The root node of the tree represents the entire stylesheet, and its child nodes can be different selectors (such as class selectors, ID selectors, element selectors, etc.). Each selector node can have multiple attribute nodes, representing the style properties corresponding to that selector.
[0072] Parsing stylesheets into a node tree structure is a crucial foundation for subsequent style optimization and processing. For example, when removing redundant styles, it's essential to accurately identify which style nodes are not used in the project code. By utilizing tree traversal algorithms, and considering style references within the project code, each style node can be analyzed and evaluated.
[0073] Please see Figure 4 This application provides an embodiment of an icon font file processing apparatus, comprising: Extraction unit 401 extracts the actual style nodes used in the project code. Each actual style node corresponds to a style definition or reference in the project code. Matching unit 402 determines the target encoding value that matches the actual style node from a preset mapping relationship table. The mapping relationship table is used to establish the correspondence between style nodes and encoding values in the style sheet file. The first processing unit 403 processes the icon font file according to the target encoding value and the character encoding value in the icon font file, and generates a processed icon font file. The processed icon font file only contains the characters actually used in the project code. The second processing unit 404 processes the style sheet file based on the actual style nodes and the style nodes in the style sheet file, and generates a processed style sheet file. The processed style sheet file only contains the style nodes actually used in the project code.
[0074] Optionally, the processing device also includes: Unit 405 constructs a mapping table based on the stylesheet file.
[0075] Optionally, building unit 405 is specifically used for: Scan the stylesheet file and obtain the style nodes and their corresponding encoded values. Construct a mapping table based on style nodes and encoding values.
[0076] Optionally, the first processing unit 403 is specifically used for: Get the character encoding values from the icon font file; The target encoded value is compared with the encoded value of the character to obtain the first comparison result; Based on the first comparison result, redundant characters in the icon font file are removed, and the processed icon font file is obtained. The redundant characters are characters not used in the project code.
[0077] Optionally, the second processing unit 404 is specifically used for: The actual style nodes are compared with the style nodes in the stylesheet file to obtain the second comparison result; Based on the second comparison result, redundant styles in the stylesheet file are removed, and a processed stylesheet file is obtained. The redundant styles are style nodes that are not used in the project code.
[0078] Optionally, the extraction unit 401 is specifically used for: Transform the project code into an AST tree structure; Traverse the AST tree structure and extract the actual style nodes; Identify the identifier of the actual style node. If there are actual style nodes with duplicate identifiers, merge them.
[0079] Optionally, the processing device also includes: Parsing unit 406 parses the stylesheet file into a node tree structure.
[0080] For detailed implementation methods, please refer to... Figures 1 to 3 Examples are not detailed here.
[0081] Please see Figure 5 This application provides an apparatus for processing icon font files, including: Processor 501, memory 502, input / output unit 503, and bus 504.
[0082] The processor 501 is connected to the memory 502, the input / output unit 503, and the bus 504.
[0083] The memory 502 stores a program, and the processor 501 calls the program to execute it, such as... Figure 1 , Figure 2 and Figure 3 The processing method in [the document / document].
[0084] This application provides a computer-readable storage medium on which a program is stored, and when the program is executed on a computer, it performs the following... Figure 1 , Figure 2 and Figure 3 The processing method in [the document / document].
[0085] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0086] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, or indirect coupling or communication connection between apparatuses or units, and may be electrical, mechanical, or other forms.
[0087] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0088] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0089] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
Claims
1. A method for processing icon font files, characterized in that, include: Extract the actual style nodes used in the project code, where each actual style node corresponds to a style definition or reference in the project code; The target encoding value that matches the actual style node is determined from the preset mapping table, which is used to establish the correspondence between style nodes and encoding values in the style sheet file; The icon font file is processed according to the target encoding value and the character encoding values in the icon font file to generate a processed icon font file. The processed icon font file contains only the characters actually used in the project code. The style sheet file is processed based on the actual style nodes and the style nodes in the style sheet file to generate a processed style sheet file. The processed style sheet file contains only the style nodes actually used in the project code.
2. The method according to claim 1, characterized in that, Before determining the target encoding value matching the actual style node from the preset mapping table, the processing method further includes: Based on the stylesheet file, construct a mapping table.
3. The method according to claim 2, characterized in that, The step of constructing a mapping table based on the stylesheet file includes: Scan the style sheet file and obtain the style nodes in the style sheet file and the corresponding encoded values of the style nodes; A mapping table is constructed based on the style node and the encoding value.
4. The method according to claim 1, characterized in that, The step of processing the icon font file according to the target encoding value and the character encoding values in the icon font file to generate the processed icon font file includes: Get the character encoding values from the icon font file; The target encoded value and the character encoded value are compared to obtain the first comparison result; Based on the first comparison result, redundant characters in the icon font file are removed to obtain a processed icon font file. The redundant characters are characters not used in the project code.
5. The method according to claim 1, characterized in that, The step of processing the style sheet file based on the actual style nodes and the style nodes in the style sheet file to generate a processed style sheet file includes: The actual style node is compared with the style node in the style sheet file to obtain a second comparison result; Based on the second comparison result, redundant styles in the style sheet file are removed, and a processed style sheet file is obtained. The redundant styles are style nodes that are not used in the project code.
6. The method according to claim 1, characterized in that, The extraction of actual style nodes used in the project code includes: Transform the project code into an AST tree structure; Traverse the AST tree structure and extract the actual style nodes; When it is determined that there are actual style nodes with duplicate identifiers based on the identifiers of the actual style nodes, a merging process is performed.
7. The method according to any one of claims 1 to 6, characterized in that, Before extracting the actual style nodes used in the project code, the processing method further includes: The obtained stylesheet file is parsed into a node tree structure.
8. A processing apparatus for icon font files, characterized in that, include: The extraction unit extracts the actual style nodes used in the project code, and each actual style node corresponds to a style definition or reference in the project code. The matching unit determines the target encoding value that matches the actual style node from a preset mapping relationship table, wherein the mapping relationship table is used to establish the correspondence between style nodes and encoding values in the style sheet file; The first processing unit processes the icon font file according to the target encoding value and the character encoding values in the icon font file to generate a processed icon font file. The processed icon font file contains only the characters actually used in the project code. The second processing unit processes the style sheet file based on the actual style nodes and the style nodes in the style sheet file to generate a processed style sheet file, which contains only the style nodes actually used in the project code.
9. A processing apparatus for icon font files, characterized in that, include: The processor includes a processor, a memory, an input / output unit, and a bus, wherein the processor is connected to the memory, the input / output unit, and the bus, the memory stores a program, and the processor calls the program to execute the processing method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium contains a program that, when executed on a computer, performs the processing method as described in any one of claims 1 to 7.