Font switching method and device, electronic equipment and storage medium

CN117350248BActive Publication Date: 2026-10-09VIVO MOBILE COMM CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311427234.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-10-30
Publication Date
2026-10-09
Estimated Expiration
2043-10-30

AI Technical Summary

Technical Problem

相关技术中,在进行系统字体切换时,会消耗大量系统内存,导致系统操作卡顿,影响电子设备的正常工作

Benefits of technology

[0017] In a sixth aspect, embodiments of this application provide a computer program product stored in a storage medium, which is executed by at least one processor to implement the steps of the font switching method as described in the first aspect.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117350248B_ABST
    Figure CN117350248B_ABST
Patent Text Reader

Abstract

The application discloses a font switching method and device, electronic equipment and a storage medium, and belongs to the technical field of electronic equipment. The method comprises the following steps: in response to a font switching instruction, a first font family file corresponding to a first font is found according to the mapping relationship between a font and a font family in a system font configuration file; the font switching instruction is used to indicate that the system font is switched from the first font to a second font, and a first font file used to draw the first font is contained in the first font family file; a second font file used to draw the second font is created; the first font file in the first font family file is replaced by the second font file; and in response to the operation of a user opening an interface, view text on the interface is rendered based on the second font file in the first font family file.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of electronic equipment technology, specifically relating to a font switching method, device, electronic equipment, and storage medium. Background Technology

[0002] With the rapid development of electronic devices, ease of operation and user-friendly design have become indispensable aspects. For example, users may want to switch the system font on their electronic devices for a richer visual experience. However, in some technologies, switching system fonts consumes a significant amount of system memory, causing system lag and affecting the normal operation of the electronic device. Summary of the Invention

[0003] The purpose of this application is to provide a font switching method, apparatus, electronic device, and storage medium that can reduce the amount of memory consumed by system font switching and ensure the normal operation of electronic devices.

[0004] In a first aspect, embodiments of this application provide a font switching method, the method comprising:

[0005] In response to a font switching command, the system locates the first font family file corresponding to the first font based on the mapping relationship between fonts and font families in the system font configuration file; the font switching command is used to indicate that the system font is switched from the first font to the second font, and the first font family file contains a first glyph file for drawing the first font;

[0006] Create a second glyph file for drawing the second font;

[0007] Replace the first font file in the first font family file with the second font file;

[0008] In response to the user's operation of opening the interface, the view text on the interface is rendered using the second font file in the first font family file.

[0009] Secondly, embodiments of this application provide a font switching device, the method comprising:

[0010] The lookup module is used to respond to a font switching command and, based on the mapping relationship between fonts and font families in the system font configuration file, find the first font family file corresponding to the first font; the font switching command is used to instruct the system font to be switched from the first font to the second font, and the first font family file contains a first glyph file for drawing the first font;

[0011] Create a module to create a second glyph file for drawing the second font;

[0012] The replacement module is used to replace the first font file in the first font family file with the second font file;

[0013] The rendering module is used to render the view text on the interface in response to the user's operation of opening the interface, based on the second font file in the first font family file.

[0014] Thirdly, embodiments of this application provide an electronic device including a processor and a memory, wherein the memory stores a program or instructions executable on the processor, and the program or instructions, when executed by the processor, implement the steps of the font switching method as described in the first aspect.

[0015] Fourthly, embodiments of this application provide a readable storage medium storing a program or instructions that, when executed by a processor, implement the steps of the font switching method as described in the first aspect.

[0016] Fifthly, embodiments of this application provide a chip, the chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the steps of the font switching method as described in the first aspect.

[0017] In a sixth aspect, embodiments of this application provide a computer program product stored in a storage medium, which is executed by at least one processor to implement the steps of the font switching method as described in the first aspect.

[0018] In this embodiment, in response to a font switching command, the system locates the first font family file corresponding to the first font based on the font-font family mapping relationship in the system font configuration file. The font switching command instructs the system font to be switched from the first font to the second font. The first font family file contains a first glyph file for drawing the first font. A second glyph file for drawing the second font is created. The first glyph file in the first font family file is replaced with the second glyph file. In response to the user opening the interface, the view text on the interface is rendered based on the second glyph file in the first font family file. Therefore, in this embodiment, when the user switches the system font, the font switching on the interface can be achieved by updating the font's glyph file. Since creating the glyph file occupies less system memory, the amount of memory consumed by system font switching can be reduced, ensuring the normal operation of the electronic device. Attached Figure Description

[0019] Figure 1 This is one of the example diagrams showing the font effects of different visual size values ​​provided in the embodiments of this application;

[0020] Figure 2 This is the second example of the font effect with different visual size values ​​provided in the embodiments of this application;

[0021] Figure 3 This is one of the flowcharts of a font switching method provided in the embodiments of this application;

[0022] Figure 4 This is a second flowchart of a font switching method provided in an embodiment of this application;

[0023] Figure 5 This is a structural block diagram of a font switching device provided in an embodiment of this application;

[0024] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application;

[0025] Figure 7 This is a schematic diagram of the hardware structure of an electronic device that implements the various embodiments of this application. Detailed Implementation

[0026] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.

[0027] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such terms can be used interchangeably where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, the character " / " generally indicates that the preceding and following objects have an "or" relationship.

[0028] This application provides a font switching method, apparatus, electronic device, and storage medium. For ease of understanding, some concepts and application scenarios involved in the embodiments of this application will first be introduced.

[0029] I. Concept

[0030] The system runtime library layer, also known as the Native layer, is a layer in the Android system architecture that provides support for the main features of the Android system through C / C++ libraries.

[0031] The application framework layer, also known as the Java layer, is a layer in the Android system architecture. This layer mainly provides various APIs that may be used when building applications. Some core applications that come with the Android system are implemented using these APIs, and developers can also use these APIs to build their own applications.

[0032] A Typeface object, also known as a font object or font file, is a class that represents a font. It represents a collection of glyphs in a specific style and can be used to render view text in Android applications. Typeface objects can be created by loading from system resources or custom font files. The Android system provides several predefined font styles, such as KaiTi, SongTi, HeiTi, FangSongTi, and Founder Fonts, and you can also create Typeface objects using custom font files.

[0033] A Font object, also known as a font file, is a reference to a font, usually a predefined system font or a developer-defined font. It stores information such as the path to the font file and the font's variable axis parameters.

[0034] A FontFamily object, also known as a font family object or font family file, is a class that represents a group of font families. It can be used to create Typeface objects. A FontFamily object contains many Font objects, which are like containers for Font objects. It can be used to draw fonts with various text styles.

[0035] The fonts.xml file, also known as the system font configuration file, is the configuration file for all font files in the system. The fonts.xml file contains multiple... <family>`tags and multiple` <alias>`tags, where` <family>`The tag is a font family tag,` <alias>The `tag` is an alias tag, each `` <family>`The tag contains multiple` <font>`tag,` <font>The tag is a font tag, each ` <font>The `<script>` tag contains the path information of the font file and `` <axis>`tag,` <axis>`The tag is a variable axis tag for font.` <axis>The `<label>` contains font variable axis parameters. <alias>`Labels are used to indicate` <axis>The `<font>` tag contains aliases for the variable axis parameters of each font. In the fonts.xml file, there is a special family named `sans-serif`, which represents the font family currently used by the system.

[0036] Font styles refer to various online fonts, including colored or other fonts. Theme stores offer a wide variety of fonts for download, such as KaiTi, SongTi, and HeiTi.

[0037] The weight of a font, also known as its thickness, usually includes multiple levels, such as nine levels: 100, 200, 300, 350, 400, 500, 600, 700, and 800, which correspond to Thin / Hairline, Extra-Light / Ultra-Light, Light, Demi-Light, Regular / Normal / Book / Plain, Medium, Demi-Bold / Semi-Bold, Bold, and Extra-bold / Extra. For example, it includes 8 levels: 100, 200, 300, 400, 500, 600, 700, and 800, which correspond to Thin / Hairline, Extra-Light / Ultra-Light, Light, Regular / Normal / Book / Plain, Medium, Demi-Bold / Semi-Bold, Bold, and Extra-bold / Extra.

[0038] The visual size of a font, also known as its central area, typically includes multiple levels, such as 13 levels. Visual size usually encompasses the following characteristics: scaling characteristics, stroke avoidance characteristics, intersection thinning characteristics, and spatial characteristics. Regarding scaling characteristics, smaller font sizes use larger character surfaces and a larger central area to improve readability, while larger font sizes have a smaller central area to improve aesthetics. Regarding stroke avoidance characteristics, smaller font sizes use stroke avoidance to increase the spacing between strokes and reduce visual clutter. Regarding intersection thinning characteristics, smaller font sizes thin out the intersections of complex strokes to make them clearer. Regarding spatial characteristics, ... Figure 1 For example, the central circles on the left and right sides are the same size, but the outer circles on the right are smaller, creating the illusion that the central circle on the right is larger than the one on the left. This is the principle of visual illusion: within a specific frame, appropriately increasing the central space and decreasing the space at the edges enlarges the central area, enhancing the visible range of the text and making the text more eye-catching and readable. Figure 2 For example, in the top group of nine squares, the middle square is large and the surrounding squares are small, which makes it appear spacious. In the bottom group of nine squares, all nine squares are the same size, which makes it appear compact. As the nine squares change from small to large, the feeling of spaciousness and compactness will be enhanced, and the difference will be more obvious. It can be seen that in the last two small nine squares, the small squares in the top group are visually more spacious than the small squares in the bottom group.

[0039] Font refers to the broader concept of a font's style, thickness, and visual size.

[0040] Native font loading process: When an electronic device boots up, the system service process (Systemserver process) parses the fonts.xml file and instantiates Typeface, Font, and FontFamily objects. These objects contain the parameters required for font display and are passed to the system's underlying rendering engine for font rendering. The Typeface object created above exists only in the Systemserver process. When the application process starts, the Systemserver process passes the Typeface object to the application process via shared memory, ensuring that the view text on the application interface can be displayed correctly.

[0041] Functions used in the native font loading process:

[0042] The loadPreinstalledSystemFontMap function is used to trigger the loading process of the system's native fonts. Internally, it can call the following four functions: getSystemPreinstalledFontConfig(), buildSystemFallback(), buildSystemTypefaces(), and setSystemFontMap().

[0043] The `getSystemPreinstalledFontConfig()` function is used to parse the `fonts.xml` file. This function will parse the `` in the `fonts.xml` file. <family>`tags and` <alias>`tags, based on` <family>`tags and` <alias>The `tag` creates a FontConfig object, which includes a FontFamily object and an Alias ​​object.

[0044] The `buildSystemFallback()` function is used to create a Map based on the `FontConfig` object created by the `getSystemPreinstalledFontConfig()` function.<String,FontFamily[]> In this case, the key value of the Map is ` <family>The function, which takes the name of the tag, will create the Native layer FontFamily object and the Font object.

[0045] The `buildSystemTypefaces()` function is used to generate an Alias ​​object from the `getSystemPreinstalledFontConfig()` function and a Map from the `buildSystemFallback()` function.<String,FontFamily[]> Create a Typeface object, i.e., a Map.<String,Typeface> The key values ​​of the Map include ` <family>`tag name and` <alias>The reason for the tag's name is... <family>`tags and` <alias>`The tags have a mapping relationship,` <alias>The tag records the name of the font weight, the font source, and the font weight value used.

[0046] For example, `<alias name="sans-serif-thin"to="sans-serif"weight="200" / > ` indicates that the application can use `android:fontFamily="sans-serif-thin"` as the font weight for 200 characters, which is taken from `<family name="sans-serif"> `tag`

[0047] The `setSystemFontMap()` function is used to initialize `Map`.<String,Typeface> `sSystemFontMap` and `Typeface[]sDefaults`, that is, Map<String,Typeface> The Map in the code is directly assigned to sSystemFontMap, which is a very important object containing all the Typeface objects used by the system interface. The interface tells the system which font weight to use by passing in `android:fontFamily`, and the system will directly retrieve the corresponding font weight's Typeface object from sSystemFontMap for the interface to use.

[0048] Functions used in the font switching process:

[0049] The `updatePersistentConfigurationWithAttribution` function is the entry point function triggered by font switching. This function is called when the user switches the font style or adjusts the font weight or size.

[0050] The `createFonts` function is used to create new Font objects.

[0051] The `updateFont` function replaces the `Font` object in the `FontFamily` object. Internally, it calls three native method interfaces to bring the process into the Native layer and replace the `Font` object in the Native layer's `FontFamily` object.

[0052] The nResetFont function, a Native interface function, is used to delete the Font object of the current Native layer FontFamily object.

[0053] The nVAddFont function, a Native interface function, is used to add a new Font object to a FontFamily object.

[0054] The `nRefreshCoverage` function is a native interface function used to re-trigger the underlying rendering.

[0055] II. Application Scenarios

[0056] In electronic devices, fonts are extremely important in system interfaces and application interfaces. Font style, weight, and visual size are core attributes that play a crucial role in the presentation of text on the interface. Currently, users want to be able to switch the font on their electronic device's system for a richer visual experience.

[0057] III. Differences between related technologies and embodiments of this application

[0058] In related technologies, only font style and font weight switching can be implemented, but not font visual size switching. When implementing font style and font weight switching, the solution used is to update the Typeface object. Each time the font is switched, a new Typeface object needs to be created and replaced. The Typeface object is replaced in the JAVA layer. This solution will cause system memory fluctuations and consume a lot of system memory. Since each creation of a Typeface object requires a lot of system memory, and the frequency of Typeface object creation is very high, if users frequently switch fonts, it will cause system memory overflow, background processes will be frequently killed, system operation will be slowed down, and electronic devices will not be able to work properly.

[0059] In this embodiment, in addition to defining different font file path information and font weight levels for each family in the fonts.xml file, it also defines different visual size levels for each family and defines alias tags for each level, enabling not only switching of font style and font weight but also switching of font visual size. The approach to implementing font style, font weight, and font visual size switching is to update the Font object. This involves reverse-searching the FontFamily object corresponding to the currently used font's Typeface object, and then replacing the Font object in the FontFamily object with the Font object of the font to be switched at the Native layer. This fully integrates the Java layer and the Native layer. Since creating a new Font object each time requires less system memory, it reduces the memory consumed by system font switching, ensuring the normal operation of electronic devices.

[0060] The font switching method provided in the embodiments of this application will now be described in detail.

[0061] It should be noted that the font switching method provided in this application embodiment is applicable to electronic devices. In practical applications, the electronic device may include mobile terminals such as smartphones, tablets, and personal digital assistants. This application embodiment does not limit this.

[0062] Figure 3 This is one of the flowcharts of a font switching method provided in the embodiments of this application, such as... Figure 3 As shown, the method may include the following steps: step 301, step 302, step 303 and step 304;

[0063] In step 301, in response to the font switching instruction, the first font family file corresponding to the first font is found according to the mapping relationship between fonts and font families in the system font configuration file; wherein, the font switching instruction is used to indicate that the system font is switched from the first font to the second font, and the first font family file contains the first glyph file used to draw the first font.

[0064] In this embodiment of the application, for ease of understanding and description, in the following scheme, "first Typeface object" is used as "first font", "first FontFamily object" is used as "first font family file", "first Font object" is used as "first font file" and "second Font object" is used as "second font file".

[0065] In this embodiment of the application, the mapping relationship between fonts and font families in the system font configuration file refers to the mapping relationship between the Typeface object and the FontFamily object recorded in the fonts.xml file. This mapping relationship can be parsed by the following functions: getSystemPreinstalledFontConfig(), buildSystemFallback(), buildSystemTypefaces(), and setSystemFontMap().

[0066] In this embodiment of the application, the first font is the font currently used by the system, and the second font is the font expected by the user. The first FontFamily object corresponding to the first Typeface object can be found through the mapping relationship between the Typeface object and the FontFamily object recorded in the fonts.xml file. The first FontFamily object contains the first Font object used to draw the first Typeface object.

[0067] In some embodiments, each font file may include: path information of the font library file and font variable axis parameters, wherein each font variable axis parameter includes at least one of: font weight value and visual size value; a font style corresponds to a font library file.

[0068] In this embodiment, the path information of the font library file is used to indicate the font library file of a font style, the font weight value in the font variable axis parameter is used to indicate the thickness of a font, and the visual size value in the font variable axis parameter is used to indicate the visual size of a font.

[0069] In this embodiment of the application, the first font file includes: path information of the font library file of the current font in the system and font variable axis parameters; the second font file includes: path information of the font library file of the font that the user wants to switch to and font variable axis parameters.

[0070] In this embodiment, font style switching can be achieved by changing the path information of the font library file in the font file; font weight switching can be achieved by changing the font weight value in the font file; and font visual size switching can be achieved by changing the visual size value in the font file.

[0071] As can be seen, in this embodiment of the application, each font file can contain parameters of multiple dimensions such as font style, thickness and visual size, so that by changing the above parameters in the font file, the font can be switched without modifying the code, which is highly flexible.

[0072] In some embodiments, the system font configuration file contains multiple font family tags and multiple alias tags; each font family tag contains multiple glyph tags, each glyph tag contains the path information of the font library file and a font variable axis tag, each font variable axis tag contains font variable axis parameters, and the alias tags are used to identify the font variable axis parameters.

[0073] In this embodiment of the application, the fonts.xml file can exhaustively list all permutations and combinations of font weight and visual size. The Typeface object generated by parsing in this way contains all combinations of font weight and visual size. When setting the font, the interface can first match the required visual size value according to the current font size, and then match the final required Typeface object according to the required visual size value and the required font weight value, thereby realizing the switching effect of font visual size.

[0074] For example, there are 13 FontFamily objects related to the visual size of the fonts in the fonts.xml file, with the values ​​of the variable axis of visual size corresponding to 10 to 22 respectively; each FontFamily object contains 8 Typeface objects with different font weights, with the values ​​of the variable axis of font weight corresponding to 100 to 800 respectively.

[0075] As can be seen, in this embodiment, in addition to defining different font file path information and font weight levels for each family in the fonts.xml file, it also defines different visual size levels for each family and defines an alias tag for each level. This enables not only switching of font style and weight but also switching of font visual size. Furthermore, by defining the visual size levels and aliases in the fonts.xml file, it is convenient for later maintenance and modification. If new font variable features need to be added later, only the fonts.xml file needs to be modified without modifying the application code, thus improving the maintainability of the application.

[0076] In this embodiment, the font switching command can be triggered by the user through a font switching control on the operating system interface. For example, the system settings interface includes the following font switching controls: a font style switching control, a font weight switching control, and a font size switching control. The user can switch the font style by operating the font style switching control, switch the font weight by operating the font weight switching control, and switch the font size by operating the font size switching control. Alternatively, the font switching command can also be triggered by the user through a voice command.

[0077] In one example, the system is currently using the KaiTi font style, and the user wants to switch to the SongTi font style. That is, the first font style is KaiTi and the second font style is SongTi.

[0078] In one example, the system is currently using a KaiTi font with a Medium weight. The user wants to switch to a Thin font with a different weight. That is, the first font is KaiTi with a Medium weight, and the second font is KaiTi with a Thin weight.

[0079] In one example, the system is currently using the KaiTi font style and the font size is 12pt. The user wants to switch the font size to 12pt. That is, the first font style is KaiTi and the visual size is the visual size mapped to the 12pt font size, and the second font style is KaiTi and the visual size is the visual size mapped to the 12pt font size.

[0080] In step 302, a second glyph file is created for drawing the second font.

[0081] In this embodiment, the font switching instruction can carry font feature parameters of the second font. Based on these font feature parameters and the existing createFonts function, a second Font object for drawing the second font is created. Specifically, when switching font styles, a second Font object with the new font library path is created; when switching font weight, a second Font object with the new font weight value is created; and when switching font size, a second Font object with the visual size value mapped to the user-adjusted font size value is created.

[0082] In some embodiments, when a user switches the style of the system font, the font style of the first font is different from that of the second font; the font switching instruction carries the style identifier of the second font; accordingly, step 302 may include the following steps: step 3021 and step 3022;

[0083] In step 3021, the path information of the font file corresponding to the second font is determined according to the style identifier of the second font carried in the font switching instruction.

[0084] In step 3022, a second font file for drawing the second font is created based on the path information of the font library file corresponding to the second font.

[0085] In this embodiment of the application, for the scenario of font style switching, a font style switching control can be provided. Users can trigger a font switching instruction by operating the font style switching control. The font switching instruction carries the style identifier of the second font.

[0086] In this embodiment of the application, the style identifier of the second font can be obtained from the font switching instruction, the path information of the corresponding font library file can be determined according to the style identifier of the second font, and a second Font object containing the path information of the font library file corresponding to the second font and the font variable axis parameter can be created. The difference between the second Font object and the first Font object is that the path information of the font library file is different, but the variable axis parameter of the two can be the same.

[0087] As can be seen, in this embodiment of the application, when switching font styles, a second font file for drawing the second font can be created according to the style identifier of the second font carried in the font switching instruction. Since obtaining the style identifier and the font file path is relatively simple, creating the second font file will not occupy too much system resources, and the cost of switching font styles is low.

[0088] In some embodiments, when a user switches the weight of the system font, the weight value of the first font is different from that of the second font; the font switching instruction carries the weight adjustment value of the second font; accordingly, step 302 may include the following steps: step 3023 and step 3024.

[0089] In step 3023, the font weight value corresponding to the second font is determined according to the weight adjustment value and the base weight value of the second font carried in the font switching instruction.

[0090] In step 3024, a second font file for drawing the second font is created based on the font weight value corresponding to the second font.

[0091] In this embodiment of the application, for the scenario of switching font weight, a font weight switching control can be provided, such as a font weight slider control that can be slid left and right. The user can trigger a font switching command by operating the font weight switching control, and the font switching command carries the weight adjustment value of the second font.

[0092] In this embodiment, the weight adjustment value of the second font can be obtained from the font switching instruction. The weight adjustment value is a scaling factor. Since the weight of a font usually includes multiple levels, such as levels 100 to 800, the base weight value of level 100 to 800 can be multiplied by the weight adjustment value of the second font based on the base weight level to obtain the font weight value of the second font. A second Font object is then created, which includes the font weight value of the second font, the font library path information corresponding to the second font, and the visual size value. The difference between the second Font object and the first Font object is that the variable axis parameter of the font weight is different, but the font library path information and visual size value of the two can be the same.

[0093] In some embodiments provided in this application, when a user switches the font size of the system font, the font size value of the first font is different from the font size value of the second font; the font switching instruction carries the font size value of the second font; accordingly, the above step 302 may include the following steps: step 3025 and step 3026;

[0094] In step 3025, the visual size value corresponding to the second font is determined based on the font size value of the second font carried in the font switching instruction and the mapping relationship between the font size value and the visual size value.

[0095] In step 3026, a second glyph file for drawing the second font is created based on the visual size value corresponding to the second font.

[0096] In this embodiment, for the scenario of switching font visual size, there is no dedicated adjustment control for the font visual size value. Users cannot directly adjust the font visual size through explicit controls, unlike adjusting font style and font weight. Since the font visual size value is related to the font size, a font size switching control can be provided. When users adjust the font size using the font weight switching control, the font visual size value will change accordingly.

[0097] In this embodiment, the visual size and font weight of the font do not affect each other. The visual size is also one of the variable axis parameters. The font size value of the second font can be obtained from the font switching instruction. Since there is a mapping relationship between the font size and the visual size, the corresponding visual size value can be found based on the font size value of the second font. A second Font object containing the visual size value, the font library path information corresponding to the second font, and the font weight value can be created. The difference between the second Font object and the first Font object is that the variable axis parameter of the font visual size is different. The font library path information and font weight value of the two can be the same.

[0098] In step 303, the first font file in the first font family file is replaced with the second font file.

[0099] In this embodiment of the application, the updateFont function, nResetFont function, and nVAddFont function can be called to replace the first Font object in the first FontFamily object with the second Font object.

[0100] In step 304, in response to the user's operation of opening the interface, the view text on the interface is rendered using the second font file in the first font family file.

[0101] In this embodiment of the application, the interface can be a system interface or an application interface.

[0102] In this embodiment, the nRefreshCoverage function can be called to render the font of the view text on the interface based on the second Font object in the first FontFamily object, thereby realizing the display of the font on the interface.

[0103] As can be seen from the above embodiments, in this embodiment, in response to a font switching command, the system searches for a first font family file corresponding to the first font based on the font-font family mapping relationship in the system font configuration file; the font switching command is used to instruct the system font to be switched from the first font to the second font, and the first font family file contains a first glyph file for drawing the first font; a second glyph file for drawing the second font is created; the first glyph file in the first font family file is replaced with the second glyph file; in response to the user opening the interface, the view text on the interface is rendered based on the second glyph file in the first font family file. Therefore, in this embodiment, when the user switches the system font, the font switching on the interface can be achieved by updating the font glyph file. Since creating the glyph file occupies less system memory, the amount of memory consumed by system font switching can be reduced, ensuring the normal operation of the electronic device.

[0104] Figure 4 This is a second flowchart of a font switching method provided in this application embodiment. In this application embodiment, the font switching process is described from the perspective of operating system architecture. Accordingly, as shown... Figure 4 As shown, the method may include the following steps: step 401, step 402, step 403 and step 404;

[0105] In step 401, in response to the font switching instruction, the system finds the first font family file corresponding to the first font in the system runtime library layer according to the mapping relationship between fonts and font families in the system font configuration file.

[0106] In this embodiment of the application, since font rendering is performed in the Native layer, the first FontFamily object in the Native layer corresponding to the first Typeface object is found according to the mapping relationship between the Typeface object and the FontFamily object in the system font configuration file.

[0107] In this embodiment, the difference between switching the font of the system interface and switching the font of the application interface lies in the triggering method of the font switching command. When switching the font of the system interface, the font switching command is triggered through the entry point provided by the updatePersistentConfigurationWithAttribution function. When switching the font of the application interface, the font switching command is triggered through the entry point provided by the handleConfigurationChanged function. The font switching process after triggering the font switching command is the same, and steps 402 to 404 can be reused.

[0108] In step 402, at the application framework layer, a second font file for drawing the second font is created, and the second font file is passed from the application framework layer to the system runtime layer.

[0109] In this embodiment of the application, in the JAVA layer, a second Font object for drawing the second font can be created by calling the createFonts function, and the Font object can be passed from the JAVA layer to the Native layer by calling the updateFont function.

[0110] In step 403, at the system runtime library layer, the first font file in the first font family file is deleted, and the second font file is added to the first font family file.

[0111] In this embodiment of the application, at the Native layer, the first Font object in the FontFamily object is deleted by calling the nResetFont function, and the second Font object is added to the first FontFamily object by calling the nVAddFont function.

[0112] In step 404, in response to the user's operation of opening the interface, the system runtime library layer renders the view text on the interface based on the second font file in the first font family file.

[0113] In this embodiment of the application, in response to the user's operation of opening the interface, in the Native layer, based on the second Font object in the first FontFamily object and by calling the nRefreshCoverage function, the font rendering of the view text on the interface is triggered, thereby realizing the switching of the font on the interface.

[0114] As can be seen, unlike current methods that update the Typeface object only at the Java layer when implementing font switching, this approach differs from previous methods. These methods require updating the Typeface object, which only replaces the Typeface object at the Java layer. Each time a font is switched, a new Typeface object needs to be created and replaced. Since each creation of the Typeface object allocates additional memory, and the creation frequency is very high, frequent font switching can cause system memory fluctuations, consuming a large amount of system memory, leading to memory overflow, frequent killing of background processes, and system lag. In this embodiment, the solution is to update the Font object, fully integrating the Java and Native layers. Each creation of a new Font object does not occupy additional memory; the underlying layer reuses the Font object, making full use of system memory and avoiding memory fluctuations.

[0115] The font switching method provided in this application can be executed by a font switching device. This application uses the example of a font switching device executing the font switching method to illustrate the font switching device provided in this application.

[0116] Figure 5 This is a structural block diagram of a font switching device provided in some embodiments of this application, such as... Figure 5 As shown, the font switching device 500 may include: a search module 501, a creation module 502, a replacement module 503, and a rendering module 504;

[0117] The lookup module 501 is used to respond to a font switching command and look up the first font family file corresponding to the first font according to the mapping relationship between fonts and font families in the system font configuration file; the font switching command is used to indicate that the system font is switched from the first font to the second font, and the first font family file contains a first glyph file for drawing the first font;

[0118] Create module 502 to create a second glyph file for drawing the second font;

[0119] Replacement module 503 is used to replace the first font file in the first font family file with the second font file;

[0120] The rendering module 504 is used to render the view text on the interface in response to the user's operation of opening the interface, based on the second font file in the first font family file.

[0121] As can be seen from the above embodiments, in this embodiment, in response to a font switching command, the system searches for a first font family file corresponding to the first font based on the font-font family mapping relationship in the system font configuration file; the font switching command is used to instruct the system font to be switched from the first font to the second font, and the first font family file contains a first glyph file for drawing the first font; a second glyph file for drawing the second font is created; the first glyph file in the first font family file is replaced with the second glyph file; in response to the user opening the interface, the view text on the interface is rendered based on the second glyph file in the first font family file. Therefore, in this embodiment, when the user switches the system font, the font switching on the interface can be achieved by updating the font glyph file. Since creating the glyph file occupies less system memory, the amount of memory consumed by system font switching can be reduced, ensuring the normal operation of the electronic device.

[0122] Optionally, as an embodiment, the search module 501 may include:

[0123] The lookup submodule is used to respond to font switching commands by finding the first font family file in the system runtime library layer corresponding to the first font, based on the mapping relationship between fonts and font families in the system font configuration file.

[0124] The creation module 502 may include:

[0125] The first creation submodule is used to create a second font file for drawing the second font in the application framework layer, and to pass the second font file from the application framework layer to the system runtime library layer.

[0126] The replacement module 503 may include:

[0127] The replacement submodule is used in the system runtime library layer to delete the first font file in the first font family file and add the second font file to the first font family file.

[0128] Optionally, as an embodiment, each font file includes: path information of the font library file and font variable axis parameters, wherein the font variable axis parameters include at least one of font weight value and visual size value; one font style corresponds to one font library file.

[0129] Optionally, as an embodiment, the font style of the first font is different from that of the second font; the font switching instruction carries the style identifier of the second font;

[0130] The creation module 502 may include:

[0131] The first determining submodule is used to determine the path information of the font file corresponding to the second font based on the style identifier of the second font carried in the font switching instruction;

[0132] The second creation submodule is used to create a second font file for drawing the second font based on the path information of the font library file corresponding to the second font.

[0133] Optionally, as an embodiment, the font weight value of the first font is different from that of the second font; the font switching instruction carries the weight adjustment value of the second font;

[0134] The creation module 502 may include:

[0135] The second determining submodule is used to determine the font weight value corresponding to the second font based on the weight adjustment value and the base weight value of the second font carried in the font switching instruction;

[0136] The third creation submodule is used to create a second font file for drawing the second font based on the font weight value corresponding to the second font.

[0137] Optionally, as an embodiment, the font size value of the first font is different from the font size value of the second font; the font switching instruction carries the font size value of the second font;

[0138] The creation module 502 may include:

[0139] The third determining submodule is used to determine the visual size value corresponding to the second font based on the font size value of the second font carried in the font switching instruction and the mapping relationship between the font size value and the visual size value;

[0140] The fourth creation submodule is used to create a second glyph file for drawing the second font based on the visual size value corresponding to the second font.

[0141] Optionally, as an embodiment, the system font configuration file includes multiple font family tags and multiple alias tags;

[0142] The font family tag contains multiple font tags, the font tags contain the path information of the font library file and the font variable axis tag, the font variable axis tag contains the font variable axis parameters, and the alias tag is used to identify the font variable axis parameters.

[0143] The font switching device in this application embodiment can be a stand-alone electronic device or a component within an electronic device, such as an integrated circuit or chip. The electronic device can be a terminal or other devices besides a terminal. For example, the electronic device can be a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, mobile internet device (MID), augmented reality (AR) / virtual reality (VR) device, robot, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc. It can also be a server, network attached storage (NAS), personal computer (PC), television (TV), ATM, or self-service machine, etc. This application embodiment does not specifically limit the device.

[0144] The font switching device in this application embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit it.

[0145] The font switching device provided in this application embodiment can achieve... Figure 3 or Figure 4 To avoid repetition, the various processes implemented in the method embodiment shown will not be described again here.

[0146] Optionally, such as Figure 6 As shown, this application embodiment also provides an electronic device 600, including a processor 601 and a memory 602. The memory 602 stores a program or instructions that can run on the processor 601. When the program or instructions are executed by the processor 601, they implement the various steps of the above-described font switching method embodiment and can achieve the same technical effect. To avoid repetition, they will not be described again here.

[0147] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.

[0148] Figure 7 This is a schematic diagram of the hardware structure of an electronic device that implements the various embodiments of this application.

[0149] The electronic device 700 includes, but is not limited to, components such as: radio frequency unit 701, network module 702, audio output unit 703, input unit 704, sensor 705, display unit 706, user input unit 707, interface unit 708, memory 709, and processor 710.

[0150] Those skilled in the art will understand that the electronic device 700 may also include a power supply (such as a battery) for supplying power to various components. The power supply may be logically connected to the processor 710 through a power management system, thereby enabling functions such as managing charging, discharging, and power consumption through the power management system. Figure 7 The electronic device structure shown does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown, or combine certain components, or have different component arrangements, which will not be elaborated here.

[0151] The processor 710 is configured to, in response to a font switching instruction, locate a first font family file corresponding to a first font according to the font-font family mapping relationship in the system font configuration file; the font switching instruction is configured to indicate that the system font is switched from the first font to a second font, the first font family file containing a first font file for drawing the first font; create a second font file for drawing the second font; replace the first font file in the first font family file with the second font file; and, in response to a user opening an interface, render the view text on the interface based on the second font file in the first font family file.

[0152] As can be seen, in this embodiment of the application, when the user switches the system font, the font switching on the interface can be achieved by updating the font file. Since creating the font file occupies less system memory, the amount of memory consumed by switching the system font can be reduced, ensuring the normal operation of the electronic device.

[0153] Optionally, as an embodiment, the processor 710 is further configured to, in response to a font switching instruction, locate the first font family file corresponding to the first font in the system runtime library layer according to the mapping relationship between fonts and font families in the system font configuration file; in the application framework layer, create a second font file for drawing the second font, and transfer the second font file from the application framework layer to the system runtime library layer; in the system runtime library layer, delete the first font file from the first font family file, and add the second font file to the first font family file.

[0154] Optionally, as an embodiment, each font file includes: path information of the font library file and font variable axis parameters, wherein the font variable axis parameters include at least one of font weight value and visual size value; one font style corresponds to one font library file.

[0155] Optionally, as an embodiment, the font style of the first font is different from that of the second font; the font switching instruction carries the style identifier of the second font;

[0156] The processor 710 is further configured to determine the path information of the font library file corresponding to the second font based on the style identifier of the second font carried in the font switching instruction; and to create a second font file for drawing the second font based on the path information of the font library file corresponding to the second font.

[0157] Optionally, as an embodiment, the font weight value of the first font is different from that of the second font; the font switching instruction carries the weight adjustment value of the second font;

[0158] The processor 710 is further configured to determine the font weight value corresponding to the second font based on the weight adjustment value and the reference weight value of the second font carried in the font switching instruction; and to create a second font file for drawing the second font based on the font weight value corresponding to the second font.

[0159] Optionally, as an embodiment, the font size value of the first font is different from the font size value of the second font; the font switching instruction carries the font size value of the second font;

[0160] The processor 710 is further configured to determine the visual size value corresponding to the second font based on the font size value of the second font carried in the font switching instruction and the mapping relationship between the font size value and the visual size value; and to create a second font file for drawing the second font based on the visual size value corresponding to the second font.

[0161] Optionally, as an embodiment, the system font configuration file includes multiple font family tags and multiple alias tags; the font family tags include multiple glyph tags, the glyph tags include the path information of the font library file and the font variable axis tag, the font variable axis tag includes the font variable axis parameter, and the alias tag is used to identify the font variable axis parameter.

[0162] It should be understood that, in this embodiment, the input unit 704 may include a graphics processing unit (GPU) 7041 and a microphone 7042. The GPU 7041 processes image data of still images or videos obtained by an image capture device (such as a camera) in video capture mode or image capture mode. The display unit 706 may include a display panel 7061, which may be configured in the form of a liquid crystal display, an organic light-emitting diode, or the like. The user input unit 707 includes at least one of a touch panel 7071 and other input devices 7072. The touch panel 7071 is also called a touch screen. The touch panel 7071 may include a touch detection device and a touch controller. Other input devices 7072 may include, but are not limited to, physical keyboards, function keys (such as volume control buttons, power buttons, etc.), trackballs, mice, and joysticks, which will not be described in detail here.

[0163] The memory 709 can be used to store software programs and various data. The memory 709 may primarily include a first storage area for storing programs or instructions and a second storage area for storing data. The first storage area may store the operating system, application programs or instructions required for at least one function (such as sound playback, image playback, etc.). Furthermore, the memory 709 may include volatile memory or non-volatile memory, or both. The non-volatile memory may be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct memory bus RAM (DRRAM). The memory 709 in the embodiments of this application includes, but is not limited to, these and any other suitable types of memory.

[0164] Processor 710 may include one or more processing units; optionally, processor 710 integrates an application processor and a modem processor, wherein the application processor mainly handles operations involving the operating system, user interface, and applications, and the modem processor mainly handles wireless communication signals, such as a baseband processor. It is understood that the aforementioned modem processor may also not be integrated into processor 710.

[0165] This application also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the above-described font switching method embodiments and achieve the same technical effect. To avoid repetition, they will not be described again here.

[0166] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.

[0167] This application also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above-described font switching method embodiments and achieve the same technical effect. To avoid repetition, it will not be described again here.

[0168] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.

[0169] This application also provides a computer program product, which is stored in a storage medium and executed by at least one processor to implement the various processes of the font switching method embodiment described above, and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0170] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one…" does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.

[0171] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (e.g., ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (e.g., a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.

[0172] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.< / alias> < / alias> < / family> < / alias> < / family> < / family> < / alias> < / family> < / alias> < / family> < / axis> < / alias> < / axis> < / axis> < / axis> < / font> < / font> < / font> < / family> < / alias> < / family> < / alias> < / family>

Claims

1. A font switching method, characterized in that, The method includes: In response to a font switching command, the system locates the first font family file corresponding to the first font based on the mapping relationship between fonts and font families in the system font configuration file; the font switching command is used to indicate that the system font is switched from the first font to the second font, and the first font family file contains a first glyph file for drawing the first font; Create a second glyph file for drawing the second font; Replace the first font file in the first font family file with the second font file; In response to the user's operation of opening the interface, the view text on the interface is rendered using the second font file in the first font family file.

2. The method according to claim 1, characterized in that, The process of responding to a font switching command, based on the mapping relationship between fonts and font families in the system font configuration file, finding the first font family file corresponding to the first font, creating a second font file for drawing the second font, and replacing the first font file in the first font family file with the second font file includes: In response to a font switching command, the system locates the first font family file in the system runtime library layer corresponding to the first font, based on the mapping relationship between fonts and font families in the system font configuration file. In the application framework layer, a second font file for drawing the second font is created, and the second font file is passed from the application framework layer to the system runtime library layer; In the system runtime library layer, the first font file in the first font family file is deleted, and the second font file is added to the first font family file.

3. The method according to claim 1 or 2, characterized in that, Each font file includes: path information of the font library file and font variable axis parameters, wherein the font variable axis parameters include at least one of font weight value and visual size value; one font style corresponds to one font library file.

4. The method according to claim 3, characterized in that, The font style of the first font is different from that of the second font; the font switching instruction carries the style identifier of the second font; The creation of the second glyph file for drawing the second font includes: Based on the style identifier of the second font carried in the font switching instruction, determine the path information of the font library file corresponding to the second font; Based on the path information of the font file corresponding to the second font, create a second font file for drawing the second font.

5. The method according to claim 3, characterized in that, The weight values ​​of the first font and the second font are different; the font switching instruction carries the weight adjustment value of the second font. The creation of the second glyph file for drawing the second font includes: Based on the weight adjustment value and the base weight value of the second font carried in the font switching instruction, the font weight value corresponding to the second font is determined; Create a second glyph file for drawing the second font based on the font weight value corresponding to the second font.

6. The method according to claim 3, characterized in that, The font size value of the first font is different from that of the second font; the font switching instruction carries the font size value of the second font; The creation of the second glyph file for drawing the second font includes: Based on the font size value of the second font carried in the font switching instruction, and the mapping relationship between the font size value and the visual size value, the visual size value corresponding to the second font is determined; Based on the visual size value corresponding to the second font, create a second glyph file for drawing the second font.

7. The method according to claim 3, characterized in that, The system font configuration file contains multiple font family tags and multiple alias tags; The font family tag contains multiple font tags, the font tags contain the path information of the font library file and the font variable axis tag, the font variable axis tag contains the font variable axis parameters, and the alias tag is used to identify the font variable axis parameters.

8. A font switching device, characterized in that, The device includes: The lookup module is used to respond to a font switching command and, based on the mapping relationship between fonts and font families in the system font configuration file, find the first font family file corresponding to the first font; the font switching command is used to instruct the system font to be switched from the first font to the second font, and the first font family file contains a first glyph file for drawing the first font; Create a module to create a second glyph file for drawing the second font; The replacement module is used to replace the first font file in the first font family file with the second font file; The rendering module is used to render the view text on the interface in response to the user's operation of opening the interface, based on the second font file in the first font family file.

9. An electronic device, characterized in that, The electronic device includes a processor and a memory, the memory storing programs or instructions that can run on the processor, the programs or instructions being executed by the processor to implement the steps of the font switching method as described in any one of claims 1 to 7.

10. A readable storage medium, characterized in that, The readable storage medium stores a program or instructions that, when executed by a processor, implement the steps of the font switching method as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Font switching method, mobile terminal and computer readable storage medium

    CN107153551A

  • Font switching method and mobile terminal

    CN111309238A