Font matching method and device

By obtaining the basic properties of the source font and common fonts, calculating the distance and dot product, and determining the target font, the problem of font matching effects and performance in the existing technology cannot be taken into account, and efficient font matching among common fonts is achieved.

CN120509378APending Publication Date: 2025-08-19ZHUHAI KINGSOFT OFFICE SOFTWARE +2
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510618111.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-14
Publication Date
2025-08-19

AI Technical Summary

Technical Problem

The existing technology cannot take into account both the matching effect and the matching performance in font matching. The font matching performance of the convolutional neural network is poor, while the font matching effect of the mapping table is poor.

Method used

By obtaining the basic properties of the source font and common font, calculate the distance and dot product between the two, determine the target font from the commonly used font based on the sorting results, and match it with the font alias whitelist and candidate font list.

Benefits of technology

It realizes font matching among commonly used fonts, achieves better matching effect and matching performance, and takes into account both font matching effect and performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120509378A_ABST
    Figure CN120509378A_ABST
Patent Text Reader

Abstract

The invention relates to a font matching method and device, and the method comprises the steps: obtaining a text presented by a source font, and obtaining a first font basic attribute of the source font; obtaining at least one common font, and obtaining a second font basic attribute of each common font; and determining a target font matched with the text from the at least one common font according to the first font basic attribute and the second font basic attribute. In this way, font matching is carried out in common fonts, a good matching effect and matching performance can be achieved, and meanwhile the matching effect and the matching performance are considered.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a font matching method and device. Background Art

[0002] Currently, for documents presented in specific fonts, when the documents face cross-platform / device display, document conversion (such as converting layout documents to streaming documents), and the need to avoid copyright risks, if the device or software does not support the original specific font of the document, it is necessary to quickly find the most suitable alternative font for these unsupported fonts, and then display the document with the alternative font.

[0003] In related technologies, a convolutional neural network is usually designed to convert the font matching task into an image classification task. By inputting the text image of the font to be matched into the convolutional neural network, the matching calligraphy type is obtained, and then the calligraphy type mapping list is queried according to the calligraphy type to obtain fonts with the same calligraphy type.

[0004] Alternatively, you can call a mapping table query interface to obtain a mapping table, enter the source font name you want to match, and then determine whether there is a target font matching the source font name in the mapping table. If so, replace the source font with the target font. In this way, font matching can be achieved by providing a mapping table.

[0005] However, while the convolutional neural network approach described above can achieve good font matching results, its font matching performance is poor. While the mapping table approach offers good font matching performance, its font matching results are poor. Therefore, neither approach can achieve a balanced balance between matching results and matching performance. Summary of the Invention

[0006] In order to solve the technical problem that no matter which implementation method is used, both matching effect and matching performance cannot be taken into account, the embodiments of the present application provide a font matching method, device, electronic device and storage medium. The specific technical solution is as follows:

[0007] In a first aspect of an embodiment of the present application, a font matching method is first provided, the method comprising:

[0008] Obtaining text rendered in a source font, and obtaining a first font basic attribute of the source font;

[0009] Obtain at least one commonly used font, and obtain a second font basic attribute of each commonly used font;

[0010] A target font matching the text is determined from at least one of the common fonts according to the first basic font attribute and the second basic font attribute.

[0011] In an optional embodiment, determining a target font matching the text from at least one of the commonly used fonts based on the first font basic attributes and the second font basic attributes includes:

[0012] determining a distance and a dot product between each of the commonly used fonts and the source font according to the first font basic attribute and the second font basic attribute;

[0013] sorting at least one of the commonly used fonts according to the distance and the dot product to obtain a commonly used font sorting result;

[0014] Determining a target font that matches the text from at least one of the commonly used fonts according to the commonly used font sorting result;

[0015] The determining of the distance and dot product between each of the commonly used fonts and the source font based on the first font basic attribute and the second font basic attribute includes:

[0016] Constructing first font coordinates corresponding to the source font according to the first font basic attributes;

[0017] For any of the commonly used fonts, constructing second font coordinates corresponding to the commonly used font according to the second font basic attributes;

[0018] The distance and dot product between the commonly used font and the source font are determined according to the first font coordinates and the second font coordinates.

[0019] In an optional embodiment, the first basic font attributes include a first font stretch attribute, a first font style attribute, and a first font weight attribute; and first font coordinates corresponding to the source font are constructed based on the first basic font attributes.

[0020] The step of constructing first font coordinates corresponding to the source font according to the first font basic attributes includes:

[0021] Processing the attribute value of the first font stretch attribute to obtain an X-axis coordinate value;

[0022] Processing the attribute value of the first font style attribute to obtain a Y-axis coordinate value;

[0023] Processing the attribute value of the first font weight attribute to obtain a Z-axis coordinate value;

[0024] Construct first font coordinates corresponding to the source font according to the X-axis coordinate value, the Y-axis coordinate value, and the Z-axis coordinate value.

[0025] In an optional implementation, the processing the attribute value of the first font stretch attribute to obtain the X-axis coordinate value includes:

[0026] Subtracting a first preset stretching threshold from the attribute value of the first font stretching attribute to obtain a first stretching difference;

[0027] The first stretching difference is multiplied by a second preset stretching threshold to obtain an X-axis coordinate value.

[0028] In an optional implementation, the processing of the attribute value of the first font style attribute to obtain the Y-axis coordinate value includes:

[0029] The attribute value of the first font style attribute is multiplied by a preset style threshold to obtain a Y-axis coordinate value.

[0030] In an optional implementation, the processing the attribute value of the first font weight attribute to obtain the Z-axis coordinate value includes:

[0031] Subtracting a first preset thickness threshold from the attribute value of the first font thickness attribute to obtain a first thickness difference;

[0032] Dividing the first thickness difference by a second preset thickness threshold to obtain a first thickness quotient;

[0033] The first thickness quotient is multiplied by a third preset thickness threshold to obtain a Z-axis coordinate value.

[0034] In an optional embodiment, determining a target font that matches the text from at least one of the commonly used fonts according to the commonly used font sorting result includes:

[0035] From the ranking results of the commonly used fonts, a commonly used font ranked first is selected, and the commonly used font ranked first is determined as a target font that matches the text.

[0036] In an optional embodiment, determining the first-ranked commonly used font as the target font matching the text includes:

[0037] Finding a target distance between a top-ranked common font and the source font from among all the distances;

[0038] Determining whether the target distance exceeds a first preset distance threshold, and whether the first-ranked commonly used font contains the glyph in the source font;

[0039] If the target distance does not exceed a first preset distance threshold and the first-ranked commonly used font includes the glyph in the source font, the first-ranked commonly used font is determined as the target font matching the text.

[0040] In an optional embodiment, the method further comprises:

[0041] When no target font matching the text is found in at least one of the commonly used fonts, obtaining a font alias whitelist;

[0042] Determining a target font that matches the text according to the font alias whitelist;

[0043] If no target font matching the text is found according to the font alias whitelist, obtaining a candidate font list;

[0044] A target font matching the text is determined from the candidate fonts in the candidate font list.

[0045] In an optional implementation, determining the target font that matches the text according to the font alias whitelist includes:

[0046] Obtaining a font name or font cluster name of the source font, and searching the font alias whitelist for a font alias corresponding to the font name or font cluster name;

[0047] The font corresponding to the font alias is determined as the target font that matches the text.

[0048] In an optional implementation, determining the font corresponding to the font alias as the target font matching the text includes:

[0049] Acquire a first font bold attribute and / or a first font italic attribute of the source font, and a second font bold attribute and / or a second font italic attribute of the font corresponding to the font alias;

[0050] In a case where the first font bold attribute is the same as the second font bold attribute and / or the first font italic attribute is the same as the second font italic attribute, determining whether the font corresponding to the font alias includes a glyph in the source font;

[0051] In a case where the font corresponding to the font alias includes glyphs in the source font, the font corresponding to the font alias is determined as a target font that matches the text.

[0052] In an optional embodiment, determining the target font that matches the text from the candidate fonts in the candidate font list includes:

[0053] Filtering at least one candidate font from the candidate font list, wherein the candidate font includes glyphs in the source font;

[0054] Acquire a first font appearance attribute of the source font, and for any candidate font, acquire a second font appearance attribute of the candidate font;

[0055] determining a feature distance between the source font and the candidate font according to the first font appearance attribute and the second font appearance attribute;

[0056] sorting at least one candidate font according to all the feature distances to obtain a candidate font sorting result;

[0057] According to the candidate font sorting result, a target font matching the text is determined from at least one candidate font.

[0058] In an optional embodiment, the number of the first font appearance attributes and the number of the second font appearance attributes are both M, where M is a positive integer;

[0059] The determining, based on the first font appearance attribute and the second font appearance attribute, a feature distance between the source font and the candidate font includes:

[0060] Inputting the i-th first font appearance attribute and the corresponding i-th second font appearance attribute into the following formula to obtain the characteristic distance between the source font and the candidate font, where i is 1, 2, 3, ..., M in sequence;

[0061] Cost=sqrt(Sum_i((Ri-Ai)^2*Wi)); the Cost is the feature distance, the Ri is the i-th first font appearance attribute, the Ai is the i-th second font appearance attribute, and the Wi is the weight corresponding to the i-th first font appearance attribute and the i-th second font appearance attribute.

[0062] In an optional embodiment, determining a target font matching the text from at least one candidate font according to the candidate font sorting result includes:

[0063] From the candidate font ranking results, the candidate font ranked first is selected and determined as the target font matching the text.

[0064] In an optional embodiment, determining the first-ranked candidate font as the target font matching the text includes:

[0065] Finding a target feature distance between the candidate font ranked first and the source font from all the feature distances;

[0066] When the target feature distance does not exceed a second preset distance threshold, the candidate font ranked first is determined as the target font that matches the text.

[0067] In an optional embodiment, the method further comprises:

[0068] When the target feature distance exceeds a second preset distance threshold, a default font is determined as a target font that matches the text, wherein the default font includes glyphs in the source font.

[0069] In an optional embodiment, the document containing the text is a layout document, the text is a character at any position in the layout document, and the number of characters is at least one. After the font matching of the text is completed, the font matching of subsequent characters of the text includes:

[0070] Determine the font distance between the mth character and the previous character in the document containing the text, where m is a positive integer greater than or equal to 2;

[0071] When the font distance is less than the distance threshold, determining a matching font for the mth character based on a matching font for a previous character;

[0072] When the font distance is greater than the distance threshold, a matching font for the mth character is determined based on a font matching method.

[0073] In a second aspect of the embodiments of the present application, a font matching device is further provided, the device comprising:

[0074] A text acquisition module, configured to acquire text presented in a source font and acquire a first basic font attribute of the source font;

[0075] An attribute acquisition module, configured to acquire at least one commonly used font and acquire a second font basic attribute of each commonly used font;

[0076] The font matching module is configured to determine a target font that matches the text from at least one of the commonly used fonts based on the first font basic attributes and the second font basic attributes.

[0077] In an optional implementation, the font matching module specifically includes:

[0078] a distance and dot product determination submodule, configured to determine the distance and dot product between each of the commonly used fonts and the source font based on the first font basic attributes and the second font basic attributes;

[0079] a common font sorting submodule, configured to sort at least one of the common fonts according to the distance and the dot product to obtain a common font sorting result;

[0080] a font matching submodule, configured to determine a target font that matches the text from at least one of the commonly used fonts according to the commonly used font sorting result;

[0081] The distance and dot product determination submodule specifically includes:

[0082] A first font coordinate construction unit, configured to construct first font coordinates corresponding to the source font according to the first font basic attributes;

[0083] A second font coordinate construction unit, configured to construct, for any of the commonly used fonts, second font coordinates corresponding to the commonly used font according to the second font basic attributes;

[0084] A distance and dot product determining unit is configured to determine a distance and a dot product between the commonly used font and the source font according to the first font coordinates and the second font coordinates.

[0085] In an optional embodiment, the first basic font attributes include a first font stretch attribute, a first font style attribute, and a first font weight attribute; the first font coordinate construction unit is specifically configured to: construct first font coordinates corresponding to the source font according to the first basic font attributes;

[0086] The first font coordinate construction unit specifically includes:

[0087] An X-axis coordinate value generating subunit is used to process the attribute value of the first font stretch attribute to obtain an X-axis coordinate value;

[0088] A Y-axis coordinate value generating subunit, configured to process the attribute value of the first font style attribute to obtain a Y-axis coordinate value;

[0089] A Z-axis coordinate value generating subunit is used to process the attribute value of the first font weight attribute to obtain a Z-axis coordinate value;

[0090] The first font coordinate construction subunit is configured to construct first font coordinates corresponding to the source font according to the X-axis coordinate value, the Y-axis coordinate value, and the Z-axis coordinate value.

[0091] In an optional embodiment, the X-axis coordinate value generating subunit is specifically configured to:

[0092] Subtracting a first preset stretching threshold from the attribute value of the first font stretching attribute to obtain a first stretching difference;

[0093] The first stretching difference is multiplied by a second preset stretching threshold to obtain an X-axis coordinate value.

[0094] In an optional embodiment, the Y-axis coordinate value generating subunit is specifically configured to:

[0095] The attribute value of the first font style attribute is multiplied by a preset style threshold to obtain a Y-axis coordinate value.

[0096] In an optional embodiment, the Z-axis coordinate value generating subunit is specifically configured to:

[0097] Subtracting a first preset thickness threshold from the attribute value of the first font thickness attribute to obtain a first thickness difference;

[0098] Dividing the first thickness difference by a second preset thickness threshold to obtain a first thickness quotient;

[0099] The first thickness quotient is multiplied by a third preset thickness threshold to obtain a Z-axis coordinate value.

[0100] In an optional embodiment, the font matching submodule specifically includes:

[0101] a commonly used font selection unit, configured to select a commonly used font ranked first from the commonly used font sorting result;

[0102] The font matching unit is used to determine the first-ranked commonly used font as a target font that matches the text.

[0103] In an optional implementation, the font matching unit is specifically configured to:

[0104] Finding a target distance between a top-ranked common font and the source font from among all the distances;

[0105] Determining whether the target distance exceeds a first preset distance threshold, and whether the first-ranked commonly used font contains the glyph in the source font;

[0106] If the target distance does not exceed a first preset distance threshold and the first-ranked commonly used font includes the glyph in the source font, the first-ranked commonly used font is determined as the target font matching the text.

[0107] In an optional embodiment, the device further comprises:

[0108] a list acquisition module, configured to acquire a font alias whitelist when no target font matching the text is found in at least one of the commonly used fonts;

[0109] A first font determination module is used to determine a target font that matches the text according to the font alias whitelist;

[0110] a list acquisition module, configured to acquire a candidate font list when no target font matching the text is found according to the font alias whitelist;

[0111] The second font determination module is configured to determine a target font that matches the text from the candidate fonts in the candidate font list.

[0112] In an optional implementation, the first font determination module specifically includes:

[0113] an alias search submodule, configured to obtain a font name or a font cluster name of the source font, and search the font alias whitelist for a font name or a font cluster name corresponding to the font name or the font cluster name;

[0114] The font determination submodule is configured to determine the font corresponding to the font alias as a target font that matches the text.

[0115] In an optional implementation, the font determination submodule is specifically configured to:

[0116] Acquire a first font bold attribute and / or a first font italic attribute of the source font, and a second font bold attribute and / or a second font italic attribute of the font corresponding to the font alias;

[0117] In a case where the first font bold attribute is the same as the second font bold attribute and / or the first font italic attribute is the same as the second font italic attribute, determining whether the font corresponding to the font alias includes a glyph in the source font;

[0118] In a case where the font corresponding to the font alias includes glyphs in the source font, the font corresponding to the font alias is determined as a target font that matches the text.

[0119] In an optional implementation, the second font determination module specifically includes:

[0120] a font screening submodule, configured to screen out at least one candidate font from the candidate font list, wherein the candidate font includes glyphs in the source font;

[0121] an appearance attribute acquisition submodule, configured to acquire a first font appearance attribute of the source font, and for any candidate font, acquire a second font appearance attribute of the candidate font;

[0122] a feature distance determination submodule, configured to determine a feature distance between the source font and the candidate font based on the first font appearance attribute and the second font appearance attribute;

[0123] a candidate font sorting submodule, configured to sort at least one candidate font according to all the feature distances to obtain a candidate font sorting result;

[0124] The second font determination submodule is configured to determine a target font that matches the text from at least one candidate font according to the candidate font sorting result.

[0125] In an optional embodiment, the number of the first font appearance attributes and the number of the second font appearance attributes are both M, where M is a positive integer; and the feature distance determination submodule is specifically configured to:

[0126] Inputting the i-th first font appearance attribute and the corresponding i-th second font appearance attribute into the following formula to obtain the characteristic distance between the source font and the candidate font, where i is 1, 2, 3, ..., M in sequence;

[0127] Cost=sqrt(Sum_i((Ri-Ai)^2*Wi)); the Cost is the feature distance, the Ri is the i-th first font appearance attribute, the Ai is the i-th second font appearance attribute, and the Wi is the weight corresponding to the i-th first font appearance attribute and the i-th second font appearance attribute.

[0128] In an optional implementation, the second font determination submodule specifically includes:

[0129] A candidate font selection unit, configured to select the top-ranked candidate font from the candidate font ranking results;

[0130] The font determination unit is configured to determine the candidate font ranked first as the target font matching the text.

[0131] In an optional implementation, the font determination unit is specifically configured to:

[0132] Finding a target feature distance between the candidate font ranked first and the source font from all the feature distances;

[0133] When the target feature distance does not exceed a second preset distance threshold, the candidate font ranked first is determined as the target font that matches the text.

[0134] In an optional implementation, the font determination unit is further configured to:

[0135] When the target feature distance exceeds a second preset distance threshold, a default font is determined as a target font that matches the text, wherein the default font includes glyphs in the source font.

[0136] In an optional embodiment, the document containing the text is a layout document, the text is a character at any position in the layout document, and the number of characters is at least one, and the device further includes:

[0137] The subsequent character font matching module is used to match the fonts of subsequent characters of the text after the font matching of the text is completed, including:

[0138] Determine the font distance between the mth character and the previous character in the document containing the text, where m is a positive integer greater than or equal to 2;

[0139] When the font distance is less than the distance threshold, determining a matching font for the mth character based on a matching font for a previous character;

[0140] When the font distance is greater than the distance threshold, a matching font for the mth character is determined based on a font matching method.

[0141] In a third aspect of the embodiments of the present application, an electronic device is further provided, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other via the communication bus;

[0142] Memory for storing computer programs;

[0143] The processor is configured to implement any one of the font matching methods described in the first aspect when executing a program stored in the memory.

[0144] In a fourth aspect of the embodiments of the present application, a storage medium is further provided, wherein instructions are stored in the storage medium, and when the instructions are executed on a computer, the computer executes any font matching method described in the first aspect above.

[0145] In a fifth aspect of the embodiments of the present application, a computer program product comprising instructions is further provided, which, when executed on a computer, enables the computer to execute any of the above-mentioned font matching methods.

[0146] The technical solution provided by the embodiment of the present application obtains text presented in a source font, and obtains the first basic font attributes of the source font, obtains at least one commonly used font, and obtains the second basic font attributes of each of the commonly used fonts, and determines the target font that matches the text from at least one of the commonly used fonts based on the first basic font attributes and the second basic font attributes.

[0147] By obtaining the first basic font attribute of the source font and the second basic font attribute of at least one commonly used font, a target font that matches the text is determined from at least one of the commonly used fonts based on the first basic font attribute and the second basic font attribute. In this way, font matching is performed among commonly used fonts to achieve better matching effect and matching performance, while taking into account both matching effect and matching performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0148] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0149] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0150] One or more embodiments are exemplarily illustrated by pictures in the corresponding drawings. These exemplifications do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings are represented as similar elements. Unless otherwise stated, the figures in the drawings do not constitute proportional limitations.

[0151] Figure 1 This is a schematic diagram of an implementation flow of a font matching method shown in an embodiment of the present application;

[0152] Figure 2 This is a schematic diagram of an implementation flow of another font matching method shown in an embodiment of the present application;

[0153] Figure 3 This is a schematic diagram of an implementation flow of another font matching method shown in an embodiment of the present application;

[0154] Figure 4 This is a schematic diagram of an implementation flow of another font matching method shown in an embodiment of the present application;

[0155] Figure 5 This is a structural diagram of a font matching device shown in an embodiment of the present application;

[0156] Figure 6 This is a schematic structural diagram of an electronic device shown in an embodiment of the present application. DETAILED DESCRIPTION

[0157] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0158] The disclosure below provides many different embodiments or examples for implementing different structures of the present application. In order to simplify the disclosure of the present application, the components and settings of specific examples are described below. Of course, these are merely examples and are not intended to limit the present application. In addition, the present application may repeat reference numbers and / or letters in different examples. Such repetition is for the purpose of simplicity and clarity and does not in itself indicate the relationship between the various embodiments and / or settings discussed.

[0159] like Figure 1 FIG. 1 is a schematic diagram of an implementation flow of a font matching method provided in an embodiment of the present application. The method is applied to an electronic device and may specifically include the following steps:

[0160] S101: Acquire text presented in a source font, and acquire a first basic font attribute of the source font.

[0161] In an embodiment of the present application, for a document presented in a specific font, when the document faces cross-platform / device display, document conversion (such as converting a layout document to a streaming document), and the need to avoid copyright risks, if the device or software does not support the original specific font of the document, it is necessary to quickly find the most suitable alternative font for these unsupported fonts, and then display the document with the alternative font.

[0162] To this end, text presented in a source font is obtained. The text originates from the document. The text may be a character at any position in the document, with at least one character, or a line or lines of text, or a paragraph or paragraphs. Of course, the text may also be all the text in the document, which is not limited in this embodiment of the present application. The source font may be, for example, Songti.

[0163] For example, if a document rendered in a specific font is being converted, such as a PDF document being converted to a Word document, and the device or software doesn't support the document's original font, it's necessary to quickly find the most suitable replacement font for the unsupported font and then display the document in the replacement font. To do this, obtain the text rendered in the original font, which is derived from the PDF document.

[0164] Furthermore, in the embodiments of the present application, a font typically has several basic font attributes, such as a font stretch attribute, a font style attribute, and a font weight attribute. When more basic font attributes are selected for font matching, the font matching effect is better but the font matching performance is worse. Conversely, the font matching effect is worse but the font matching performance is better. Therefore, it is necessary to select an appropriate number of basic font attributes for font matching to balance the font matching effect and font matching performance.

[0165] Based on this, in an embodiment of the present application, for the source font, the first basic font attribute of the source font is obtained. For the first basic font attribute, in an embodiment of the present application, three relatively important basic font attributes may be included, such as the first font stretching attribute (for example, the first font stretching attribute takes the value of normal, so that the font maintains a standard width), the first font style attribute (for example, the first font style attribute takes the value of italic, so that the font is displayed in an italic style), and the first font weight attribute (for example, the first font weight attribute takes the value of 400, which is equivalent to normal, representing a font of standard weight). In this way, when participating in font matching subsequently, both the font matching effect and the font matching performance can be taken into account.

[0166] S102: Acquire at least one commonly used font, and acquire a second font basic attribute of each commonly used font.

[0167] In the embodiments of this application, commonly used fonts refer to font types that are widely used and well-known in various scenarios such as daily writing, typesetting and printing, electronic documents, and web design. Among them, commonly used fonts can be directly preset according to needs. The following are some common commonly used fonts: Songti, Heiti, Kaiti, Fangsongti, Times New Roman, etc.

[0168] Thus, at least one commonly used font can be obtained, and the second basic font attributes of each commonly used font can be obtained. The second basic font attributes, similar to the first basic font attributes, can also include three relatively important basic font attributes, such as a second font stretch attribute, a second font style attribute, and a second font weight attribute. The second basic font attributes are the same as the first basic font attributes; the same attributes include the same number and type.

[0169] It should be noted that for commonly used fonts, there are a large number of them, so some commonly used fonts and their second font basic attributes can be pre-loaded in the memory. In one embodiment of the present application, the memory usage of the current system can be detected within a preset time. When the memory usage of other functions (i.e., the remaining functions except the font matching function) is high (the memory usage reaches a preset first usage threshold), according to the priority of the commonly used fonts, a part of the commonly used fonts is released from the memory, so that the memory usage of the current system is lower than the first usage threshold, and the second font basic attributes of the corresponding commonly used fonts are also released; on the contrary, when the memory usage of other functions is low (the memory usage is lower than the preset second usage threshold), according to the priority of the commonly used fonts, based on the memory usage, a part of the commonly used fonts is selected to be loaded into the memory, so that the memory usage of the current system is higher than the second usage threshold or meets the number of commonly used fonts loaded, and the second font basic attributes of the corresponding commonly used fonts are also loaded into the memory. In this way, according to the current memory usage and the priority of the commonly used fonts, the commonly used fonts and their second font basic attributes stored in the memory are dynamically adjusted, which can strengthen the font matching requirements while taking into account the system performance. Among them, the preset time can be a fixed time set in advance or the time when the system's memory usage is detected to change, which is not limited in this application. The second usage threshold is less than the first usage threshold.

[0170] S103: Determine a target font that matches the text from at least one commonly used font based on the first basic font attribute and the second basic font attribute.

[0171] In an embodiment of the present application, through the above steps, the second basic font attributes of each commonly used font and the first basic font attributes of the source font can be obtained, and the target font that matches the text can be determined from at least one commonly used font based on the first basic font attributes and the second basic font attributes.

[0172] Among them, for at least one commonly used font obtained above, the difference between the second font basic attribute of the commonly used font and the first font basic attribute of the source font can be compared, and then a commonly used font that is similar to the source font can be selected as the target font that matches the text. This embodiment of the present application does not limit this.

[0173] Furthermore, it should be noted that due to common writing habits, a paragraph or line of text in a document typically uses the same font. Therefore, after determining the target font that matches the text, the next text consisting of several characters after the text can directly use the currently matched target font. This embodiment of the application does not limit this.

[0174] Through the above description of the technical solution provided in the embodiment of the present application, text presented in a source font is obtained, and the first basic font attributes of the source font are obtained, at least one commonly used font is obtained, and the second basic font attributes of each of the commonly used fonts are obtained, and based on the first basic font attributes and the second basic font attributes, a target font that matches the text is determined from at least one of the commonly used fonts.

[0175] By obtaining the first basic font attribute of the source font and the second basic font attribute of at least one commonly used font, a target font that matches the text is determined from at least one of the commonly used fonts based on the first basic font attribute and the second basic font attribute. In this way, font matching is performed among commonly used fonts to achieve better matching effect and matching performance, while taking into account both matching effect and matching performance.

[0176] In an embodiment of the present application, for the second basic font attribute of the commonly used font and the first basic font attribute of the source font, the distance and dot product between the commonly used font and the source font can be calculated, and the commonly used fonts can be sorted according to the distance and dot product. Based on the commonly used font sorting results, the target font that matches the text can be determined from the commonly used fonts.

[0177] Based on this, Figure 2 FIG. 1 is a schematic diagram of an implementation flow of another font matching method provided in an embodiment of the present application. The method is applied to an electronic device and may specifically include the following steps:

[0178] S201: Acquire text presented in a source font, and acquire a first basic font attribute of the source font.

[0179] In the embodiment of the present application, this step is similar to the above-mentioned step S101, and the embodiment of the present application will not be described in detail here.

[0180] S202: Acquire at least one commonly used font, and acquire a second basic font attribute of each commonly used font.

[0181] In the embodiment of the present application, this step is similar to the above-mentioned step S102, and the embodiment of the present application will not be repeated here.

[0182] S203: Determine the distance and dot product between each commonly used font and the source font according to the first font basic attribute and the second font basic attribute.

[0183] In an embodiment of the present application, after the above steps, the first basic font attributes of the source font and the second basic font attributes of each commonly used font can be obtained, thereby determining the distance and dot product between each commonly used font and the source font based on the first basic font attributes and these second basic font attributes.

[0184] For any commonly used font, the distance and dot product between the commonly used font and the source font are determined according to the second basic font attribute of the commonly used font and the first basic font attribute of the source font.

[0185] To calculate the distance and dot product between the commonly used font and the source font, the font coordinates of the source font and the font coordinates of the commonly used font may be constructed, and the distance and dot product between the font coordinates may be calculated as the distance and dot product between the commonly used font and the source font.

[0186] Based on this, for the first font basic attribute of the source font, the first font coordinates corresponding to the source font are constructed based on the first font basic attribute. For any commonly used font, the second font coordinates corresponding to the commonly used font are constructed based on the second font basic attribute. Based on the first font coordinates and the second font coordinates, the distance and dot product between the commonly used font and the source font are determined. For the calculation method of the distance and dot product, reference can be made to existing methods, and the embodiments of this application will not be repeated here.

[0187] Font coordinates are usually three-dimensional coordinates, so three basic font attributes are needed to construct the font coordinates. Among them, the three more important basic font attributes are selected, namely font stretch attribute, font style attribute, and font weight attribute, which are not limited in the embodiments of this application.

[0188] Based on this, the first font basic attributes include a first font stretch attribute, a first font style attribute, and a first font weight attribute. Based on the first font stretch attribute, the first font style attribute, and the first font weight attribute, first font coordinates corresponding to the source font are constructed. The first font coordinates corresponding to the source font include an X-axis coordinate value, a Y-axis coordinate value, and a Z-axis coordinate value.

[0189] Specifically, the attribute value of the first font stretch attribute is processed to obtain the X-axis coordinate value, the attribute value of the first font style attribute is processed to obtain the Y-axis coordinate value, and the attribute value of the first font thickness attribute is processed to obtain the Z-axis coordinate value. According to the X-axis coordinate value, the Y-axis coordinate value, and the Z-axis coordinate value, the first font coordinate corresponding to the source font is constructed.

[0190] In addition, it should be noted that the above-mentioned X-axis coordinate value, Y-axis coordinate value, and Z-axis coordinate value can be replaced with each other. For example, the X-axis coordinate value is used as the Y-axis coordinate value, the Y-axis coordinate value is used as the Z-axis coordinate value, and the Z-axis coordinate value is used as the X-axis coordinate value. In this way, the first font coordinate corresponding to the source font is constructed. The embodiment of the present application is not limited to this.

[0191] Similarly, the second basic font attributes include a second font stretch attribute, a second font style attribute, and a second font weight attribute. Based on the second font stretch attribute, the second font style attribute, and the second font weight attribute, the second font coordinates corresponding to the commonly used font are constructed. The second font coordinates corresponding to the commonly used font include an X-axis coordinate value, a Y-axis coordinate value, and a Z-axis coordinate value.

[0192] Specifically, the attribute value of the second font stretch attribute is processed to obtain the X-axis coordinate value, the attribute value of the second font style attribute is processed to obtain the Y-axis coordinate value, and the attribute value of the second font thickness attribute is processed to obtain the Z-axis coordinate value. According to the X-axis coordinate value, the Y-axis coordinate value, and the Z-axis coordinate value, the second font coordinate corresponding to the commonly used font is constructed.

[0193] In addition, it should be noted that the X-axis coordinate value, Y-axis coordinate value, and Z-axis coordinate value here can be replaced with each other. For example, the X-axis coordinate value can be used as the Y-axis coordinate value, the Y-axis coordinate value can be used as the Z-axis coordinate value, and the Z-axis coordinate value can be used as the X-axis coordinate value. In this way, the second font coordinate corresponding to the commonly used font is constructed. The embodiment of this application is not limited to this.

[0194] Among them, the attribute value of the first font stretch attribute is processed, specifically: the attribute value of the first font stretch attribute is subtracted from the first preset stretch threshold to obtain a first stretch difference, and the first stretch difference is multiplied by the second preset stretch threshold to obtain the X-axis coordinate value. The above-mentioned processing process of the attribute value of the first font stretch attribute is organized into a formula, for example, FontAttrVec.X = (stretch-first preset stretch threshold) * second preset stretch threshold, wherein FontAttrVec.X is the X-axis coordinate value, stretch is the attribute value of the first font stretch attribute, the first preset stretch threshold can be 5, and the second preset stretch threshold can be 11. Similarly, the processing process for the attribute value of the second font stretch attribute is similar, and the embodiments of the present application will not be repeated here.

[0195] The attribute value of the first font style attribute is processed, specifically by multiplying the attribute value of the first font style attribute by a preset style threshold to obtain a Y-axis coordinate value. The above-mentioned processing of the attribute value of the first font style attribute can be organized into a formula, for example, FontAttrVec.Y = style * preset style threshold, where FontAttrVec.Y is the Y-axis coordinate value, style is the attribute value of the first font style attribute, and the preset style threshold can be 7. Similarly, the processing of the attribute value of the second font style attribute is similar and will not be further described in detail in this embodiment of the present application.

[0196] The attribute value of the first font weight attribute is processed, specifically: the attribute value of the first font weight attribute is subtracted from the first preset weight threshold to obtain a first weight difference, the first weight difference is divided by the second preset weight threshold to obtain a first weight quotient, and the first weight quotient is multiplied by the third preset weight threshold to obtain a Z-axis coordinate value. The above-mentioned processing of the attribute value of the first font weight attribute is organized into a formula, for example, FontAttrVec.Z = (weight-first preset weight threshold) / second preset weight threshold*third preset weight threshold, FontAttrVec.Z is the Z-axis coordinate value, weight is the attribute value of the first font weight attribute, the first preset weight threshold can be 400, the second preset weight threshold can be 100, and the third preset weight threshold can be 5. Similarly, the processing process for the attribute value of the second font weight attribute is similar, and the embodiments of the present application will not be repeated here.

[0197] S204: Sort at least one commonly used font according to the distance and the dot product to obtain a commonly used font sorting result.

[0198] In an embodiment of the present application, after the above steps, for any commonly used font, there is a distance and dot product between it and the source font. Therefore, at least one commonly used font can be sorted according to these distances and dot products to obtain a commonly used font sorting result.

[0199] It should be noted that distance can be used to prioritize sorting at least one commonly used font from smallest to largest. During the sorting process, if common fonts with the same distance are encountered, dot product can be used to further sort them from smallest to largest. If common fonts with the same dot product are encountered, the distances along the three axes (XYZ, YZX, or ZYX) are compared in order to sort them from smallest to largest. The order of comparison of XYZ is not limited here.

[0200] For example, if you encounter a common font with the same distance and dot product, you can calculate the X-axis difference, Y-axis difference, and Z-axis difference between the second font coordinate of the common font and the first font coordinate of the source font, and prioritize sorting them from small to large according to the X-axis difference. If the X-axis differences are the same, then sort them from small to large according to the Y-axis difference, and so on.

[0201] S205 : Determine a target font that matches the text from at least one common font according to the common font sorting result.

[0202] In the embodiment of the present application, after the above steps, the commonly used fonts are sorted, and a commonly used font sorting result can be obtained, so that a target font that matches the text is determined from at least one commonly used font based on the commonly used font sorting result.

[0203] Among them, the most commonly used font can be selected from the commonly used font sorting results and determined as the target font for text matching. In this way, font matching among commonly used fonts can achieve better matching effect and matching performance, while taking into account both matching effect and matching performance.

[0204] Furthermore, if the top-ranked commonly used font is not significantly different from the source font, it will be selected as the target font for text matching, achieving better matching results and performance. However, if the top-ranked commonly used font is significantly different from the source font, selecting the top-ranked commonly used font as the target font for text matching will ensure matching performance, but not guarantee the matching results. Therefore, it is necessary to determine the top-ranked commonly used font to ensure that it is not significantly different from the source font.

[0205] Based on this, the target distance between the first-ranked commonly used font and the source font is found from all distances, and it is determined whether the target distance exceeds a first preset distance threshold (for example, the first preset distance threshold can be 10), and whether the first-ranked commonly used font contains the glyphs in the source font. If the target distance does not exceed the first preset distance threshold and the first-ranked commonly used font contains the glyphs in the source font, the first-ranked commonly used font is determined as the target font for text matching. In this way, font matching is performed among commonly used fonts, and the difference between the matched commonly used font and the source font is ensured to be small, which can achieve better matching effect and matching performance, while taking into account both matching effect and matching performance.

[0206] In addition, when the target distance exceeds the first preset distance threshold, and / or the first-ranked commonly used font does not contain the glyphs in the source font, it means that the difference between the first-ranked commonly used font and the source font is large, and font matching is performed among the commonly used fonts. The font matching fails, which means that the target font matching the text is not matched in at least one commonly used font. At this time, secondary font matching is required, that is, obtaining a font alias whitelist, and performing font matching based on the font alias whitelist to determine the target font matching the text.

[0207] It should be noted that the order of font matching is to first match the commonly used fonts. If no match is found, then match the fonts according to the font alias whitelist. This has the following advantages:

[0208] Prioritizing universality and compatibility: Common fonts are widely available and supported across various devices and software, but their naming may differ across platforms. Matching among commonly used fonts first ensures that text displays correctly and consistently across platforms and environments. This avoids issues like missing fonts, display anomalies, or confusing layouts caused by using uncommon fonts. It also prevents similar or identical fonts from being mismatched due to naming differences, ensuring universality and compatibility for documents, web pages, and other content.

[0209] Improve matching efficiency: Commonly used fonts are relatively few in number and are the most likely to be used. By matching within this smaller range first, you can quickly locate the appropriate font, reducing search and matching time and improving font matching efficiency. If you start by searching within a larger and more complex set, such as a whitelist of font aliases, the computational effort and matching time will increase.

[0210] Respecting user habits and design standards: Commonly used fonts tend to conform to popular aesthetics and design standards and, in most cases, can meet standard text display needs. Using commonly used fonts for matching first adheres to general design principles and user habits, resulting in a more visually harmonious and aesthetically pleasing text content. The font alias whitelist may contain specialized font aliases designed to meet specific design requirements. These aliases are used when commonly used fonts fail to meet specific requirements. This allows for flexible adaptation to personalized design needs while maintaining basic design results.

[0211] Reduce font management complexity: Prioritizing commonly used fonts helps simplify font management. Because commonly used fonts are provided by default by the system or software, there's no need for extensive font installation and management. Only when commonly used fonts are insufficient will you need to use a font alias whitelist to introduce specialized fonts. This avoids installing too many uncommon fonts in the system, reducing font management complexity and system resource usage.

[0212] Based on this, Figure 3 FIG. 1 is a schematic diagram of an implementation flow of another font matching method provided in an embodiment of the present application. The method is applied to an electronic device and may specifically include the following steps:

[0213] S301 : When no target font matching the text is found in at least one commonly used font, obtain a font alias whitelist.

[0214] In an embodiment of the present application, when the target distance exceeds a first preset distance threshold, and / or the first-ranked commonly used font does not contain a glyph in the source font, it indicates that the first-ranked commonly used font is significantly different from the source font, and font matching fails among the commonly used fonts, meaning that a target font matching the text is not found in at least one commonly used font. In this case, secondary font matching is required. For this purpose, a font alias whitelist is obtained.

[0215] It should be noted that the same font may have different names on different devices or software. For example, "Microsoft YaHei" may be called "MS YaHei" on some devices. Therefore, fonts may have aliases. Based on the common names and aliases of fonts, a font alias whitelist can be created, which records the common names and aliases of fonts.

[0216] S302: Determine a target font that matches the text based on the font alias whitelist.

[0217] In the embodiment of the present application, the target font that matches the text is determined based on the font alias whitelist obtained in the above step, wherein the font alias whitelist records the common name and alias of the font.

[0218] Thus, the font name or font cluster name of the source font is obtained, the font alias corresponding to the font name or font cluster name is searched in the font alias whitelist, and the font corresponding to the font alias is determined as the target font that matches the text.

[0219] In addition, in order to minimize the difference between the font corresponding to the font alias and the source font, it is also necessary to compare whether the bold attributes and / or italic attributes are consistent, and whether the font corresponding to the font alias contains the glyphs in the source font.

[0220] Based on this, the first font bold attribute and / or the first font italic attribute of the source font, and the second font bold attribute and / or the second font italic attribute of the font corresponding to the font alias are obtained. When the first font bold attribute is the same as the second font bold attribute and / or the first font italic attribute is the same as the second font italic attribute, it is determined whether the font corresponding to the font alias contains the glyphs in the source font. When the font corresponding to the font alias contains the glyphs in the source font, the font corresponding to the font alias is determined as the target font that matches the text.

[0221] In addition, in the embodiment of the present application, the above-mentioned secondary font matching may fail, that is, the difference between the font corresponding to the font alias and the source font is too large, in which case a tertiary Panose font matching is required. In the tertiary Panose font matching, a fine font matching is required, that is, based on the font appearance attributes, the feature distance between the candidate font and the source font is calculated, the candidate fonts are sorted according to the feature distance, and based on the sorting result, the target font that matches the text is determined.

[0222] Based on this, Figure 4 FIG. 1 is a schematic diagram of an implementation flow of another font matching method provided in an embodiment of the present application. The method is applied to an electronic device and may specifically include the following steps:

[0223] S401 : When no target font matching the text is found according to the font alias whitelist, a candidate font list is obtained.

[0224] In an embodiment of the present application, when at least one of the following conditions is met, it means that the target font that matches the text is not matched according to the font alias whitelist. At this time, a third-level Panose font matching is required, that is, obtaining a candidate font list, which includes fonts supported by the current device or software.

[0225] Condition 1: The font alias corresponding to the font name or font cluster name is not found in the font alias whitelist;

[0226] Condition 2: The bold attribute of the first font is different from the bold attribute of the second font;

[0227] Condition 3: the first font italic attribute is different from the second font italic attribute;

[0228] Condition 4: The font corresponding to the font alias does not contain the glyphs in the source font.

[0229] S402: Determine a target font that matches the text from the candidate fonts in the candidate font list.

[0230] In an embodiment of the present application, for the candidate font list obtained in the above steps, a target font matching the text can be determined from the candidate fonts in the candidate font list. The fonts in the candidate font list can be first screened according to the glyphs in the source fonts, and then the feature distance between the source fonts and the screened fonts can be calculated based on the font appearance attributes. The screened fonts can be sorted based on the feature distance, and the target font matching the text can be determined based on the sorting result.

[0231] Based on this, at least one candidate font is screened out from the candidate font list, wherein the candidate font contains glyphs in the source font; a first font appearance attribute of the source font is obtained, and for any candidate font, a second font appearance attribute of the candidate font is obtained; based on the first font appearance attribute and the second font appearance attribute, a feature distance between the source font and the candidate font is determined; based on all feature distances, at least one candidate font is sorted to obtain a candidate font sorting result; based on the candidate font sorting result, a target font that matches the text is determined from at least one candidate font.

[0232] The number of the first font appearance attributes and the number of the second font appearance attributes are both M, and M is a positive integer. For example, the first font appearance attribute and the second font appearance attribute both include the following 10 font appearance attributes in Panose:

[0233] Family Type: Used to specify the main category of the font, such as serif fonts, sans serif fonts, handwriting fonts, etc.

[0234] Serif Style: Describes the decorative style at the end of the font strokes, including sans serif, thin serif, thick serif, etc.

[0235] Weight: refers to the thickness of the font, such as light, normal, bold, extra bold, etc.

[0236] Proportion: Indicates the aspect ratio of the font, including normal ratio, narrow ratio, wide ratio, etc.

[0237] Contrast: Describes the degree of contrast between the thickness of the font strokes, ranging from low contrast to high contrast.

[0238] Stroke Endings: The shape and style of the ends of the strokes in a font, such as square, round, pointed, etc.

[0239] Connector Styles: Used to describe the style of the stroke connectors in a font, such as solid connectors, disconnected connectors, rounded connectors, etc.

[0240] Slant: The tilt angle of the font, usually with options such as upright, italic, and oblique.

[0241] Stem Weight: The thickness of the main strokes. It is related to the overall weight, but focuses more on the characteristics of the main strokes.

[0242] Character Spacing: The spacing between characters, including tight, normal, loose, etc.

[0243] Thus, the characteristic distance between the source font and the candidate font is determined based on the first and second font appearance attributes. Specifically, the characteristic distance between the source font and the candidate font can be obtained by inputting the i-th first font appearance attribute and the corresponding i-th second font appearance attribute into the following formula, where i is 1, 2, 3, ..., M; Cost = sqrt(Sum_i((Ri-Ai)^2*Wi)); Cost is the characteristic distance, Ri is the i-th first font appearance attribute, Ai is the i-th second font appearance attribute, and Wi is the weight corresponding to the i-th first font appearance attribute and the i-th second font appearance attribute. Sum is the sum, and sqrt is the square root.

[0244] The above formula means that for any first font appearance attribute and the corresponding second font appearance attribute, the difference between the two is calculated, then squared, and multiplied by a weight to obtain a corresponding result. Then, all the results are summed and the square root is taken to obtain the final feature distance between the source font and the candidate font.

[0245] For the candidate font ranking results, the candidate font ranked first may be selected from the candidate font ranking results, and the candidate font ranked first may be determined as the target font for text matching.

[0246] In order to avoid excessive differences between the first-ranked candidate font and the source font, the target feature distance between the first-ranked candidate font and the source font can also be found from all feature distances; when the target feature distance does not exceed the second preset distance threshold, the first-ranked candidate font is determined as the target font that matches the text.

[0247] In addition, in the above-mentioned three-level Panose font matching, the font matching may fail, that is, the target feature distance exceeds the second preset distance threshold, which means that the font matching fails. Therefore, when the target feature distance exceeds the second preset distance threshold, the default font (for example, the default font is Songti) is determined as the target font for text matching, wherein the default font contains the glyphs in the source font.

[0248] The above process first matches commonly used fonts. If no match is found, the font is matched against the font alias whitelist. If no match is found, the font is matched based on the font appearance attributes. If no match is found, the default font is used. This three-level font matching strategy optimizes the entire font matching process, greatly improving matching performance and effectiveness. This allows for quick replacement of unsupported fonts when displaying documents across platforms and devices, converting documents, and avoiding copyright risks.

[0249] When the document containing the text presented by the source font is a layout document, due to the storage characteristics of the layout document, if the conventional method is used, each character needs to be matched once. When the document contains a lot of content, such as 1,000 words, or even more content, it takes a long time to match to get the final matching result. Therefore, in order to improve the efficiency of font matching, in one embodiment of the present application, a PDF document is used as an example for explanation. After the font matching method in the above example is used to match the font of the first character in the document, the font matching of subsequent characters includes the following steps:

[0250] Determine the font distance between the mth character and the previous character in the document containing the text rendered in the source font; where m is a positive integer greater than or equal to 2 and is the number of characters in the document;

[0251] When the font distance between the m-th word and the previous word in the document containing the text presented in the source font is less than a distance threshold, determining a matching font for the m-th word based on the matching font of the previous word;

[0252] Alternatively, when the font distance between the m-th character and the previous character in the document containing the text presented in the source font is greater than a distance threshold, a matching font for the m-th character is determined based on the font matching method in the above embodiment, that is, based on the three-level font matching strategy in the above embodiment, a matching font for the m-th character is determined;

[0253] Alternatively, when the font distance between the m-th character and the previous character in the document containing the text presented in the source font is equal to a distance threshold, the matching font of the m-th character can be determined based on the matching font of the previous character, or the matching font of the m-th character can be determined based on the font matching method in the above embodiment, that is, the matching font of the m-th character can be determined according to the three-level font matching strategy in the above embodiment.

[0254] The step of determining whether the font distance between the mth character and the previous character in the document containing the text presented in the source font is less than a distance threshold comprises:

[0255] Respectively obtaining the coordinates of the mth character and the previous character in the document containing the text presented in the source font; calculating the distance between the two coordinates; when the distance between the two coordinates is less than a first threshold, determining that the font distance between the mth character and the previous character in the document containing the text presented in the source font is less than the distance threshold; or, when the distance between the two coordinates is greater than or equal to the first threshold, determining that the font distance between the mth character and the previous character in the document containing the text presented in the source font is greater than the distance threshold;

[0256] and / or,

[0257] Respectively obtain the indexes of the mth character and the previous character in the document containing the text rendered in the source font; when the indexes of the mth character and the previous character in the document containing the text rendered in the source font are consecutive indexes, determine whether the font distance between the mth character and the previous character in the document containing the text rendered in the source font is less than a distance threshold; or, when the indexes of the mth character and the previous character in the document containing the text rendered in the source font are not consecutive indexes, determine whether the font distance between the mth character and the previous character in the document containing the text rendered in the source font is greater than the distance threshold. Consecutive indexes refer to two index numbers being consecutive.

[0258] Specifically, respectively obtain the indexes of the mth character and the previous character in the document where the text presented by the source font is located; for example: when the index of the mth character in the document where the text presented by the source font is located is 2, and the index of the previous character is 1; determine that the indexes of the mth character and the previous character in the document where the text presented by the source font is located are consecutive indexes, and the fonts of the latter character and the previous character are of the same origin. At this time, judge that the font distance between the mth character and the previous character in the document where the text presented by the source font is located is less than a distance threshold; or, when the indexes of the mth character and the previous character in the document where the text presented by the source font is located are not consecutive indexes, judge that the font distance between the mth character and the previous character in the document where the text presented by the source font is located is greater than a distance threshold.

[0259] Wherein, when the font distance between the m-th word and the previous word in the document where the text presented in the source font is located is less than a distance threshold, determining the matching font of the m-th word based on the matching font of the previous word; including:

[0260] The matching font of the word preceding the m-th word in the document where the text presented by the source font is located is used as the matching font of the m-th word in the document where the text presented by the source font is located;

[0261] Alternatively, the matching font priority of the previous word is adjusted to the highest, and the font is used as the first matching font to match the font of the m-th word in the document where the text presented by the source font is located; if the match is successful, the matching font of the previous word of the m-th word in the document where the text presented by the source font is located is used as the matching font of the m-th word in the document where the source font is located; if the match is unsuccessful, continue to match the remaining at least one commonly used font.

[0262] Specifically, when a PDF document contains 10,000 words, the first word is a text and is matched as Songti. When the font distance between the second word and the first word in the document where the text presented by the source font is located is less than the distance threshold, Songti can be directly used as the matching font for the second word; or, the priority of Songti is adjusted to the highest, and the font matching of the second word is prioritized. If the match is successful, Songti is used as the matching font for the second word in the document where the text presented by the source font is located; if the match is unsuccessful, continue to match at least one of the remaining commonly used fonts. And so on, matching the words in the PDF document can improve the matching efficiency.

[0263] If the matching is unsuccessful, the method further includes:

[0264] When no matching font matching the mth character in the document where the source font is located is found in at least one commonly used font, obtaining a font alias whitelist;

[0265] Determine, based on the font alias whitelist, a matching font that matches the mth character in the document where the source font is located;

[0266] If no matching font matching the mth character in the document where the source font is located is found according to the font alias whitelist, obtaining a candidate font list;

[0267] A matching font that matches the mth character in the document where the source font is located is determined from the candidate fonts in the candidate font list.

[0268] Corresponding to the above method embodiment, the embodiment of the present application also provides a font matching device, such as Figure 5 As shown, the device may include: a text acquisition module 510 , an attribute acquisition module 520 , and a font matching module 530 .

[0269] A text acquisition module 510 is configured to acquire text presented in a source font and acquire a first basic font attribute of the source font;

[0270] The attribute acquisition module 520 is configured to acquire at least one commonly used font and acquire a second font basic attribute of each commonly used font;

[0271] The font matching module 530 is configured to determine a target font that matches the text from at least one of the commonly used fonts based on the first font basic attributes and the second font basic attributes.

[0272] In an optional implementation, the font matching module specifically includes:

[0273] a distance and dot product determination submodule, configured to determine the distance and dot product between each of the commonly used fonts and the source font based on the first font basic attributes and the second font basic attributes;

[0274] a common font sorting submodule, configured to sort at least one of the common fonts according to the distance and the dot product to obtain a common font sorting result;

[0275] a font matching submodule, configured to determine a target font that matches the text from at least one of the commonly used fonts according to the commonly used font sorting result;

[0276] The distance and dot product determination submodule specifically includes:

[0277] A first font coordinate construction unit, configured to construct first font coordinates corresponding to the source font according to the first font basic attributes;

[0278] A second font coordinate construction unit, configured to construct, for any of the commonly used fonts, second font coordinates corresponding to the commonly used font according to the second font basic attributes;

[0279] A distance and dot product determining unit is configured to determine a distance and a dot product between the commonly used font and the source font according to the first font coordinates and the second font coordinates.

[0280] In an optional embodiment, the first basic font attributes include a first font stretch attribute, a first font style attribute, and a first font weight attribute; the first font coordinate construction unit is specifically configured to: construct first font coordinates corresponding to the source font according to the first basic font attributes;

[0281] The first font coordinate construction unit specifically includes:

[0282] An X-axis coordinate value generating subunit is used to process the attribute value of the first font stretch attribute to obtain an X-axis coordinate value;

[0283] A Y-axis coordinate value generating subunit, configured to process the attribute value of the first font style attribute to obtain a Y-axis coordinate value;

[0284] A Z-axis coordinate value generating subunit is used to process the attribute value of the first font weight attribute to obtain a Z-axis coordinate value;

[0285] The first font coordinate construction subunit is configured to construct first font coordinates corresponding to the source font according to the X-axis coordinate value, the Y-axis coordinate value, and the Z-axis coordinate value.

[0286] In an optional embodiment, the X-axis coordinate value generating subunit is specifically configured to:

[0287] Subtracting a first preset stretching threshold from the attribute value of the first font stretching attribute to obtain a first stretching difference;

[0288] The first stretching difference is multiplied by a second preset stretching threshold to obtain an X-axis coordinate value.

[0289] In an optional embodiment, the Y-axis coordinate value generating subunit is specifically configured to:

[0290] The attribute value of the first font style attribute is multiplied by a preset style threshold to obtain a Y-axis coordinate value.

[0291] In an optional embodiment, the Z-axis coordinate value generating subunit is specifically configured to:

[0292] Subtracting a first preset thickness threshold from the attribute value of the first font thickness attribute to obtain a first thickness difference;

[0293] Dividing the first thickness difference by a second preset thickness threshold to obtain a first thickness quotient;

[0294] The first thickness quotient is multiplied by a third preset thickness threshold to obtain a Z-axis coordinate value.

[0295] In an optional embodiment, the font matching submodule specifically includes:

[0296] a commonly used font selection unit, configured to select a commonly used font ranked first from the commonly used font sorting result;

[0297] The font matching unit is used to determine the first-ranked commonly used font as a target font that matches the text.

[0298] In an optional implementation, the font matching unit is specifically configured to:

[0299] Finding a target distance between a top-ranked common font and the source font from among all the distances;

[0300] Determining whether the target distance exceeds a first preset distance threshold, and whether the first-ranked commonly used font contains the glyph in the source font;

[0301] If the target distance does not exceed a first preset distance threshold and the first-ranked commonly used font includes the glyph in the source font, the first-ranked commonly used font is determined as the target font matching the text.

[0302] In an optional embodiment, the device further comprises:

[0303] a list acquisition module, configured to acquire a font alias whitelist when no target font matching the text is found in at least one of the commonly used fonts;

[0304] A first font determination module is used to determine a target font that matches the text according to the font alias whitelist;

[0305] a list acquisition module, configured to acquire a candidate font list when no target font matching the text is found according to the font alias whitelist;

[0306] The second font determination module is configured to determine a target font that matches the text from the candidate fonts in the candidate font list.

[0307] In an optional implementation, the first font determination module specifically includes:

[0308] an alias search submodule, configured to obtain a font name or a font cluster name of the source font, and search the font alias whitelist for a font name or a font cluster name corresponding to the font name or the font cluster name;

[0309] The font determination submodule is configured to determine the font corresponding to the font alias as a target font that matches the text.

[0310] In an optional implementation, the font determination submodule is specifically configured to:

[0311] Acquire a first font bold attribute and / or a first font italic attribute of the source font, and a second font bold attribute and / or a second font italic attribute of the font corresponding to the font alias;

[0312] In a case where the first font bold attribute is the same as the second font bold attribute and / or the first font italic attribute is the same as the second font italic attribute, determining whether the font corresponding to the font alias includes a glyph in the source font;

[0313] In a case where the font corresponding to the font alias includes glyphs in the source font, the font corresponding to the font alias is determined as a target font that matches the text.

[0314] In an optional embodiment, the device further comprises:

[0315] a list acquisition module, configured to acquire a candidate font list if the font alias corresponding to the font name or font cluster name is not found in the font alias whitelist, the first font bold attribute is different from the second font bold attribute, the first font italic attribute is different from the second font italic attribute, and / or the font corresponding to the font alias does not include a glyph in the source font;

[0316] The second font determination module is configured to determine a target font that matches the text from the candidate fonts in the candidate font list.

[0317] In an optional implementation, the second font determination module specifically includes:

[0318] a font screening submodule, configured to screen out at least one candidate font from the candidate font list, wherein the candidate font includes glyphs in the source font;

[0319] an appearance attribute acquisition submodule, configured to acquire a first font appearance attribute of the source font, and for any candidate font, acquire a second font appearance attribute of the candidate font;

[0320] a feature distance determination submodule, configured to determine a feature distance between the source font and the candidate font based on the first font appearance attribute and the second font appearance attribute;

[0321] a candidate font sorting submodule, configured to sort at least one candidate font according to all the feature distances to obtain a candidate font sorting result;

[0322] The second font determination submodule is configured to determine a target font that matches the text from at least one candidate font according to the candidate font sorting result.

[0323] In an optional embodiment, the number of the first font appearance attributes and the number of the second font appearance attributes are both M, where M is a positive integer; and the feature distance determination submodule is specifically configured to:

[0324] Inputting the i-th first font appearance attribute and the corresponding i-th second font appearance attribute into the following formula to obtain the characteristic distance between the source font and the candidate font, where i is 1, 2, 3, ..., M in sequence;

[0325] Cost=sqrt(Sum_i((Ri-Ai)^2*Wi)); the Cost is the feature distance, the Ri is the i-th first font appearance attribute, the Ai is the i-th second font appearance attribute, and the Wi is the weight corresponding to the i-th first font appearance attribute and the i-th second font appearance attribute.

[0326] In an optional implementation, the second font determination submodule specifically includes:

[0327] A candidate font selection unit, configured to select the top-ranked candidate font from the candidate font ranking results;

[0328] The font determination unit is configured to determine the candidate font ranked first as the target font matching the text.

[0329] In an optional implementation, the font determination unit is specifically configured to:

[0330] Finding a target feature distance between the candidate font ranked first and the source font from all the feature distances;

[0331] When the target feature distance does not exceed a second preset distance threshold, the candidate font ranked first is determined as the target font that matches the text.

[0332] In an optional implementation, the font determination unit is further configured to:

[0333] When the target feature distance exceeds a second preset distance threshold, a default font is determined as a target font that matches the text, wherein the default font includes glyphs in the source font.

[0334] In an optional embodiment, the document containing the text is a layout document, the text is a character at any position in the layout document, and the number of characters is at least one, and the device further includes:

[0335] The subsequent character font matching module is used to match the fonts of subsequent characters of the text after the font matching of the text is completed, including:

[0336] Determine the font distance between the mth character and the previous character in the document containing the text, where m is a positive integer greater than or equal to 2;

[0337] When the font distance is less than the distance threshold, determining a matching font for the mth character based on a matching font for a previous character;

[0338] When the font distance is greater than the distance threshold, a matching font for the mth character is determined based on a font matching method.

[0339] The present application also provides an electronic device, such as Figure 6 As shown, it includes a processor 61, a communication interface 62, a memory 63 and a communication bus 64, wherein the processor 61, the communication interface 62, and the memory 63 communicate with each other through the communication bus 64.

[0340] Memory 63, for storing computer programs;

[0341] The processor 61 is configured to execute the program stored in the memory 63 by performing the following steps:

[0342] Obtain text presented in a source font and obtain a first basic font attribute of the source font; obtain at least one commonly used font and obtain a second basic font attribute of each of the commonly used fonts; and determine a target font that matches the text from at least one of the commonly used fonts based on the first basic font attribute and the second basic font attribute.

[0343] The communication bus mentioned in the electronic device mentioned above may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. This communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is used in the figure, but this does not mean that there is only one bus or only one type of bus.

[0344] The communication interface is used for communication between the above electronic device and other devices.

[0345] The memory may include random access memory (RAM) or non-volatile memory, such as at least one disk storage. Alternatively, the memory may be at least one storage device located away from the processor.

[0346] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, and discrete hardware components.

[0347] In another embodiment provided by the present application, a storage medium is further provided. The storage medium stores instructions, which, when executed on a computer, enable the computer to execute any of the font matching methods described in the above embodiments.

[0348] In another embodiment provided by the present application, a computer program product including instructions is further provided, which, when executed on a computer, enables the computer to execute any of the font matching methods described in the above embodiments.

[0349] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When software is used for implementation, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a storage medium or transmitted from one storage medium to another. For example, the computer instructions can be transmitted from a website, computer, server or data center to another website, computer, server or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrations. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)).

[0350] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply the existence of any such actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.

[0351] Each embodiment in this specification is described in a related manner. Similar parts between the various embodiments can be referred to in conjunction with each other. Each embodiment focuses on the differences between the other embodiments. In particular, the system embodiment is generally similar to the method embodiment, so the description is relatively simple. For related parts, refer to the description of the method embodiment.

[0352] The above description is only a preferred embodiment of the present application and is not intended to limit the scope of protection of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application are included in the scope of protection of the present application.

Claims

1. A font matching method, characterized in that: The method comprises: Obtaining text rendered in a source font, and obtaining a first font basic attribute of the source font; Obtain at least one commonly used font, and obtain a second font basic attribute of each commonly used font; A target font matching the text is determined from at least one of the common fonts according to the first basic font attribute and the second basic font attribute.

2. The method according to claim 1, characterized in that Determining a target font matching the text from at least one of the commonly used fonts based on the first font basic attribute and the second font basic attribute includes: determining a distance and a dot product between each of the commonly used fonts and the source font according to the first font basic attribute and the second font basic attribute; sorting at least one of the commonly used fonts according to the distance and the dot product to obtain a commonly used font sorting result; Determining a target font that matches the text from at least one of the commonly used fonts according to the commonly used font sorting result; The determining of the distance and dot product between each of the commonly used fonts and the source font based on the first font basic attribute and the second font basic attribute includes: Constructing first font coordinates corresponding to the source font according to the first font basic attributes; For any of the commonly used fonts, constructing second font coordinates corresponding to the commonly used font according to the second font basic attributes; The distance and dot product between the commonly used font and the source font are determined according to the first font coordinates and the second font coordinates.

3. The method according to claim 2, characterized in that The first basic font attributes include a first font stretch attribute, a first font style attribute, and a first font weight attribute; constructing first font coordinates corresponding to the source font based on the first basic font attributes; The step of constructing first font coordinates corresponding to the source font according to the first font basic attributes includes: Processing the attribute value of the first font stretch attribute to obtain an X-axis coordinate value; Processing the attribute value of the first font style attribute to obtain a Y-axis coordinate value; Processing the attribute value of the first font weight attribute to obtain a Z-axis coordinate value; Construct first font coordinates corresponding to the source font according to the X-axis coordinate value, the Y-axis coordinate value, and the Z-axis coordinate value.

4. The method according to claim 3, characterized in that The processing of the attribute value of the first font stretch attribute to obtain the X-axis coordinate value includes: Subtracting a first preset stretching threshold from the attribute value of the first font stretching attribute to obtain a first stretching difference; The first stretching difference is multiplied by a second preset stretching threshold to obtain an X-axis coordinate value.

5. The method according to claim 3, characterized in that The processing of the attribute value of the first font style attribute to obtain the Y-axis coordinate value includes: The attribute value of the first font style attribute is multiplied by a preset style threshold to obtain a Y-axis coordinate value.

6. The method according to claim 3, characterized in that The processing of the attribute value of the first font weight attribute to obtain the Z-axis coordinate value includes: Subtracting a first preset thickness threshold from the attribute value of the first font thickness attribute to obtain a first thickness difference; Dividing the first thickness difference by a second preset thickness threshold to obtain a first thickness quotient; The first thickness quotient is multiplied by a third preset thickness threshold to obtain a Z-axis coordinate value.

7. The method according to claim 1, characterized in that The method further comprises: When no target font matching the text is found in at least one of the commonly used fonts, obtaining a font alias whitelist; Determining a target font that matches the text according to the font alias whitelist; If no target font matching the text is found according to the font alias whitelist, obtaining a candidate font list; A target font matching the text is determined from the candidate fonts in the candidate font list.

8. The method according to claim 7, characterized in that Determining a target font that matches the text according to the font alias whitelist includes: Obtaining a font name or font cluster name of the source font, and searching the font alias whitelist for a font alias corresponding to the font name or font cluster name; The font corresponding to the font alias is determined as the target font that matches the text.

9. The method according to claim 8, characterized in that The step of determining the font corresponding to the font alias as a target font matching the text includes: Acquire a first font bold attribute and / or a first font italic attribute of the source font, and a second font bold attribute and / or a second font italic attribute of the font corresponding to the font alias; In a case where the first font bold attribute is the same as the second font bold attribute and / or the first font italic attribute is the same as the second font italic attribute, determining whether the font corresponding to the font alias includes a glyph in the source font; In a case where the font corresponding to the font alias includes glyphs in the source font, the font corresponding to the font alias is determined as a target font that matches the text.

10. The method according to claim 7, characterized in that Determining a target font that matches the text from the candidate fonts in the candidate font list includes: Filtering at least one candidate font from the candidate font list, wherein the candidate font includes glyphs in the source font; Acquire a first font appearance attribute of the source font, and for any candidate font, acquire a second font appearance attribute of the candidate font; determining a feature distance between the source font and the candidate font according to the first font appearance attribute and the second font appearance attribute; sorting at least one candidate font according to all the feature distances to obtain a candidate font sorting result; According to the candidate font sorting result, a target font matching the text is determined from at least one candidate font.

11. The method according to claim 10, characterized in that The number of the first font appearance attributes and the number of the second font appearance attributes are both M, where M is a positive integer; The determining, based on the first font appearance attribute and the second font appearance attribute, a feature distance between the source font and the candidate font includes: Inputting the i-th first font appearance attribute and the corresponding i-th second font appearance attribute into the following formula to obtain the characteristic distance between the source font and the candidate font, where i is 1, 2, 3, ..., M in sequence; Cost=sqrt(Sum_i((Ri-Ai)^2*Wi)); the Cost is the feature distance, the Ri is the i-th first font appearance attribute, the Ai is the i-th second font appearance attribute, and the Wi is the weight corresponding to the i-th first font appearance attribute and the i-th second font appearance attribute.

12. The method according to any one of claims 1 to 11, characterized in that The document containing the text is a layout document, the text is a character at any position in the layout document, and the number of characters is at least one. After the font matching of the text is completed, the font matching of subsequent characters of the text includes: Determine the font distance between the mth character and the previous character in the document containing the text, where m is a positive integer greater than or equal to 2; When the font distance is less than the distance threshold, determining a matching font for the mth character based on a matching font for a previous character; When the font distance is greater than the distance threshold, a matching font for the mth character is determined based on a font matching method.

13. A font matching device, characterized in that: The device comprises: A text acquisition module, configured to acquire text presented in a source font and acquire a first basic font attribute of the source font; An attribute acquisition module, configured to acquire at least one commonly used font and acquire a second font basic attribute of each commonly used font; The font matching module is configured to determine a target font that matches the text from at least one of the commonly used fonts based on the first font basic attributes and the second font basic attributes.