Font Loading Method, Device, Electronic Device, and Storage Medium

By caching Native font resources to a shared directory and using URIs to load them in Flutter pages, the method addresses the issue of redundant font storage, reducing app package size and improving user experience.

CN113641369BActive Publication Date: 2025-07-15BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110931213.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-08-13
Publication Date
2025-07-15
Estimated Expiration
2041-08-13

AI Technical Summary

Technical Problem

In APPs developed based on a hybrid development of Native technology and Flutter technology, Native pages and Flutter pages cannot share font resources, resulting in waste of resources and increased installation package volume.

Method used

By cache the font files of the Native page to a preset directory and use the font files under the directory to load Native fonts on the Flutter page, share a font resource and avoid repeated storage in the installation package.

Benefits of technology

It reduces the volume of the APP installation package, improves user download and installation efficiency, and improves user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113641369B_ABST
    Figure CN113641369B_ABST
Patent Text Reader

Abstract

The present application discloses a font loading method, device, electronic device, and storage medium. Among them, the method includes: a first program of the electronic device caches the font files in the first directory of the electronic device to a second directory of the preset electronic device; the font files in the first directory include the Native font resources of the first program; the first program uses at least one preset URI to obtain the font files in the second directory, and uses the font files in the second directory to load Native fonts on the Flutter page; each URI corresponds to at least one font file in the second directory.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technologies, and in particular, to a data processing method, apparatus, electronic device, and storage medium. Background Art

[0002] For the development of application programs (APPs), more and more cross-platform solutions have emerged. Among them, Flutter technology is a cross-platform development framework launched by Google, and it has great advantages in terms of performance, adaptability, etc. There are usually two modes for APP development based on Flutter technology:

[0003] 1) Developing an APP based on a newly created Flutter project;

[0004] 2) Embedding Flutter pages in a Native project for hybrid development of an APP.

[0005] Since the business logic in most native APPs is relatively complex, if all Flutter technology is used for APP reconstruction, the cycle is long and the risk is high; moreover, Flutter technology, as a new technology, is not yet very mature. Therefore, usually the second mode above (i.e., embedding Flutter pages in a Native project for hybrid development of an APP) is adopted for APP development.

[0006] However, in related technologies, for an APP developed based on the hybrid of Native technology and Flutter technology, the Native pages and Flutter pages cannot share font resources. Summary of the Invention

[0007] To solve the related technical problems, embodiments of this application provide a font loading method, apparatus, electronic device, and storage medium.

[0008] The technical solution of the embodiments of this application is implemented as follows:

[0009] Embodiments of this application provide a font loading method, which is applied to an electronic device and includes:

[0010] A first program of the electronic device caches a font file in a first directory of the electronic device to a preset second directory of the electronic device; the font file in the first directory includes Native font resources of the first program;

[0011] The first program obtains the font files in the second directory by using at least one preset Uniform Resource Identifier (URI), and loads the native font on the Flutter page by using the font files in the second directory; each URI corresponds to at least one font file in the second directory.

[0012] In the above solution, caching the font files in the first directory of the electronic device to the preset second directory of the electronic device includes:

[0013] When the first program starts, it detects whether there are cached font files in the second directory;

[0014] When the first program does not detect cached font files in the second directory, it caches the font files in the first directory to the second directory.

[0015] In the above solution, obtaining the font files in the second directory by using at least one preset URI includes:

[0016] For each URI in the at least one URI, the first program detects whether there is a font file corresponding to the corresponding URI in the second directory; when it is determined that there is a font file corresponding to the corresponding URI in the second directory, it obtains the font file corresponding to the corresponding URI.

[0017] In the above solution, each URI also corresponds to a cloud download address of a font file; obtaining the font files in the second directory by using at least one preset URI includes:

[0018] For each URI in the at least one URI, the first program detects whether there is a font file corresponding to the corresponding URI in the second directory; when it is determined that there is no font file corresponding to the corresponding URI in the second directory, it downloads the font file corresponding to the corresponding URI to the second directory by using the cloud download address corresponding to the corresponding URI; and obtains the font file corresponding to the corresponding URI.

[0019] In the above solution, loading the native font on the Flutter page by using the font files in the second directory includes:

[0020] The first program verifies the validity of each font file in the second directory; when the validity verification of the corresponding font file passes, it loads the corresponding native font on the Flutter page by using the corresponding font file.

[0021] In the above solution, when the validity check of the corresponding font file passes, loading the corresponding Native font in the Flutter page using the corresponding font file includes:

[0022] When the validity check of the corresponding font file passes, the first program decrypts the corresponding font file, and uses the decrypted font file to load the corresponding Native font in the Flutter page.

[0023] In the above solution, the method further includes:

[0024] When the first program fails to successfully load the Native font using the font file in the second directory, load the preset system font in the Flutter page.

[0025] An embodiment of the present application further provides a font loading device, which is set on an electronic device and includes:

[0026] A first program unit, configured to cache the font file in the first directory of the electronic device to the preset second directory of the electronic device; obtain the font file in the second directory using at least one preset URI, and use the font file in the second directory to load the Native font in the Flutter page; the font file in the first directory contains the Native font resources of the first program unit; each URI corresponds to at least one font file in the second directory.

[0027] An embodiment of the present application further provides an electronic device, including: a processor and a memory for storing a computer program that can run on the processor,

[0028] Wherein, when the processor is used to run the computer program, it executes the steps of any of the above methods.

[0029] An embodiment of the present application further provides a storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it implements the steps of any of the above methods.

[0030] The font loading method, device, electronic device, and storage medium provided by the embodiments of the present application. The first program of the electronic device caches the font files in the first directory of the electronic device to the second directory preset in the electronic device; the font files in the first directory include the Native font resources of the first program; the first program uses at least one preset URI to obtain the font files in the second directory, and uses the font files in the second directory to load Native fonts on the Flutter page; each URI corresponds to at least one font file in the second directory. In the solution of the embodiments of the present application, the first program caches the font files in the first directory containing the Native font resources to the preset second directory, and uses the font files in the second directory to load Native fonts on the Flutter page; thus, for an APP developed by mixing Native technology and Flutter technology, the Native page and the Flutter page can share a copy of Native font resources (i.e., the font files in the first directory). In other words, it is not necessary to store two identical font resources for the Native page and the Flutter page respectively in the installation package of the APP, but only one font resource needs to be stored in the installation package of the APP, thereby effectively reducing the volume of the installation package of the APP, and then improving the efficiency of users downloading and installing the APP, and enhancing the user experience. Description of the Drawings

[0031] Figure 1 It is a schematic flowchart of the font loading method according to the embodiments of the present application;

[0032] Figure 2 It is a schematic flowchart of font loading in the application embodiment of the present application;

[0033] Figure 3 It is a schematic structural diagram of the font loading device according to the embodiments of the present application;

[0034] Figure 4 It is a schematic structural diagram of the electronic device according to the embodiments of the present application. Detailed Embodiments

[0035] The present application will be further described in detail below with reference to the drawings and embodiments.

[0036] In the related art, for an APP developed by mixing Native technology and Flutter technology, if a custom font needs to be loaded on a Flutter page, the corresponding font resources need to be built into the project (i.e., stored in the APP's installation package), so that the custom font can be presented when displaying text on the Flutter page by adding parameter settings. However, since the storage locations (i.e., storage paths) of the font resources corresponding to the Native page and the Flutter page are different, the Native page and the Flutter page cannot share the font resources.

[0037] In actual application, to solve the problem that the Native page and the Flutter page cannot share the font resources, it can be considered to store two identical font resources for the Native page and the Flutter page respectively in the APP's installation package. However, this will lead to a waste of the font resources built in (i.e., saved) in the APP and increase the extra volume of the APP's installation package.

[0038] Based on this, in various embodiments of the present application, the first program (i.e., the APP) installed on the electronic device caches the font files in the first directory containing the Native font resources to a preset second directory, and uses the font files in the second directory to load the Native font on the Flutter page; thus, for an APP developed by mixing Native technology and Flutter technology, the Native page and the Flutter page can share a Native font resource (i.e., the font files in the first directory). In other words, it is not necessary to store two identical font resources for the Native page and the Flutter page respectively in the APP's installation package, but only one font resource needs to be stored in the APP's installation package, so as to effectively reduce the volume of the APP's installation package, thereby improving the efficiency of users downloading and installing the APP and enhancing the user experience.

[0039] An embodiment of the present application provides a font loading method, which is applied to an electronic device, as Figure 1 shown, the method includes:

[0040] Step 101: The first program of the electronic device caches the font files in the first directory of the electronic device to the preset second directory of the electronic device;

[0041] Here, the first program is implemented based on Native technology and Flutter technology; the font files in the first directory contain the Native font resources of the first program;

[0042] Step 102: The first program obtains the font files in the second directory by using at least one preset URI, and loads the native font on the Flutter page by using the font files in the second directory; each URI corresponds to at least one font file in the second directory.

[0043] In practical applications, the electronic device may include a personal computer (PC), a mobile phone, a wearable device, etc.; the PC may include a desktop computer, a laptop computer, a tablet computer, an in-vehicle computer, etc.

[0044] In practical applications, the first directory can be understood as the storage path of the native font resources of the first program; the second directory can be understood as the font resource cache path corresponding to the Flutter page of the first program; caching the font files in the first directory to the second directory can be understood as copying the font files in the first directory to the specified cache path (i.e., the second directory). Here, the first directory and the second directory can be set in advance according to requirements; the first directory and the second directory can be generated during the installation process of the first program on the electronic device.

[0045] In step 101, in practical applications, since the font files cached in the second directory may be cleared under certain circumstances, such as when the user actively deletes the font files, or the cache management software clears the cache of the first program, etc., therefore, in order to ensure that the Flutter page can load the native font, the first program needs to detect whether there are cached font files in the second directory when starting up, and cache the font files in the first directory to the second directory when no cached font files are detected in the second directory.

[0046] Based on this, in an embodiment, caching the font files in the first directory of the electronic device to the second directory preset in the electronic device may include:

[0047] The first program detects whether there are cached font files in the second directory when starting up;

[0048] The first program caches the font files in the first directory to the second directory when no cached font files are detected in the second directory.

[0049] Here, when the first program detects cached font files in the second directory, it can execute step 102.

[0050] In actual application, when the first program is started for the first time after being installed on the electronic device, since the font files in the first directory have not been cached to the second directory yet, the first program can directly cache the font files in the first directory to the second directory without detecting whether there are cached font files in the second directory. In subsequent startup situations such as the second startup, the first program then detects whether there are cached font files in the second directory and determines whether a caching operation needs to be performed based on the detection result.

[0051] Among them, since the first program only does not detect whether there are cached font files in the second directory at the first startup, the first program can separately start a pre-set thread (denoted as the first thread in the subsequent description) to cache the font files in the first directory to the second directory at the first startup. In subsequent startup situations such as the second startup, the first program then detects whether there are cached font files in the second directory through other pre-set threads (denoted as the second thread in the subsequent description), and when the second thread does not detect cached font files in the second directory, caches the font files in the first directory to the second directory through the first thread.

[0052] In actual application, when starting up, the first program can detect whether there are cached font files in the second directory through the application programming interface (API, Application Programming Interface) provided by the operating system of the electronic device.

[0053] In step 102, in actual application, since the cached font files in the second directory may be cleared at any time, in order to ensure that the Flutter page can load the Native font, the first program needs to detect again whether there are font files corresponding to each URI in the second directory during the process of obtaining the font files in the second directory by using at least one preset URI, and when it is determined that there are font files corresponding to the corresponding URI in the second directory, obtain the font files corresponding to the corresponding URI.

[0054] Based on this, in one embodiment, the obtaining of the font files in the second directory by using at least one preset URI may include:

[0055] The first program detects whether there are font files corresponding to the corresponding URI in the second directory for each URI in the at least one URI; when it is determined that there are font files corresponding to the corresponding URI in the second directory, obtain the font files corresponding to the corresponding URI.

[0056] In practical applications, when the first program needs to obtain the font files in the second directory by using at least one preset URI, the font files in the second directory may have been cleared. Therefore, in order to further ensure that the Flutter page can load the Native font, the font files can be stored in the cloud server in advance, and a cloud download address for downloading the corresponding font file from the cloud server can be preset for each URI. In this way, when it is determined that the font file corresponding to the corresponding URI does not exist in the second directory, the first program can use the cloud download address corresponding to the corresponding URI to download the font file corresponding to the corresponding URI to the second directory, so that the Flutter page can load the Native font.

[0057] Based on this, in an embodiment, each URI can also correspond to a cloud download address of a font file. The obtaining of the font files in the second directory by using at least one preset URI may include:

[0058] For each URI in the at least one URI, the first program detects whether a font file corresponding to the corresponding URI exists in the second directory. When it is determined that the font file corresponding to the corresponding URI does not exist in the second directory, the font file corresponding to the corresponding URI is downloaded to the second directory by using the cloud download address corresponding to the corresponding URI; and the font file corresponding to the corresponding URI is obtained.

[0059] In practical applications, the format of each URI in the at least one URI can be set according to requirements. Exemplarily, each URI can include "nativeFont: font name". At this time, when the first program detects whether a font file corresponding to the corresponding URI exists in the second directory, it can obtain the font name corresponding to the corresponding URI through the URI, and then detect whether a font file corresponding to the font name exists in the second directory through the API provided by the operating system of the electronic device.

[0060] In practical applications, in order to further ensure that the Flutter page can load the Native font, the number of retries N (N is an integer greater than 0) allowed when the file download fails can be set in advance, that is, the first program can perform at most N + 1 download operations on the font file corresponding to the corresponding URI by using the cloud download address corresponding to the corresponding URI. Here, the value of N can be set according to requirements. Exemplarily, N can be equal to the number of Internet Protocol (IP) address lists corresponding to the cloud download address corresponding to the corresponding URI after domain name resolution.

[0061] In actual application, during the process of loading Native fonts in the Flutter page using the font files in the second directory, in order to prevent the font files from being maliciously tampered with and ensure the data security of users, the validity of the font files can be verified.

[0062] Based on this, in one embodiment, the process of loading Native fonts in the Flutter page using the font files in the second directory may include:

[0063] The first program verifies the validity of each font file in the second directory; when the validity verification of the corresponding font file passes, the corresponding Native font is loaded in the Flutter page using the corresponding font file.

[0064] In actual application, the first program may verify the validity of the font file corresponding to the corresponding URI based on a preset first policy. The first policy can be set according to requirements. For example, the Message Digest Algorithm 5 can be used to verify the validity of the font file corresponding to the corresponding URI, etc.

[0065] In actual application, in order to further prevent the font files from being maliciously tampered with and ensure the data security of users, each font file can be encrypted in advance. Correspondingly, the first program can decrypt the corresponding font file and use the decrypted font file to load the corresponding Native font in the Flutter page.

[0066] Based on this, in one embodiment, when the validity verification of the corresponding font file passes, the process of loading the corresponding Native font in the Flutter page using the corresponding font file may include:

[0067] When the validity verification of the corresponding font file passes, the first program decrypts the corresponding font file and uses the decrypted font file to load the corresponding Native font in the Flutter page.

[0068] In actual application, the first program may decrypt the corresponding font file based on a preset second policy. The second policy can be set according to requirements. For example, font editing software such as FontCreator and FontForge can be used to decrypt the corresponding font file, etc.

[0069] In actual application, to ensure the normal display of the Flutter page, the system font to be loaded in the case where the Native font cannot be successfully loaded on the Flutter page can be preset. That is, the first program can load the preset system font on the Flutter page when the Native font cannot be successfully loaded using the font file in the second directory.

[0070] Based on this, in one embodiment, the method may further include:

[0071] When the first program cannot successfully load the Native font using the font file in the second directory, it loads the preset system font on the Flutter page.

[0072] In actual application, the situation where the Native font cannot be successfully loaded using the font file in the second directory may include one of the following:

[0073] The font file corresponding to the corresponding URI cannot be downloaded to the second directory using the cloud download address corresponding to the corresponding URI;

[0074] The corresponding font file fails the validity check;

[0075] The corresponding font file cannot be successfully decrypted.

[0076] In actual application, using the at least one URI can also enable the first program and other programs (denoted as the second program in the subsequent description) of the electronic device to share the same font resource. That is, the second program can obtain the font file in the second directory using the at least one URI, and use the font file in the second directory to load the Native font on the Flutter page and / or the Native page; it can be understood that both the first program and the second program have access rights to the second directory.

[0077] The font loading method provided by the embodiment of the present application is that the first program of the electronic device caches the font files in the first directory of the electronic device to the preset second directory of the electronic device; the font files in the first directory include the Native font resources of the first program; the first program uses at least one preset URI to obtain the font files in the second directory, and uses the font files in the second directory to load Native fonts on the Flutter page; each URI corresponds to at least one font file in the second directory. In the solution of the embodiment of the present application, the first program caches the font files in the first directory containing Native font resources to the preset second directory, and uses the font files in the second directory to load Native fonts on the Flutter page; in this way, for an APP developed by mixing Native technology and Flutter technology, the Native page and the Flutter page can share a copy of Native font resources (that is, the font files in the first directory). In other words, it is not necessary to store two identical font resources for the Native page and the Flutter page respectively in the installation package of the APP, but only one font resource needs to be stored in the installation package of the APP, so as to effectively reduce the volume of the installation package of the APP, and then improve the efficiency of users downloading and installing the APP, and enhance the user experience.

[0078] The following further describes the present application in detail in combination with application embodiments.

[0079] In this application embodiment, after the APP (i.e., the above-mentioned first program) is started for the first time, the existing Native built-in font resources (i.e., the Native font resources stored in the installation package of the APP) are pre-stored in a specified directory (i.e., the above-mentioned second directory) by caching, and are shared with the Flutter side (i.e., the Flutter page) of this APP or shared with other APPs (such as the above-mentioned second program) by URI loading.

[0080] In this application embodiment, the APP includes a font preloading module, a font URI parsing module, and a cloud loading module; among them,

[0081] The font preloading module is used to, when the APP is launched for the first time, process the caching operation of the font file containing the Native font resources by starting a separately set thread (i.e., the above-mentioned first thread), so as to circularly cache the Native font resources into the specified cache directory on the disk (i.e., the second directory of the above-mentioned electronic device). Here, the "circular" means that when the cached font file is deleted under specific circumstances (such as when the user actively deletes the cache, the cache management software clears the APP cache, etc.), the APP will check whether there is a cached font file in the cache directory after the next startup, and automatically cache the font file containing the Native font resources into the cache directory when it is detected that there is no cached font file.

[0082] The font URI parsing module is used to, through the URI parameter information configured in the font display component (i.e., the above-mentioned preset at least one URI), check whether there is a corresponding font file in the cache directory when the Flutter page needs to load the Native font. Here, the URI parameter information can include "nativeFont: font name", and the font URI parsing module can check whether there is a font file corresponding to the font name in the cache directory according to the font name included in the URI parameter information. In addition, each built-in Native font can correspond one-to-one with the font file in the cloud, that is, the font URI parsing module can notify the cloud loading module when the local font file cannot be loaded normally, so as to pull the font file in the cloud for loading.

[0083] The cloud loading module is used to parse the corresponding cloud font download address through the URI parameter information. In other words, each URI corresponds to a cloud font download address, and the cloud loading module can perform domain name resolution on the cloud font download address and use the resolved IP address to download the corresponding font file. Here, if the font file download fails, it is allowed to retry N times (N represents the number of IP address lists corresponding after domain name resolution), that is, at most N + 1 font file download operations can be performed.

[0084] In this application embodiment, the APP will perform validity verification on the font file obtained from the local or the cloud to prevent the font file from being maliciously tampered with and affecting the user experience. In addition, the font file can be encrypted in advance, that is, the APP will decrypt the font file and then load the corresponding Native font.

[0085] In this application embodiment, as Figure 2 shown, the font loading process of the APP can specifically include the following steps:

[0086] Step 201: The font preloading module checks whether the font file is successfully cached; if not, execute Step 202; if so, execute Step 203;

[0087] Step 202: Cache the font file; then execute Step 203;

[0088] Step 203: Open the Flutter page to load the Native font; then execute Step 204;

[0089] Step 204: The font URI parsing module detects whether the font file corresponding to the URI exists; if it exists, execute Step 207; if not, execute Step 205;

[0090] Step 205: The cloud loading module downloads the font file corresponding to the URI; then execute Step 206;

[0091] Step 206: Determine whether the font file is successfully downloaded; if so, execute Step 207; if not, execute Step 208;

[0092] Step 207: Determine whether the font file passes the validity check; if so, execute Step 209; if not, execute Step 208;

[0093] Step 208: The Flutter page displays the system font;

[0094] Step 209: Determine whether the font file is successfully decrypted; if so, execute Step 210; if not, execute Step 208;

[0095] Step 210: The Flutter page displays the Native font.

[0096] In this application embodiment, when the APP is started for the first time, the font file containing the Native font resources is cached; after the APP is started next time, the font cache file will be checked. If the cached font file is not detected, the Native font file will be automatically cached to the specified cache directory; the Flutter page of the APP can load the specified Native font through the URI parameter information configured in the font display component.

[0097] In the embodiments of this application, the rules for loading Native fonts include: using the font name obtained by parsing the URI link, preferentially loading the locally cached font files, and each font file corresponds one-to-one with the cloud font files (it can also be understood that each Native font corresponds one-to-one with the cloud font files). When the locally cached font file cannot be loaded normally, the APP will pull the cloud font file for loading to display the Native font. When the APP fails to download the font file from the cloud, the APP defaults to displaying the specified system font on the Flutter page.

[0098] In actual application, during the process of rendering Native fonts on the Flutter page of the APP, the APP can first pre-load the locally cached font files, that is, check whether the locally cached font files exist and are available (i.e., validity verification). If valid, the APP can directly read the font files from the cache directory and display the corresponding custom Native fonts. It can be understood that this reading method requires pre-loading the custom font resources (i.e., the font files in the cache directory) before the Flutter page is loaded.

[0099] The solution provided by the embodiments of this application optimizes and improves the loading method of Native fonts on the Flutter page, and specifically has the following advantages:

[0100] 1) The Flutter page and the Native page can share the same font resources;

[0101] 2) Effectively reduce the volume of the APP installation package;

[0102] 3) Multiple APPs can share the same font resources.

[0103] To implement the method of the embodiments of this application, the embodiments of this application also provide a font loading device, as Figure 3 shown. The font loading device 302 is set on the electronic device 301. The device includes:

[0104] The first program unit 303 is used to cache the font files in the first directory of the electronic device 301 to the second directory of the preset electronic device 301; obtain the font files in the second directory by using at least one preset URI, and use the font files in the second directory to load Native fonts on the Flutter page; the first program unit 303 is implemented based on Native technology and Flutter technology; the font files in the first directory include the Native font resources of the first program unit 303; each URI corresponds to at least one font file in the second directory.

[0105] Wherein, in one embodiment, the first program unit 303 is specifically configured to:

[0106] Detect whether there is a cached font file in the second directory at startup;

[0107] In the case where no cached font file is detected in the second directory, cache the font files in the first directory to the second directory.

[0108] In one embodiment, the first program unit 303 is further configured to, for each of the at least one URIs, detect whether there is a font file corresponding to the corresponding URI in the second directory; in the case where it is determined that there is a font file corresponding to the corresponding URI in the second directory, obtain the font file corresponding to the corresponding URI.

[0109] In one embodiment, each URI also corresponds to a cloud download address of a font file; the first program unit 303 is further configured to, for each of the at least one URIs, detect whether there is a font file corresponding to the corresponding URI in the second directory; in the case where it is determined that there is no font file corresponding to the corresponding URI in the second directory, download the font file corresponding to the corresponding URI to the second directory using the cloud download address corresponding to the corresponding URI; and obtain the font file corresponding to the corresponding URI.

[0110] In one embodiment, the first program unit 303 is further configured to verify the validity of each font file in the second directory; in the case where the validity verification of the corresponding font file passes, load the corresponding Native font on the Flutter page using the corresponding font file.

[0111] In one embodiment, the first program unit 303 is further configured to, in the case where the validity verification of the corresponding font file passes, decrypt the corresponding font file, and load the corresponding Native font on the Flutter page using the decrypted font file.

[0112] In one embodiment, the first program unit 303 is further configured to, in the case where the Native font cannot be successfully loaded using the font file in the second directory, load a preset system font on the Flutter page.

[0113] Here, the functions of the first program unit 303 are equivalent to the functions of the font preloading module, the font URI parsing module, and the cloud loading module in the above application embodiment.

[0114] In actual application, the first program unit 303 may be implemented by a processor in the font loading device.

[0115] It should be noted that: when the font loading device provided in the above embodiments loads fonts, only the division of the above program modules is used for illustration. In actual applications, the above processing can be allocated to different program modules according to needs, that is, the internal structure of the device is divided into different program modules to complete all or part of the above-described processing. In addition, the font loading device provided in the above embodiments and the embodiments of the font loading method belong to the same concept. For the specific implementation process, please refer to the method embodiments and will not be elaborated here.

[0116] Based on the hardware implementation of the above program modules, and in order to implement the method of the embodiments of the present application, the embodiments of the present application further provide an electronic device, as Figure 4 shown. The electronic device 400 includes:

[0117] A communication interface 401, capable of interacting with other electronic devices;

[0118] A processor 402, connected to the communication interface 401 to implement information interaction with other electronic devices, and used to execute the method provided by the above one or more technical solutions when running a computer program;

[0119] A memory 403, storing a computer program that can run on the processor 402.

[0120] Specifically, the processor 402 is used for:

[0121] By running the first program stored in the memory 403, cache the font files in the first directory of the electronic device 400 to the second directory preset in the electronic device 400; the first program is implemented based on Native technology and Flutter technology; the font files in the first directory include the Native font resources of the first program;

[0122] By running the first program, obtain the font files in the second directory using at least one preset URI, and use the font files in the second directory to load Native fonts on the Flutter page; each URI corresponds to at least one font file in the second directory.

[0123] Among them, in one embodiment, the processor 402 is specifically used for:

[0124] By running the first program, detect whether there are cached font files in the second directory when the first program starts;

[0125] By running the first program, in the case where no cached font files are detected in the second directory, cache the font files in the first directory to the second directory.

[0126] In one embodiment, the processor 402 is further configured to, by running the first program, for each of the at least one URIs, detect whether a font file corresponding to the corresponding URI exists in the second directory; and in the case where it is determined that a font file corresponding to the corresponding URI exists in the second directory, obtain the font file corresponding to the corresponding URI.

[0127] In one embodiment, each URI further corresponds to a cloud download address of a font file; the processor 402 is further configured to, by running the first program, for each of the at least one URIs, detect whether a font file corresponding to the corresponding URI exists in the second directory; in the case where it is determined that a font file corresponding to the corresponding URI does not exist in the second directory, download the font file corresponding to the corresponding URI to the second directory by using the cloud download address corresponding to the corresponding URI; and obtain the font file corresponding to the corresponding URI.

[0128] In one embodiment, the processor 402 is further configured to, by running the first program, verify the validity of each font file in the second directory; and in the case where the validity verification of the corresponding font file passes, load the corresponding Native font on the Flutter page by using the corresponding font file.

[0129] In one embodiment, the processor 402 is further configured to, by running the first program, decrypt the corresponding font file in the case where the validity verification of the corresponding font file passes, and load the corresponding Native font on the Flutter page by using the decrypted font file.

[0130] In one embodiment, the processor 402 is further configured to, by running the first program, in the case where the Native font cannot be successfully loaded by using the font file in the second directory, load a preset system font on the Flutter page.

[0131] It should be noted that: The specific process of the processor 402 executing the above operations can be seen in the method embodiment, which will not be elaborated here.

[0132] Of course, in practical applications, the various components in the electronic device 400 are coupled together through the bus system 404. It can be understood that the bus system 404 is used to realize the connection and communication between these components. The bus system 404 includes not only a data bus, but also a power bus, a control bus, and a status signal bus. However, for the sake of clear description, in Figure 4 all kinds of buses are labeled as the bus system 404.

[0133] The memory 403 in the embodiments of the present application is used to store various types of data to support the operation of the electronic device 400. Examples of such data include: any computer program for operating on the electronic device 400.

[0134] The methods disclosed in the embodiments of the present application described above can be applied to or implemented by the processor 402. The processor 402 may be an integrated circuit chip with signal processing capabilities. In the implementation process, the steps of the above methods can be completed by the integrated logic circuit in the hardware of the processor 402 or instructions in the form of software. The above-mentioned processor 402 may be a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The processor 402 can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor may be a microprocessor or any conventional processor, etc. Combining the steps of the methods disclosed in the embodiments of the present application, it can be directly embodied as being executed and completed by the hardware decoding processor, or executed and completed by a combination of the hardware and software modules in the decoding processor. The software module may be located in a storage medium, and this storage medium is located in the memory 403. The processor 402 reads the information in the memory 403 and combines its hardware to complete the steps of the foregoing methods.

[0135] In an exemplary embodiment, the electronic device 400 can be implemented by one or more application-specific integrated circuits (ASICs), DSPs, programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field-programmable gate arrays (FPGAs), general-purpose processors, controllers, microcontroller units (MCUs), microprocessors, or other electronic components for executing the foregoing methods.

[0136] It can be understood that the memory 403 in the embodiments of the present application can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM, Read Only Memory), a programmable read-only memory (PROM, Programmable Read-Only Memory), an erasable programmable read-only memory (EPROM, Erasable Programmable Read-Only Memory), an electrically erasable programmable read-only memory (EEPROM, Electrically Erasable Programmable Read-Only Memory), a ferromagnetic random access memory (FRAM, ferromagnetic random access memory), a flash memory (FlashMemory), a magnetic surface memory, an optical disc, or a compact disc read-only memory (CD-ROM, Compact Disc Read-Only Memory); the magnetic surface memory can be a disk memory or a tape memory. The volatile memory can be a random access memory (RAM, Random Access Memory), which is used as an external cache. By way of example but not limitation, many forms of RAM are available, such as a static random access memory (SRAM, Static Random Access Memory), a synchronous static random access memory (SSRAM, Synchronous Static Random Access Memory), a dynamic random access memory (DRAM, Dynamic Random Access Memory), a synchronous dynamic random access memory (SDRAM, Synchronous Dynamic Random Access Memory), a double data rate synchronous dynamic random access memory (DDRSDRAM, Double Data Rate Synchronous Dynamic Random Access Memory), an enhanced synchronous dynamic random access memory (ESDRAM, Enhanced Synchronous Dynamic Random AccessMemory), a synchronous link dynamic random access memory (SLDRAM, SyncLink Dynamic Random AccessMemory), a direct rambus random access memory (DRRAM, Direct Rambus Random Access Memory).The memories described in the embodiments of the present application are intended to include, but are not limited to, these and any other suitable types of memories.

[0137] In an exemplary embodiment, the embodiments of the present application further provide a storage medium, namely a computer storage medium, specifically a computer-readable storage medium, for example, including a memory 403 storing a computer program, and the above computer program can be executed by a processor 402 of an electronic device 400 to complete the steps described in the foregoing method. The computer-readable storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, Flash Memory, magnetic surface memory, optical disc, or CD-ROM.

[0138] It should be noted that: "first", "second", etc. are used to distinguish similar objects and do not necessarily need to be used to describe a specific order or sequence.

[0139] In addition, the technical solutions described in the embodiments of the present application can be combined arbitrarily without conflict.

[0140] The above is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application.

Claims

1. A font loading method, characterized in that, Applied to an electronic device, including: The first program of the electronic device caches the font files in the first directory of the electronic device to the second directory of the preset electronic device; the font files in the first directory include the Native font resources of the first program; the first directory is the storage path of the Native font resources of the first program, and the second directory is the font resource cache path corresponding to the Flutter page of the first program. The first directory and the second directory are generated during the installation process of the first program on the electronic device; The first program uses at least one preset Uniform Resource Identifier (URI) to obtain the font files in the second directory, and uses the font files in the second directory to load Native fonts on the Flutter page; each URI corresponds to at least one font file in the second directory.

2. The method according to claim 1, wherein The caching of the font files in the first directory of the electronic device to the second directory of the preset electronic device includes: When the first program starts, it detects whether there are cached font files in the second directory; When the first program does not detect cached font files in the second directory, it caches the font files in the first directory to the second directory.

3. The method according to claim 1, wherein The obtaining of the font files in the second directory using at least one preset URI includes: For each URI in the at least one URI, the first program detects whether there is a font file corresponding to the corresponding URI in the second directory; when it is determined that there is a font file corresponding to the corresponding URI in the second directory, it obtains the font file corresponding to the corresponding URI.

4. The method according to claim 1, wherein Each URI also corresponds to a cloud download address of a font file; the obtaining of the font files in the second directory using at least one preset URI includes: For each URI in the at least one URI, the first program detects whether there is a font file corresponding to the corresponding URI in the second directory; when it is determined that there is no font file corresponding to the corresponding URI in the second directory, it downloads the font file corresponding to the corresponding URI to the second directory using the cloud download address corresponding to the corresponding URI; and obtains the font file corresponding to the corresponding URI.

5. The method according to any one of claims 1 to 4, characterized in that, The loading of Native fonts on the Flutter page using the font files in the second directory includes: The first program verifies the validity of each font file in the second directory; when the validity verification of the corresponding font file passes, it uses the corresponding font file to load the corresponding Native font on the Flutter page.

6. The method according to claim 5, wherein When the validity verification of the corresponding font file passes, the using of the corresponding font file to load the corresponding Native font on the Flutter page includes: When the validity verification of the corresponding font file passes, the first program decrypts the corresponding font file, and uses the decrypted font file to load the corresponding Native font on the Flutter page.

7. The method according to any one of claims 1 to 4, characterized in that The method further includes: When the first program fails to successfully load the Native font using the font file in the second directory, the preset system font is loaded on the Flutter page.

8. A font loading device, characterized in that, Set on an electronic device, including: A first program unit for caching the font file in the first directory of the electronic device to the second directory of the preset electronic device; obtaining the font file in the second directory using at least one preset URI, and loading the Native font on the Flutter page of the first program unit using the font file in the second directory; the font file in the first directory includes the Native font resources of the first program unit; each URI corresponds to at least one font file in the second directory; the first directory is the storage path of the Native font resources of the first program unit, the second directory is the font resource cache path corresponding to the Flutter page, and the first directory and the second directory are generated during the installation process of the first program unit on the electronic device.

9. An electronic device, characterized in that, Including: A processor and a memory for storing a computer program that can run on the processor, wherein, when the processor is used to run the computer program, it executes the steps of the method according to any one of claims 1 to 7.

10. A storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it realizes the steps of the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Resource sharing method and terminal

    CN107995245A

  • Fast page loading in hybrid applications

    CN110168539A