:[Tutorial] An in-depth interpretation of the Android font mechanism, this article is enough to handle the global replacement and thickness classification of all Android phone fonts-Font Tutorial免费ppt模版下载-道格办公

[Tutorial] An in-depth interpretation of the Android font mechanism, this article is enough to handle the global replacement and thickness classification of all Android phone fonts

It's my pleasure to provide you with a tutorial that provides an in-depth look at the mechanics of Android fonts. First of all, the Android font mechanism is based on the replacement principle. Typically, there is a default font on every Android device th

 
One article is enough, as long as you After reading it thoroughly, coupled with the fonts shared by my official account, I can draw inferences about other cases from one instance, perfectly replace the fonts on any Android phone that can be rooted, and realize multi-thickness calls.

The picture of the little Android robot above is a bit different from the usual little green man, do you think it looks like this...Zhou Dongyu's gaze^0^

Getting to know the configuration file

Android4.4 and previous font configuration files: fallback_fonts.xmlAndroid5.0-6.0 configuration files: fonts.xml and fallback_fonts.xmlAndroid> These configuration files are in system/etc Under the path, Android 5.0-6.0 is a transitional stage, and there are 2 configuration files at the same time. In the Google code notes for Android 5.0-6.0, it is written that the old file fallback_fonts.xml is used to be compatible with apps that have not been specially adapted for higher versions of Android, and the old configuration file was discarded in Android 7.0. That is to say, on Android 5.0-6.0, any fonts that cannot be defined in the new configuration file will be displayed in the old configuration file. To be on the safe side, when we add, delete, or modify the Android 5.0-6.0 configuration file , you need to change both together. After Android 7.0, there is no need to change 2. Note that some custom devices still have /vendor/etc/fallback_fonts.xml, the priority of this file is higher than the system default configuration file, which is also the rule mentioned in Google's code comments . In short, if there are some characters that cannot be changed no matter how you replace them, it may be that the customized configuration file has preferentially called the characters in another font. I don't have this kind of equipment in my hand, so I haven't studied it in depth. If you encounter it, please work around it yourself. The old configuration fallback_fonts.xml basically only has the calling list of the font family, and there is almost no room for expansion; while the new version of fonts.xml is accurate to the weight of the font, and it has more room to play. It is also an important reliance for us to change fonts.

If your system is Android 4.4 or below, just change the font you got to DroidsansFallback.ttf and replace it in your phone. There is nothing to change the configuration file.

If you have an Android system above Android 5.0, look down and maximize your phone's font display capabilities.

Interpretation of configuration files

Baidu [Notepad++], this computer software is a more professional tool for reading text, especially for viewing Android font configuration files, it will be very convenient, if you directly use ordinary The txt editor modification is prone to problems.

Let's open fallback_fonts.xml, different mobile phones may be different, the native Android 6.0 is like this:

<family>

<fileset>

<file>NotoSansSC-Regular.otf</file>

</fileset>

</family>

<family>

<fileset>

<file>NotoSansTC-Regular.otf</file>

</fileset>

</family>

<family>

<fileset>

<file>NotoSansJP-Regular.otf</file>

</fileset>

</family>

<family>

<fileset>

<file>NotoSansKR-Regular.otf</file>

</fileset>

</family>

Don’t be discouraged when you see the code. It’s very simple. In fact, four fonts are specified from top to bottom, which are Simplified Chinese, Traditional Chinese, Japanese, and Korean. If the previous file does not have this character, the system will use the latter one. Fonts to fill in. Then you will find that, apart from changing the file name of the font, it seems that nothing can be changed. Yes, you are right... That's why I said earlier, if you are Android 4.4 and below, directly replace the system The file was pulled down, because I couldn't continue playing. However, you need to know that, like miui theme fonts, substratum theme fonts, CM theme fonts, etc., where the fonts cannot be covered, you can change the font files pointed to in the configuration file, and it can be done. Because this configuration clearly tells you, on Android 5.0-6.0 mobile phones, what is the file name of the font executed in the compatibility mode of the old configuration, so that there is a direction, do you want to change the font file name in the configuration file, or To replace the system fonts, you can do it.

Let's look at fonts.xml, this is much more powerful, after all, it only appeared after Android 5.0, we changed it by changing this The font is like a godsend.

</family>

<family>

<fontweight="400"style="normal">NotoSansSC-Regular.otf</font>

</family>

<family>

<fontweight="400"style="normal">NotoSansTC-Regular.otf</font>

</family>

<family>

<fontweight="400"style="normal">NotoSansJP-Regular.otf</font>

</family>

<family>

<fontweight="400"style="normal">NotoSansKR-Regular.otf</font>

</family>

It is also the calling rules of Simplified Chinese, Traditional Chinese, Japanese, and Korean fonts, but we can see that there are 2 more parameters. One is weight and the other is style. weight is the weight of the word, that is, the thickness of the font; style is the font style, generally speaking, there are two types of regular and italic. We can completely define different weights and different styles and call different font files to achieve the effect of thick and fine details like Apple mobile phones, and even better, even italics can be specially defined. For example, you can use Yahei for bold, Song for regular, and Kai for italic. This will exhaust the typesetting effect of many books and newspapers.

Modify configuration file

As mentioned earlier, the powerful expansion ability of fonts.xml, so how should we expand it? Android actually gave us a good example, that is, the configuration and writing of the default English font:

<familyname="sans-serif">

<fontweight="100"style="normal">Roboto-Thin.ttf</font>

<fontweight="100"style="italic">Roboto-ThinItalic.ttf</font>

<fontweight="300"style="normal">Roboto-Light.ttf</font>

<fontweight="300"style="italic">Roboto-LightItalic.ttf</font>

<fontweight="400"style="normal">Roboto-Regular.ttf</font>

<fontweight="400"style="italic">Roboto-Italic.ttf</font>

<fontweight="500"style="normal">Roboto-Medium.ttf</font>

<fontweight="500"style="italic">Roboto-MediumItalic.ttf</font>

<fontweight="900"style="normal">Roboto-Black.ttf</font>

<fontweight="900"style="italic">Roboto-BlackItalic.ttf</font>

<fontweight="700"style="normal">Roboto-Bold.ttf</font>

<fontweight="700"style="italic">Roboto-BoldItalic.ttf</font>

</family>

With the previous foundation, this code is easy to interpret. There are 6 different weights of 100, 300, 400, 500, 700, and 900. It also distinguishes between normal and italic styles (normal style and italic style ). We can completely imitate this. Among them, a Chinese replacement font, if it contains the above three weights, the typesetting effect is already unsatisfactory (the idiom means barely satisfactory, no matter how it is, it means satisfaction, and many illiterate authors of novels regard it as If you are not satisfied with using it, it is simply a disgrace to the gentleman). For example, write like this:

<family>

<fontweight="300"style="normal">NotoSansSC-Light.otf</font>

<fontweight="400"style="normal">NotoSansSC-Regular.otf</font>

<fontweight="400"style="italic">Kaiti.ttf</font>

<fontweight="700"style="normal">NotoSansSC-Bold.otf</font>

</family>

Thin font NotoSansSC-Light.otf, regular font NotoSansSC-Regular.otf, italic Kaiti.ttf, bold font NotoSansSC-Bold.otf have all specified files, and then put the corresponding font file with the same name Throw it under system/fonts, restart the phone and it will be OK.

However, general Chinese does not need to define italics by itself. The system will render italics where italic Chinese is required. After all, basically does not have such an official italic Chinese font, so it is unnecessary to change one by yourself. Take the bold configuration file I wrote as an example:

<!--//++[Feature][Tranquil Rain][2017/01/13][Font]Chinesefontcustomization-->

<family lang="zh-Hans">

<fontweight="300"style="normal">NotoSansSC-Light.otf</font>

<fontweight="400"style="normal">NotoSansSC-Regular.otf</font>

<fontweight="500"style="normal">NotoSansSC-Medium.otf</font>

<fontweight="700"style="normal">NotoSansSC-Bold.otf</font>

</family>

<family lang="zh-Hant">

<fontweight="300"style="normal">NotoSansSC-Light.otf</font>

<fontweight="400"style="normal">NotoSansSC-Regular.otf</font>

<fontweight="500"style="normal">NotoSansSC-Medium.otf</font>

<fontweight="700"style="normal">NotoSansSC-Bold.otf</font>

</family>

<!--//~~[Feature][Tranquil Rain][2017/01/13][Font]Chinesefontcustomization-->

There are 2 large paragraphs in total, which are Simplified Chinese and Traditional Chinese. To save trouble, the files I call are the same. Then throw the 4 font files of Xinhei into system/fonts and restart the phone to take effect. There are Korean and Japanese configurations below the original text. We don’t need to change it, just use the original file of the system. So, if you change the font strictly according to the configuration file, is there any in the font file? Korean and Japanese are not necessary.

Android 7.0 configuration file

Take another look at the configuration of the fonts.xml Chinese character area of ​​Android 7.0, which is more advanced.

<family>

<fontweight="400"style="normal"index="2">NotoSansCJK-Regular.ttc</font>

</family>

<family>

<fontweight="400"style="normal"index="3">NotoSansCJK-Regular.ttc</font>

</family>

<family>

<fontweight="400"style="normal"index="0">NotoSansCJK-Regular.ttc</font>

</family>

<family>

<fontweight="400"style="normal"index="1">NotoSansCJK-Regular.ttc</font>

</family>

You will find that there is such a thing as index, which is actually related to the use of ttc fonts in Android 7.0. A ttc font is composed of multiple ttf files, and the index of the configuration file tells the system which file in ttc to call in different languages. So you will find NotoSansCJK-Regular.ttc in my fonts. In fact, it doesn’t matter whether you change it or not, but some apps are more stubborn, such as reading more. The default reading font is to use this font file. It is said that he should read the correct font in the Chinese environment, but the strange thing is that if you change the font configuration of the Chinese part, reading more will call the Chinese characters in Japanese... and the Japanese Chinese characters in NotoSansCJK-Regular.ttc in the Japanese environment There are problems, such as "Fu" and "Guan" are only half the width of a Chinese character. So in the NotoSansCJK-Regular.ttc I retyped, the index corresponding to the Japanese environment and the Chinese environment are actually the same, to avoid problems with some stubborn apps. On Android 7.0, I believe that the Chinese part of the black font is fully configured. It is very simple. As long as you understand it, you can easily copy it on your mobile phone.

<!--//++[Feature][Tranquil Rain][2017/01/13][Font]Chinesefontcustomization-->

<family lang="zh-Hans">

<fontweight="300"style="normal">NotoSansSC-Light.otf</font>

<fontweight="400"style="normal">NotoSansSC-Regular.otf</font>

<fontweight="500"style="normal">NotoSansSC-Medium.otf</font>

<fontweight="700"style="normal">NotoSansSC-Bold.otf</font>

</family>

<family lang="zh-Hant">

<fontweight="300"style="normal">NotoSansSC-Light.otf</font>

<fontweight="400"style="normal">NotoSansSC-Regular.otf</font>

<fontweight="500"style="normal">NotoSansSC-Medium.otf</font>

<fontweight="700"style="normal">NotoSansSC-Bold.otf</font>

</family>

<!--//~~[Feature][Tranquil Rain][2017/01/13][Font]Chinesefontcustomization-->

<family>

<fontweight="400"style="normal"index="2">NotoSansCJK-Regular.ttc</font>

</family>

<family>

<fontweight="400"style="normal"index="3">NotoSansCJK-Regular.ttc</font>

</family>

<family>

<fontweight="400"style="normal"index="0">NotoSansCJK-Regular.ttc</font>

</family>

<family>

<fontweight="400"style="normal"index="1">NotoSansCJK-Regular.ttc</font>

</family>

The self-defined Chinese character calling rules are inserted into the configuration, and the system's own calling rules are still reserved later. In this case, the system will recognize it from top to bottom, and replace the font properly, and the thickness and fineness are clearly defined.

By the way, I unpacked and watched HTC>

Similarly, Xiaomi's official Xiao Milan Pavilion and Hammer's official Holly Black are all fonts changed in this way.

This concludes the tutorial.

As long as you understand it, it is not a problem to completely replace the system fonts globally;

As long as you learn thoroughly, it is too easy to handle the thickness and fineness of fonts on Android phones;

As long as you can infer other things from one instance, such as Xiaomi, Meizu, Samsung and all kinds of miscellaneous mobile phones, you can adapt it to your mobile phone after a minute of modification with the font I shared.

All you have to do is to take out the font configuration file of the original machine and copy it according to my configuration.

Why can't I just replace it with mine?

Have you ever seen copying homework and copying other people's names into the homework book... Different mobile phones are different.

I did it with native Android.

There are so many Android phones in the world, it is impossible for me to buy them all and adapt them for you (You can buy them as a gift for me, this can be considered), you must learn to do it yourself, After I learned it, I changed things in a minute.

If you still don't want to learn, then find a way to make the font apk package yourself.

One more thing to add, when using tools such as re manager to replace system font files, it may cause the system interface to crash and restart automatically (the system detects that the file in use has been modified, and it will be confused). When opening some apps from time to time, it will crash, and the phone needs to be restarted manually, and it will be perfect in the future.


Finally, I would like to share a little tip.The built-in browsers of WeChat and QQ have the following problems:< /strong>

1. Font rendering does not strictly follow fonts.xml to implement multi-word weight mounting. After replacing multi-word weight, it will automatically become disgusting pseudo-bold2 , Web page loading efficiency, some takeaway red envelope collection pages go through WeChat login verification, often freeze the first time, and only access normally after the second time These are the ghosts of the QQ browser kernel. If you want to solve the above problems, you only need to switch the browser kernel to Android's default chrome kernel for Android 5.0+.

Reply to "browser kernel" on the official account to get the solution.

This account communicates and shares Apple and Android beautification, if you think it is helpful to you~

Please donate the rain of tranquility

Long press to identify the QR code and use WeChat payment

Articles are uploaded by users and are for non-commercial browsing only. Posted by: Lomu, please indicate the source: https://www.daogebangong.com/en/articles/detail/Tutorial%20An%20indepth%20interpretation%20of%20the%20Android%20font%20mechanism%20this%20article%20is%20enough%20to%20handle%20the%20global%20replacement%20and%20thickness%20classification%20of%20all%20Android%20phone%20fonts.html

Like (810)
Reward 支付宝扫一扫 支付宝扫一扫
single-end

Related Suggestion