A method, apparatus and storage medium for identifying a font language
By obtaining font attributes and Unicode encoding values to identify the font language, the problem of incomplete font language recognition on the Linux platform by the FontConfig library is solved, achieving accurate font language recognition across platforms and improving user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHUHAI KINGSOFT OFFICE SOFTWARE
- Filing Date
- 2021-06-25
- Publication Date
- 2026-05-29
AI Technical Summary
Windows platforms cannot effectively identify the language of fonts through the FontConfig library, resulting in a poor user experience on Linux platforms.
By obtaining the font attributes of the font to be identified, including the font name, language, and Unicode encoding value, and combining them with the preset correspondence, the language supported by the font can be identified, thus solving the problem of incomplete recognition by the FontConfig library.
Accurately identifying the language of the font on different operating systems improves the user experience and ensures consistent font selection across different systems.
Smart Images

Figure CN115526168B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to, but is not limited to, the field of computers, and in particular to a method, apparatus, and storage medium for identifying font languages. Background Technology
[0002] With the advancement of globalization and the rapid development of internet information services, people increasingly desire to overcome language barriers in communication, making automatic language recognition technology increasingly important. Automatic language recognition, as the name suggests, is the process of using a computer to automatically identify the language category of any text fragment. Through automatic language recognition, people can quickly and efficiently and accurately distinguish between different types of language fragments.
[0003] Language identification has important applications in information retrieval; any field related to language understanding requires automatic language identification technology. Therefore, research on language identification technology plays a crucial role in the development of computer science.
[0004] Currently, with the widespread use of Windows systems, various technologies applied to Windows have developed significantly. The Windows platform, through the Win32 API, can effectively determine the language of most fonts, meeting users' needs for language recognition. However, the Linux platform cannot determine the language of fonts through the Win32 API, leading to situations where fonts and characters cannot be recognized, thus impacting the user experience.
[0005] Therefore, new solutions are needed to improve the accuracy and reliability of font language identification. Summary of the Invention
[0006] The following is an overview of the subject matter described in detail herein. This overview is not intended to limit the scope of the claims.
[0007] This disclosure provides a method, apparatus, and storage medium for identifying the language of a font, enabling users to determine that the same font belongs to the same language on different operating systems.
[0008] This disclosure provides a method for identifying the language of a font, including:
[0009] Obtain the font attributes of the font to be identified, including: font name and language;
[0010] The language is identified based on the font name language in the font attributes, and the identified language is determined as the language supported by the font to be identified.
[0011] In one exemplary instance, identifying the language based on the font name language in the font attributes includes:
[0012] The font name language in the font attributes is parsed to determine whether there are any missing identifications;
[0013] If no identification is found, the language is identified based on the font name.
[0014] In one exemplary instance, parsing the font name language in the font attributes to determine whether there are any missing identifiers includes:
[0015] The language attribute of the font name of the font to be identified is parsed. If the language attribute of the font name of the font to be identified cannot be parsed, it is determined that the language identification of the font name of the font to be identified is missing; and / or,
[0016] The language attribute of the font name of the font to be identified is parsed. If the language attribute of the font name of the font to be identified is empty, it is determined that the language identification of the font name of the font to be identified is missing; and / or,
[0017] The font name language attribute of the font to be identified is parsed to obtain the number of supported languages; if the number of supported languages obtained is less than the preset target number, it is determined that the font name language recognition of the font to be identified is missing; and / or,
[0018] The language attribute of the font name of the font to be identified is analyzed. If the preset expected language is not included in the supported languages, it is determined that the language recognition of the font name of the font to be identified is missing.
[0019] In one exemplary instance, the font attribute includes the font name; the method further includes:
[0020] Determine the Unicode encoding value corresponding to the font name in the font attributes;
[0021] Based on the preset correspondence between Unicode encoding values and languages, and the Unicode encoding value corresponding to the font name, the languages supported by the font to be identified are determined.
[0022] In one exemplary instance, determining the Unicode encoding value corresponding to the font name in the font attribute includes:
[0023] Determine whether the font name contains a preset filter character;
[0024] If the font name contains preset filter characters, the font name is filtered according to the preset filter characters;
[0025] Determine the Unicode encoding value of the font name after filtering out the preset filtered characters;
[0026] The preset filter characters include at least one of the following: English letters, numbers, and symbols.
[0027] In one exemplary instance, determining the Unicode encoding value corresponding to the font name in the font attribute includes:
[0028] Determine the Unicode encoding value for each character in the font name;
[0029] The step of determining the languages supported by the font to be identified based on the preset correspondence between Unicode encoding values and languages, and the Unicode encoding value corresponding to the font name, includes:
[0030] Extract the characters from the font name sequentially;
[0031] Based on the Unicode encoding values corresponding to the characters obtained from the font name, the correspondence between preset Unicode encoding values and languages is found to determine the language corresponding to each character in the font name;
[0032] Based on the language corresponding to each character in the font name, determine the languages supported by the font to be identified.
[0033] In one exemplary instance, determining the languages supported by the font to be identified based on the language corresponding to each character in the font name includes:
[0034] Calculate the number of characters in each language based on the language corresponding to each character in the font name;
[0035] Languages are sorted in descending order based on the number of characters.
[0036] The top M languages are selected as the languages supported by the font to be identified, where M is an integer greater than or equal to 1.
[0037] This disclosure also provides an apparatus for identifying font languages, including,
[0038] The attribute acquisition module is configured to acquire the font attributes of the font to be identified, including: font name and language;
[0039] The language determination module is configured to identify the language based on the font name language in the font attributes, and determine the identified language as the language supported by the font to be identified.
[0040] This disclosure also provides an electronic device, including a memory and a processor. The memory stores a computer program for font language recognition, and the processor is configured to read and run the computer program for font language recognition to perform any of the above-described methods for recognizing font languages.
[0041] This disclosure also provides a storage medium storing a computer program, wherein the computer program is configured to execute any of the above-described methods for recognizing font languages when it is run.
[0042] After reading and understanding the accompanying diagrams and detailed descriptions, the other aspects can be understood. Attached Figure Description
[0043] Figure 1 This is a flowchart of a method for identifying font language according to Embodiment 1 of this disclosure;
[0044] Figure 2 This is a flowchart of a method for identifying font language according to Embodiment 2 of this disclosure;
[0045] Figure 3 This is a schematic diagram illustrating the effect of applying the font language identification method in this embodiment of the present disclosure to office software;
[0046] Figure 4 This is a flowchart of a method for identifying font language according to Embodiment 3 of this disclosure;
[0047] Figure 5 This is a structural diagram of a device for recognizing font languages according to Embodiment 4 of this disclosure. Detailed Implementation
[0048] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that, unless otherwise specified, the embodiments and features described in this application can be arbitrarily combined with each other.
[0049] The following step numbers are not limited to a specific execution order, and the execution order of some steps can be adjusted according to specific embodiments.
[0050] On Windows, the Win32 API can be used to determine the language of a font. On Linux, the FontConfig library is used to parse font information. FontConfig is a font management library that matches a font to its configuration and populates its various attributes. However, due to incomplete support, the FontConfig library's API (Application Programming Interface) may not fully identify the languages supported by a font. For example, it might not recognize a Chinese font. Therefore, using the FontConfig library for font language identification on Linux is not entirely reliable.
[0051] As will be known to those skilled in the art, font attributes include at least one of the following: font name, font name language, and supported languages. In the embodiments provided by this invention, the font attributes in the FontConfig library correspond to: font name (FC_FAMILY), font name language (FC_FAMILYLANG), and supported languages (FC_LANG).
[0052] Example 1
[0053] This disclosure provides a method for font recognition, such as... Figure 1 As shown, it includes:
[0054] Step 10: Determine the font to be recognized;
[0055] In one exemplary embodiment of the present invention, the font to be identified can be the font corresponding to all the text contained in the currently opened document, or the font corresponding to the text contained in the selected paragraph in the current document, the font corresponding to the text contained in the selected sentence or several sentences in the current document, the font corresponding to the text contained in the selected table in the current document, etc., and is not limited thereto. In another exemplary embodiment of the present invention, the font to be identified can also be the font corresponding to the text contained in an image. The text in the image is obtained through OCR recognition technology, and the font corresponding to the obtained text in the image is determined as the font to be identified.
[0056] Step 11: Obtain the supported language (FC_LANG) attribute of the font to be recognized; determine if the FC_LANG attribute is missing? If the FC_LANG attribute of the font to be recognized is not missing, proceed to step 12; if the FC_LANG attribute of the font to be recognized is missing, proceed to step 13.
[0057] In one exemplary embodiment of the present invention, the FontConfig library function can be used to identify the supported language (FC_LANG) of the font to be identified, or any font management library used on the Linux platform can be used to identify the supported language (FC_LANG) of the font.
[0058] Step 12: Determine the language supported by the font to be identified based on the language identified by the FC_LANG attribute.
[0059] Step 13: Obtain the font name language (FC_FAMILYLANG) attribute of the font to be identified; determine if the FC_FAMILYLANG attribute is missing? If the FC_FAMILYLANG attribute is not missing, proceed to step 14;
[0060] In one exemplary embodiment of the present invention, the font name language can be identified using the FontConfig library function, or any font management library used on the Linux platform can be used to identify the font name language.
[0061] Step 14: Determine the language supported by the font to be identified based on the language identified by the FC_FAMILYLANG attribute.
[0062] In one exemplary embodiment, determining whether the FC_LANG attribute is missing in step 11 includes:
[0063] The FC_LANG attribute of the font to be recognized is parsed. If the FC_LANG attribute of the font to be recognized cannot be parsed, it is determined that the FC_LANG attribute recognition of the font to be recognized is missing; and / or,
[0064] The FC_LANG attribute of the font to be recognized is parsed. If the FC_LANG attribute of the font to be recognized is empty, it is determined that the FC_LANG attribute recognition of the font to be recognized is missing; and / or,
[0065] The FC_LANG attribute of the font to be recognized is parsed to obtain the number of supported languages; if the number of supported languages obtained is less than the preset target number, it is determined that the FC_LANG attribute of the font to be recognized is missing; wherein, the supported languages of the font to be recognized are determined according to the number of languages contained in the FC_LANG attribute of the font to be recognized; and / or,
[0066] The FC_LANG attribute of the font to be identified is parsed. If the preset expected language is not included in the list of supported languages, it is determined that the FC_LANG attribute of the font to be identified is missing. In one exemplary embodiment, the preset expected language includes one or more.
[0067] The following specific examples illustrate the preset target quantity and preset desired language. For example:
[0068] Parsing the FC_LANG attribute of the font to be recognized reveals a supported language count of 1, which is less than the preset target count of 2. In this case, it is confirmed that the FC_LANG attribute of the font to be recognized is missing. The preset target count can be set based on historical usage needs or determined by the number of font language types contained in the selected font to be recognized. The number of font language types contained in the selected font to be recognized can be counted simply by identifying the types of font language types contained in the font. For example, for electronic devices including but not limited to laptops, smartphones, tablets, and desktop computers, the characters in the font to be recognized are obtained one by one. When the font language type of the current character is different from all previously obtained characters, the number of font language types is incremented by 1; otherwise, the number of font language types remains unchanged, and the next adjacent character in the font to be recognized is obtained, until all characters in the font to be recognized have been identified, thus obtaining the number of font language types contained in the font to be recognized. Whether the font language types are the same can be determined by whether the font attributes corresponding to the font to be identified are the same, such as the font name (FC_FAMILY), the font name language (FC_FAMILYLANG), and the supported languages (FC_LANG). Alternatively, it can be determined by the Unicode encoding of the font; there is no specific limitation here. The number of font language types contained in the selected font to be identified can also be counted by the number of font language type names contained in the font to be identified.
[0069] The FC_LANG attribute of the font to be identified is parsed, revealing supported languages such as English and German. However, the preset expected language is Simplified Chinese. In this case, it is confirmed that the FC_LANG attribute of the font to be identified is missing. In one exemplary embodiment of the present invention, the preset expected language can be set by the user, recommended by the electronic device based on analysis of the language used in the user's historical document operations, or recommended based on the geographical location of the electronic device; no limitation is imposed here.
[0070] In one exemplary embodiment, step 13, determining whether the FC_FAMILYLANG attribute is missing, includes:
[0071] The FC_FAMILYLANG attribute of the font to be identified is parsed. If no supported language can be parsed, it is determined that the FC_FAMILYLANG attribute of the font to be identified is missing; and / or,
[0072] The FC_FAMILYLANG attribute of the font to be recognized is parsed. If the FC_FAMILYLANG attribute of the font to be recognized is found to be empty, it is determined that the FC_FAMILYLANG attribute of the font to be recognized is missing; and / or,
[0073] The FC_FAMILYLANG attribute of the font to be recognized is parsed to obtain the number of supported languages; if the number of supported languages obtained is less than the preset target number, it is determined that the FC_FAMILYLANG attribute recognition is missing; and / or,
[0074] If the FC_FAMILYLANG attribute of the font to be identified is parsed and the supported languages do not include the preset expected languages, it is determined that the FC_FAMILYLANG attribute of the font to be identified is missing.
[0075] In one exemplary embodiment, the preset desired language includes one or more.
[0076] For example, if parsing the FC_FAMILYLANG attribute of the font to be identified reveals that the number of supported languages is 1, which is less than the preset target number of 2, then it is confirmed that the FC_FAMILYLANG attribute of the font to be identified is missing. Alternatively, if parsing the FC_FAMILYLANG attribute of the font to be identified reveals that English and German are supported languages, but the preset desired language is Simplified Chinese, then it is confirmed that the FC_FAMILYLANG attribute is missing. In the exemplary embodiments provided by this invention, the preset target number of the FC_FAMILYLANG attribute and the preset desired language of the FC_FAMILYLANG attribute can be obtained using the methods for obtaining the preset target number and preset desired language of the FC_FAMILYLANG attribute, respectively, and will not be elaborated further here.
[0077] Example 2
[0078] This disclosure provides a method for font recognition, such as... Figure 2 As shown, it includes:
[0079] Step 20: Determine the font to be recognized;
[0080] Step 21: Obtain the supported language (FC_LANG) attribute of the font to be recognized; determine if the FC_LANG attribute is missing? If the FC_LANG attribute of the font to be recognized is not missing, proceed to step 22; if the FC_LANG attribute of the font to be recognized is missing, proceed to step 23.
[0081] Step 22: Determine the language supported by the font to be identified based on the language identified by the FC_LANG attribute;
[0082] Step 23: Obtain the font name language (FC_FAMILYLANG) attribute of the font to be identified; determine if the FC_FAMILYLANG attribute is missing? If the FC_FAMILYLANG attribute is not missing, proceed to step 24; otherwise, proceed to step 25.
[0083] Step 24: Determine the language supported by the font to be identified based on the language identified by the FC_FAMILYLANG attribute;
[0084] The process of judging the font to be recognized in steps 20 to 24 is the same as that in steps 10 to 14, and both can achieve the same or similar beneficial effects, so it will not be described again here.
[0085] Step 25: Obtain the font name (FC_FAMILY) attribute of the font to be identified;
[0086] In one exemplary embodiment of the present invention, the font name can be identified using the FontConfig library function, or any font management library used on the Linux platform can be used to identify the font name.
[0087] Step 26: Determine the Unicode encoding value corresponding to the font name (FC_FAMILY) of the font to be identified;
[0088] Step 27: Based on the Unicode encoding value corresponding to the font name, find the preset Unicode encoding value and language correspondence to determine the languages supported by the font to be identified.
[0089] In one exemplary embodiment, determining the Unicode encoding value corresponding to the font name (FC_FAMILY) of the font to be identified includes:
[0090] Determine whether the font name of the font to be identified contains preset filter characters;
[0091] If the font name of the font to be identified contains a preset filter character, the font name (FC_FAMILY) is filtered according to the preset filter character to determine the Unicode encoding value corresponding to the filtered font name.
[0092] The preset filter characters include at least one of the following: English letters, numbers, and symbols.
[0093] In one exemplary embodiment, determining the Unicode encoding value corresponding to the font name (FC_FAMILY) of the font to be identified includes:
[0094] Determine the Unicode encoding value of each character in the font name of the font to be identified.
[0095] Accordingly, based on the Unicode encoding value corresponding to the font name, the preset Unicode encoding value and language correspondence is looked up to determine the languages supported by the font to be identified, including:
[0096] Extract the characters from the font name sequentially;
[0097] Based on the Unicode encoding values of the characters obtained from the font name, find the preset correspondence between Unicode encoding values and languages to determine the language corresponding to each character in the font name;
[0098] Based on the language corresponding to each character in the font name, determine the language containing the most characters;
[0099] The language supported by the font is the language with the most characters.
[0100] In an exemplary embodiment, the correspondence between preset Unicode encoding values and languages is shown in the table below. Taking Simplified Chinese as an example, when the Unicode encoding value ranges from 4E00 to 9FEF, the language supported by the font is Simplified Chinese.
[0101] Table 1 - Correspondence between Unicode encoding values and languages
[0102] Unicode encoding value range Language 4E00—9FEF Simplified Chinese
[0103] In one exemplary embodiment, since a Unicode encoding value may correspond to multiple languages, step 27 includes:
[0104] Based on the preset correspondence between Unicode encoding values and languages, and the Unicode encoding value of each character in the font name, the language corresponding to each character in the font name is determined.
[0105] Based on the language corresponding to each character in the font name, determine the languages supported by the font to be identified.
[0106] In one exemplary embodiment, determining the languages supported by the font to be identified based on the language corresponding to each character in the font name includes:
[0107] Calculate the number of characters in each language based on the language corresponding to each character in the font name;
[0108] Sort the languages in descending order according to the number of characters;
[0109] Obtain the top M languages before sorting as the languages supported by the font, where M is an integer greater than or equal to 1.
[0110] For example, for the font name "一二三X" of the font to be recognized, the character "一" corresponds to languages 1 and 2; the character "二" corresponds to languages 1, 3, and 4; the character "三" corresponds to language 1; the character "X" corresponds to languages 1 and 2. Then the number of characters included in language 1 is 4, the number of characters included in language 2 is 2, the number of characters included in language 3 is 1, and the number of characters included in language 4 is 1. When M = 2, the top 2 languages (languages 1 and 2) are used as the languages supported by this font, that is, the font with the font name "一二三X" supports languages 1 and 2.
[0111] In an exemplary embodiment, determining the languages supported by the font to be recognized according to the languages corresponding to each character in the font name includes:
[0112] Calculate the number of characters included in each language according to the languages corresponding to each character in the font name;
[0113] Use the languages with the number of characters included greater than the character number threshold as the languages supported by the font. The character number threshold can be set according to requirements.
[0114] Next, the method for recognizing the font language provided by the present invention will be described with different examples respectively.
[0115] Example 1
[0116] Taking the font to be recognized as MingLiU-ExtB as an example, it supports Traditional Chinese (zh-tw), but in the actual operation process, the FontConfig library can only parse that this font supports the en language. It can be seen that the parsing result obtained by the API of the Fontconfig library is incorrect.
[0117] Adopting the solution provided by the embodiment of the present invention to determine the languages supported by the font to be recognized MingLiU-ExtB includes:
[0118] 1. Obtain the FC_FAMILYLANG attribute of the font to be recognized MingLiU-ExtB;
[0119] 2. Determine whether the FC_FAMILYLANG attribute is recognized as missing. If the FC_FAMILYLANG attribute is not missing and contains the zh-tw attribute, it is determined that the font supports Traditional Chinese (zh-tw) based on the zh-tw attribute.
[0120] Example 2
[0121] Taking the Great Wall Song typeface to be recognized as an example, it supports Simplified Chinese, but in the actual operation process, the FontConfig library cannot parse that it supports Simplified Chinese (zh-cn).
[0122] Adopting the solution provided by the embodiment of the present invention to determine the languages supported by the Great Wall Song typeface to be recognized, including:
[0123] 1. Obtain the FC_FAMILY attribute of the Great Wall Song typeface, which is four characters (Chang, Cheng, Song, Ti);
[0124] 2. Determine the Unicode code values of these four characters respectively;
[0125] 3. Respectively judge that the Unicode code values corresponding to these four characters belong to the range of Chinese characters;
[0126] 4. Determine that the Great Wall Song typeface supports Simplified Chinese (zh-cn).
[0127] Example 3
[0128] Make an extension for Example 2. If, among the characters of the font name of a font, excluding characters such as English, symbols, and numbers, the remaining are all Chinese characters, it is still regarded as a Chinese font.
[0129] Taking the FangSong_GB2312 typeface to be recognized as an example, adopting the solution provided by the embodiment of the present invention to determine the languages supported by the FangSong_GB2312 typeface to be recognized, including:
[0130] 1. Obtain the FC_FAMILY attribute of the Great Wall Song typeface, which is FangSong_GB2312;
[0131] 2. Filter out the preset filtering characters therein, such as: English, symbols, numbers, and only the two characters "Fang Song" are left;
[0132] 3. Determine the Unicode code values of these two characters "Fang Song" respectively;
[0133] 4. Respectively judge that the Unicode code values corresponding to these two characters belong to the range of Chinese characters;
[0134] 5. Determine that FangSong_GB2312 supports Chinese fonts.
[0135] In one exemplary embodiment, when the method for identifying font language is applied to office software, its effect is as follows: Figure 3 As shown. The office software is installed on a Linux system. Since its operating environment is clearly Linux, its font-related functions need to recognize all fonts that support Chinese characters. Therefore, the default expected languages must include at least Simplified Chinese. During operation, the office software calls the FontConfig library function to parse font-related information.
[0136] For example, if the font to be identified in Example 2 is Great Wall Songti, and the solution provided in this embodiment is not adopted, the FontConfig library cannot parse its support for Simplified Chinese (zh-cn), then in cases such as Figure 3 The dropdown menu for Chinese fonts shown does not include the option for "Great Wall Songti". Using the solution provided in this embodiment, as shown in Example 2, based on the Unicode encoding values of the four characters of "Great Wall Songti", it is determined that the font supports Simplified Chinese. Therefore, in... Figure 3 The dropdown menu for Chinese fonts shows "Great Wall Songti" as an option.
[0137] As can be seen, the solution provided by the embodiments of this disclosure can overcome the problem that existing FontConfig library functions cannot identify or fully identify the languages supported by a certain font.
[0138] Those skilled in the art will understand that when a font recognition scheme is applied to a system based on other font library functions, the font attributes—font name, font name language, and supported languages—can also be obtained using those other font library functions; only the corresponding attribute keywords (FC_FAMILY, FC_FAMILYLANG, FC_LANG) may differ. Based on the above description, those skilled in the art can deduce how to adjust the details and implement this scheme when applied to systems using other font library functions.
[0139] Example 3
[0140] This disclosure also provides a method for identifying font language, such as... Figure 4 As shown, including,
[0141] Step 40: Obtain the font attributes of the font to be identified. The font attributes include: font name and language.
[0142] Step 41: Identify the language based on the font name language in the font attribute, and determine the identified language as the language supported by the font to be identified.
[0143] Using the above methods, even with incomplete font management library support, the language of the same font can be accurately determined across different operating systems, thus improving the user experience.
[0144] In one exemplary embodiment, step 41, which identifies the language based on the font name language in the font attributes, includes:
[0145] Parse the language of the font name in the font attributes to determine if there are any missing identifiers;
[0146] If no recognition defects are found, the language is identified based on the font name.
[0147] The process of determining whether the language attribute of the font name is missing includes:
[0148] The language attribute of the font name of the font to be identified is parsed. If the language attribute of the font name of the font to be identified cannot be parsed, it is determined that the language identification of the font name of the font to be identified is missing; and / or,
[0149] The language attribute of the font name of the font to be identified is parsed. If the language attribute of the font name of the font to be identified is empty, it is determined that the language identification of the font name of the font to be identified is missing; and / or,
[0150] The font name language attribute of the font to be identified is parsed to obtain the number of supported languages; if the number of supported languages obtained is less than the preset target number, it is determined that the font name language recognition of the font to be identified is missing; and / or,
[0151] The language attribute of the font name of the font to be identified is analyzed. If the preset expected language is not included in the supported languages, it is determined that the language recognition of the font name of the font to be identified is missing.
[0152] In one exemplary embodiment, the font attributes of the font further include: font name;
[0153] The method for identifying font language also includes: step 42, determining the Unicode encoding value corresponding to the font name in the font attributes;
[0154] Based on the preset correspondence between Unicode encoding values and languages, and the Unicode encoding value corresponding to the font name, the languages supported by the font to be identified are determined.
[0155] In one exemplary embodiment, the font attributes further include: supported languages;
[0156] The method further includes: step 43, parsing according to the supported language (attributes) to determine whether there is any recognition loss;
[0157] If a missing identification is determined, proceed to step 40 or 42;
[0158] In step 43, the parsing is performed according to the supported languages to determine whether there are any recognition gaps, including:
[0159] The supported language attributes of the font to be identified are parsed; if the supported language attributes of the font to be identified cannot be parsed, it is determined that the supported language recognition of the font to be identified is missing; and / or,
[0160] The supported language attributes of the font to be identified are parsed. If the supported language attributes of the font to be identified are empty, it is determined that the supported language recognition of the font to be identified is missing; and / or,
[0161] The supported language attributes of the font to be identified are parsed to obtain the number of supported languages; if the number of supported languages obtained is less than the preset target number, it is determined that the supported languages of the font to be identified are missing; wherein, the supported languages of the font to be identified are determined according to the number of languages included in the supported language attributes of the font to be identified; and / or,
[0162] The supported language attributes of the font to be identified are analyzed. If the expected language is not included in the supported languages obtained, it is determined that the supported language recognition of the font to be identified is missing.
[0163] In an exemplary embodiment, if it is determined that there is no missing recognition, step 44 is executed, and the supported languages are obtained by parsing the supported languages as the languages supported by the font to be recognized.
[0164] In one exemplary embodiment, obtaining the font attributes of the font includes:
[0165] Use the FontConfig library functions to get the font properties corresponding to the font.
[0166] For example, the library function FcPatternGetString can be used to obtain the font name (FC_FAMILY) and the font language (FC_FAMILYLANG).
[0167] For example, if it is determined that there is no missing recognition, the supported languages can be determined by obtaining the information of the supported languages (FC_LANG). The library function FcPatternGetString can be used to obtain the FC_LANG attribute, and the language supported by the current font can be determined based on the FC_LANG attribute.
[0168] In one exemplary embodiment, determining the Unicode encoding value corresponding to the font name in the font attributes includes:
[0169] Determine whether the font name contains preset filtered characters;
[0170] If the font name contains preset filter characters, the font name will be filtered according to the preset filter characters;
[0171] Determine the Unicode encoding value of the font name after filtering out the preset filtered characters;
[0172] The preset filter characters include at least one of the following: English letters, numbers, and symbols.
[0173] In one exemplary embodiment, determining the Unicode encoding value corresponding to the font name in the font attributes includes:
[0174] Determine the Unicode encoding value for each character in the font name;
[0175] Based on the preset correspondence between Unicode encoding values and languages, and the Unicode encoding value corresponding to the font name, the languages supported by the font are determined, including:
[0176] Extract the characters from the font name sequentially;
[0177] Based on the Unicode encoding values of the characters obtained from the font name, find the preset correspondence between Unicode encoding values and languages to determine the language corresponding to each character in the font name;
[0178] The languages supported by the font are determined based on the language corresponding to each character in the font name.
[0179] In one exemplary embodiment, determining the languages supported by the font to be identified based on the language corresponding to each character in the font name includes:
[0180] Calculate the number of characters in each language based on the language corresponding to each character in the font name;
[0181] Languages are sorted in descending order based on the number of characters.
[0182] Obtain the top M languages as the languages supported by the font to be identified, where M is an integer greater than or equal to 1.
[0183] In one exemplary embodiment, the preset correspondence between Unicode encoding values and languages includes: different languages correspond to different ranges of Unicode encoding values;
[0184] Determine the language corresponding to the character in the font name, including:
[0185] The language corresponding to the Unicode encoding value range to which the Unicode encoding value of the character belongs is determined as the language corresponding to the character.
[0186] In one exemplary embodiment, the ranges of Unicode encoding values corresponding to different languages partially overlap.
[0187] In one exemplary embodiment, a Unicode encoding value corresponds to one or more languages.
[0188] In one exemplary embodiment, other function libraries may also be used to retrieve font attributes. This is not limited to the FontConfig library functions exemplified in the embodiments of this disclosure.
[0189] As can be seen, when the font-related basic library on which the software system depends cannot fully identify the languages supported by each font (i.e., there are corresponding recognition gaps), the method provided in this disclosure embodiment can be used to identify the supported languages by utilizing the font name language in the font attributes. In an exemplary embodiment, the Unicode encoding value of the font name can also be used to identify the supported languages. The font recognition scheme is not limited to Linux systems or systems using the FontConfig library.
[0190] Example 4
[0191] This disclosure also provides an apparatus for identifying the language of a font, such as... Figure 5 As shown, including,
[0192] The attribute acquisition module 50 is set to acquire the font attributes of the font to be identified. The font attributes include: font name and language.
[0193] The language determination module 51 is set to identify the language based on the font name language in the font attributes, and determine the identified language as the language supported by the font to be identified.
[0194] In an exemplary embodiment, the language determination module 51 is configured to parse the language of the font name in the font attributes and determine whether there is any missing identification; if it is determined that there is no missing identification, the language is identified based on the language of the font name.
[0195] This includes parsing the language of the font name in the font attributes to determine if there are any missing identifiers, including:
[0196] The language attribute of the font name of the font to be identified is parsed. If the language attribute of the font name of the font to be identified cannot be parsed, it is determined that the language identification of the font name of the font to be identified is missing; and / or,
[0197] The language attribute of the font name of the font to be identified is parsed. If the language attribute of the font name of the font to be identified is empty, it is determined that the language identification of the font name of the font to be identified is missing; and / or,
[0198] The font name language attribute of the font to be identified is parsed to obtain the number of supported languages; if the number of supported languages obtained is less than the preset target number, it is determined that the font name language recognition of the font to be identified is missing; and / or,
[0199] The language attribute of the font name of the font to be identified is analyzed. If the preset expected language is not included in the supported languages, it is determined that the language recognition of the font name of the font to be identified is missing.
[0200] In one exemplary embodiment, the font attributes further include: font name;
[0201] The language determination module 51 is also configured to determine the Unicode encoding value corresponding to the font name in the font attributes; and determine the language supported by the font to be identified based on the preset correspondence between Unicode encoding values and languages, and the Unicode encoding value corresponding to the font name.
[0202] In an exemplary embodiment, the language determination module 51 is further configured to: parse the language of the font name in the font attributes to determine whether there is any missing identification; if it is determined that there is no missing identification, perform the step of identifying the language based on the language of the font name in the font attributes; if it is determined that there is any missing identification, perform the step of determining the Unicode encoding value corresponding to the font name in the font attributes.
[0203] This disclosure also provides an electronic device, including a memory and a processor. The memory stores a computer program for performing font language recognition, and the processor is configured to read and run the computer program for performing font language recognition to execute the font language recognition method described in any of the above embodiments.
[0204] This disclosure also provides a storage medium storing a computer program, wherein the computer program is configured to execute the font language recognition method described in any of the above embodiments when running.
[0205] According to the solution provided in this disclosure, language identification is performed based on the language of the font name in the font attributes. In an exemplary embodiment, the language information corresponding to the range of pre-configured Unicode encoding values can also be used to determine that the same font belongs to the same language on different operating systems. Furthermore, when running office software on different operating systems, the font dialog box can provide users with the same font selection options, preventing users from not finding the corresponding font in the relevant language and ultimately ensuring a consistent user experience.
[0206] It will be understood by those skilled in the art that all or some of the steps, systems, or apparatuses disclosed above, and their functional modules / units, can be implemented as software, firmware, hardware, or suitable combinations thereof. In hardware implementations, the division between functional modules / units mentioned above does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed collaboratively by several physical components. Some or all components may be implemented as software executed by a processor, such as a digital signal processor or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit (ASIC). Such software may be distributed on a computer-readable medium, which may include computer storage media (or non-transitory media) and communication media (or transient media). As is known to those skilled in the art, the term computer storage media includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disc (DVD) or other optical disc storage, magnetic cartridges, magnetic tape, disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and can be accessed by a computer. Furthermore, it is well known to those skilled in the art that communication media typically contain computer-readable instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery medium.
Claims
1. A method for identifying the language of a font, characterized in that, include, Obtain the font attributes of the font to be identified, including: font name and font name language; The language is identified based on the font name language in the font attributes, and the identified language is determined as the language supported by the font to be identified; The method further includes: Determine the Unicode encoding value corresponding to the font name in the font attributes; Sequentially retrieve the characters from the font name in the font attributes; Based on the Unicode encoding values corresponding to the characters obtained from the font name, the correspondence between preset Unicode encoding values and languages is found to determine the language corresponding to each character in the font name; Determining the languages supported by the font to be identified based on the language corresponding to each character in the font name includes: calculating the number of characters contained in each language according to the language corresponding to each character in the font name; sorting the languages in descending order according to the number of characters; and obtaining the top M languages as the languages supported by the font to be identified, where M is an integer greater than or equal to 1.
2. The method according to claim 1, characterized in that, The step of identifying the language based on the font name language in the font attributes includes: The font name language in the font attributes is parsed to determine whether there are any missing identifications; If no identification is found, the language is identified based on the font name.
3. The method according to claim 2, characterized in that, The font name language in the font attributes is parsed to determine if there are any missing identifiers, including: The language attribute of the font name of the font to be identified is parsed. If the language attribute of the font name of the font to be identified cannot be parsed, it is determined that the language identification of the font name of the font to be identified is missing; and / or, The language attribute of the font name of the font to be identified is parsed. If the language attribute of the font name of the font to be identified is empty, it is determined that the language identification of the font name of the font to be identified is missing; and / or, The font name language attribute of the font to be identified is parsed to obtain the number of supported languages; if the number of supported languages obtained is less than the preset target number, it is determined that the font name language recognition of the font to be identified is missing; and / or, The language attribute of the font name of the font to be identified is analyzed. If the preset expected language is not included in the supported languages, it is determined that the language recognition of the font name of the font to be identified is missing.
4. The method according to claim 1, characterized in that, Determining the Unicode encoding value corresponding to the font name in the font attributes includes: Determine whether the font name contains a preset filter character; If the font name contains preset filter characters, the font name is filtered according to the preset filter characters; Determine the Unicode encoding value of the font name after filtering out the preset filtered characters; The preset filter characters include at least one of the following: English letters, numbers, and symbols.
5. The method according to claim 1, characterized in that, Determining the Unicode encoding value corresponding to the font name in the font attributes includes: Determine the Unicode encoding value for each character in the font name.
6. A device for identifying the language of a font, characterized in that, include, The attribute acquisition module is configured to acquire the font attributes of the font to be identified, including: font name and font name language; The language determination module is configured to identify the language based on the font name language in the font attributes, and determine the identified language as the language supported by the font to be identified; and to determine the Unicode encoding value corresponding to the font name in the font attributes; sequentially obtain the characters in the font name in the font attributes; based on the Unicode encoding value corresponding to the character obtained in the font name, find a preset correspondence between the Unicode encoding value and the language, and determine the language corresponding to each character in the font name; based on the language corresponding to each character in the font name, determine the language supported by the font to be identified, including: calculating the number of characters contained in each language based on the language corresponding to each character in the font name; sorting the languages in descending order based on the number of characters; and obtaining the top M languages as the languages supported by the font to be identified, where M is an integer greater than or equal to 1.
7. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program for font language recognition, and the processor is configured to read and run the computer program for font language recognition to perform the method described in any one of claims 1 to 5.
8. A storage medium, characterized in that, The storage medium stores a computer program, wherein the computer program is configured to execute the method described in any one of claims 1 to 5 when it is run.