Search

CN-116339858-B - Font switching method and device, electronic equipment and storage medium

CN116339858BCN 116339858 BCN116339858 BCN 116339858BCN-116339858-B

Abstract

The application relates to the technical field of computers, and provides a font switching method, a font switching device, electronic equipment and a storage medium. The method comprises the steps of receiving a font switching instruction, pulling a target font configuration file from a cloud server, downloading the target switching font file into a local catalog of an application program, reading the target switching font file, converting the target switching font file into a font object which can be identified and rendered by an android system, analyzing the target font configuration file to obtain switching configuration information, rewriting a life cycle method of an interface display control of a display page of the target application program according to the switching configuration information to obtain a rewriting life cycle method, triggering the rewriting life cycle method to take effect when entering the display page of the target application program, transmitting the writing object, and switching the current application font of the display page of the target application program into the target switching font. The application can improve the download utilization rate of the application program by the user, reduce the compatibility and the safety risk of the system and has better stability.

Inventors

  • WEN ZHEN
  • YE SONGLIN

Assignees

  • 成都赛力斯科技有限公司

Dates

Publication Date
20260512
Application Date
20230330

Claims (10)

  1. 1. A font switching method, comprising: Receiving a font switching instruction, wherein the font switching instruction comprises a target application program and a target switching font; pulling a target font configuration file corresponding to the font switching instruction from a cloud server, and downloading the target switching font file corresponding to the target switching font from the cloud server to an application local directory; reading the target switching font file from the local catalog of the application program, and converting the target switching font file into a font object which can be identified and rendered by the android system; Analyzing the target font configuration file to obtain switching configuration information, wherein the switching configuration information comprises a target switching font, a switching mode, a switching method and a current application font of the target application program; according to the switching configuration information, rewriting a life cycle method of an interface display control of a display page of the target application program to obtain a rewriting life cycle method of the interface display control of the display page; And triggering the rewriting life cycle method to take effect and transmitting the font object when the display page of the target application program is entered, and switching the current application font of the display page of the target application program into a target switching font.
  2. 2. The method of claim 1, wherein the switching mode is a global switching mode; According to the switching configuration information, rewriting a life cycle method of an interface display control of a display page of the target application program to obtain a rewriting life cycle method of the interface display control of the display page, wherein the rewriting life cycle method comprises the following steps: Each display page in the target application program is determined to be a target switching page; According to the switching configuration information, rewriting the life cycle method of the interface display control of each target switching page to obtain a corresponding rewriting life cycle method; When entering the display page of the target application program, triggering the rewriting life cycle method to take effect and transmitting the font object, and switching the current application font of the display page of the target application program into a target switching font, wherein the method comprises the following steps: When any one target switching page in the target application program is entered, acquiring a root view of an interface display control of the target switching page; Traversing the root view, and finding out a target display control which is a text control or a subclass thereof in the interface display control, wherein the interface display control comprises a plurality of display controls, and the target display control is one or more of the plurality of display controls; triggering the rewriting life cycle method of the target switching page to take effect, and transmitting the font object, and switching the current application font of the page area corresponding to the target display control in the target switching page into a target switching font.
  3. 3. The method of claim 2, wherein triggering the overwrite lifecycle method of the target switch page to take effect and entering the font object, switching a current application font of a page area in the target switch page corresponding to the target display control to a target switch font comprises: If the current application fonts in the page area corresponding to the target display control in the target switching page have font styles, loading a target font file corresponding to the font styles from the target switching font file, and converting the target font file into a target font object which can be identified and rendered by the android system; Triggering the rewriting life cycle method of the target switching page to take effect, and transmitting the target font object, and switching the current application font of the page area corresponding to the target display control in the target switching page into a target switching font.
  4. 4. The method of claim 1, wherein the switch mode is a local switch mode, the switch configuration information further comprising a text control tab; According to the switching configuration information, rewriting a life cycle method of an interface display control of a display page of the target application program to obtain a rewriting life cycle method of the interface display control of the display page, wherein the rewriting life cycle method comprises the following steps: Each display page in the target application program is determined to be a target switching page; According to the switching configuration information, rewriting the life cycle method of the interface display control of each target switching page to obtain a corresponding rewriting life cycle method; When entering the display page of the target application program, triggering the rewriting life cycle method to take effect and transmitting the font object, and switching the current application font of the display page of the target application program into a target switching font, wherein the method comprises the following steps: when any one target switching page in the target application program is entered, acquiring label information of a text display control in interface display controls of the target switching page, wherein the interface display controls comprise a plurality of display controls, and the text display control is one or more of the plurality of display controls; screening out target text display controls with label information consistent with the text control labels from the text display controls; Triggering the rewriting life cycle method of the target switching page to take effect, and transmitting the font object, and switching the current application font of the page area corresponding to the target text display control in the target switching page into a target switching font.
  5. 5. The method of claim 1, wherein the switching mode is a multi-page switching mode, the switching method comprising a global font switching method or a local font switching method, the switching configuration information further comprising a plurality of page unique identification information; When entering the display page of the target application program, triggering the rewriting life cycle method to take effect and transmitting the font object, and switching the current application font of the display page of the target application program into a target switching font, wherein the method comprises the following steps: when entering a current display page of the target application program, acquiring page tag information of the current display page; If the unique page identification information comprises the page tag information, determining a target control which needs to be subjected to font switching on the current display page based on the switching method; Triggering the rewriting life cycle method of the current display page to take effect, and transmitting the font object, and switching the current application font of the page area corresponding to the target control in the current display page of the target application program into a target switching font.
  6. 6. The method of claim 1, wherein upon entering the display page of the target application, triggering the override lifecycle method to take effect and to pass into the font object, switching the current application font of the display page of the target application to a target switch font, comprising: When entering a display page A of the target application program, triggering a rewriting life cycle method of the display page A to take effect and transmitting the font object, switching the current application font of the display page A of the target application program into a target switching font, and recording font switching time; when the display page A is jumped to the display page B from the display page A, acquiring the jump time when the display page A is jumped back; Calculating the time difference between the jump time and the font switching time; and if the time difference value exceeds a preset time threshold value, re-triggering the rewriting life cycle method of the display page A to take effect and transmitting the font object, switching the current application font of the display page A of the target application program into a target switching font, and updating the font switching time.
  7. 7. The method of claim 1, wherein upon entering the display page of the target application, triggering the override lifecycle method to take effect and to pass into the font object, switching the current application font of the display page of the target application to a target switch font, comprising: setting a font switching field value of a display page A of the target application program as a first field value; when entering a display page A of the target application program, triggering a rewriting life cycle method of the display page A to take effect and transmitting the font object, switching the current application font of the display page A of the target application program into a target switching font, and modifying the first field value into a second field value; When the display page A is jumped to the display page B from the display page A, acquiring a font switching field value of the display page A; and if the font switching field value is the second field value, not triggering the rewriting life cycle method of the display page A to take effect again.
  8. 8. A font switching device, comprising: the receiving module is configured to receive a font switching instruction, wherein the font switching instruction comprises a target application program and a target switching font; The downloading module is configured to pull a target font configuration file corresponding to the font switching instruction from the cloud server and download the target switching font file corresponding to the target font configuration file from the cloud server into the local catalog of the application program; The conversion module is configured to read the target switching font file from the local directory of the application program and convert the target switching font file into a font object which can be identified and rendered by the android system; The analysis module is configured to analyze the target font configuration file to obtain switching configuration information, wherein the switching configuration information comprises a target switching font, a switching mode, a switching method and a current application font of the target application program; the rewriting module is configured to rewrite the life cycle method of the interface display control of the display page of the target application program according to the switching configuration information to obtain the rewriting life cycle method of the interface display control of the display page; And the switching module is configured to trigger the rewriting life cycle method to take effect and transmit the font object when entering the display page of the target application program, and switch the current application font of the display page of the target application program into a target switching font.
  9. 9. An electronic device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that the processor implements the steps of the method according to any of claims 1 to 7 when the computer program is executed.
  10. 10. A computer readable storage medium storing a computer program, characterized in that the computer program when executed by a processor implements the steps of the method according to any one of claims 1 to 7.

Description

Font switching method and device, electronic equipment and storage medium Technical Field The present application relates to the field of computer technologies, and in particular, to a font switching method, a font switching device, an electronic device, and a storage medium. Background With the continuous development of computer technology, terminal devices (such as mobile phones and computers) are increasingly widely used. The demands of users for personalization of application functions provided by terminal devices are increasing, for example, users want to be able to conveniently switch fonts of characters displayed by the terminal devices. In the prior art, a custom font file is generally packaged into an installation package of a third party application program, the installation package is installed in a terminal device, and the custom font file is covered with an original system font file in the terminal device, so that the terminal device can display characters of the terminal device by adopting fonts in the custom font file. Or after the user downloads the installation package of the third party application program, the installation package is required to be intercepted through a hook system API (programming interface), the installation package is required to be decompressed and decompiled to obtain a source code, an original font file referenced by the font defining the third party application program in the source code is replaced by the custom font file, a modified application program is obtained, the modified application program is repackaged to obtain a new application program package, and finally the new application program package is installed on the terminal equipment, so that the terminal equipment can display the characters of the terminal equipment by adopting the fonts in the custom font file. Therefore, the existing font switching method needs to pack the custom font file into the installation package of the third party application program, the size of the installation package of the application program can be obviously increased, the more the packed custom font file is, the larger the installation package is, the lower the downloading utilization rate of the application program is easily caused by a user, or the third party application program needs to be decompiled and repacked through the hook system API, the compatibility and the security risk easily exist in the process, and the stability is poor. Disclosure of Invention In view of the above, embodiments of the present application provide a font switching method, apparatus, electronic device, and storage medium, so as to solve the problems in the prior art that a custom font file needs to be packaged into an installation package of a third party application program, the size of the installation package is obviously increased, and the download usage rate of a user to the application program is reduced, or the third party application program needs to be decompiled and repacked through an API of a hook system, which is easy to have compatibility and security risks, and has poor stability. In a first aspect of an embodiment of the present application, a font switching method is provided, including: Receiving a font switching instruction, wherein the font switching instruction comprises a target application program and a target switching font; pulling a target font configuration file corresponding to the font switching instruction from the cloud server, and downloading the target switching font file corresponding to the target font configuration file from the cloud server to the local catalog of the application program; Reading a target switching font file from the local directory of the application program, and converting the target switching font file into a font object which can be identified and rendered by the android system; Analyzing the target font configuration file to obtain switching configuration information, wherein the switching configuration information comprises a target switching font, a switching mode, a switching method and a current application font of a target application program; According to the switching configuration information, rewriting a life cycle method of an interface display control of a display page of a target application program to obtain a rewriting life cycle method of the interface display control of the display page; and when the display page of the target application program is entered, triggering the rewriting life cycle method to take effect and transmitting the font object, and switching the current application font of the display page of the target application program into the target switching font. In a second aspect of an embodiment of the present application, there is provided a font switching device, including: the receiving module is configured to receive a font switching instruction, wherein the font switching instruction comprises a target application program and a target switching fo