Are otf fonts the same as ttf:"Tutorial" deeply interprets the Android font mechanism, and handles font replacement and thickness classification for Android phones-Font Tutorial免费ppt模版下载-道格办公

"Tutorial" deeply interprets the Android font mechanism, and handles font replacement and thickness classification for Android phones

Implement font replacement and adjust thickness on mobile phones. Here is a brief tutorial: 1. Get root permission: Before doing font replacement and weight adjustment, you need to get root permission on your phone. Root permissions allow you to modify an

For more fonts, mobile phone evaluations, etc., please pay attention to "Tranquil Rain" gongzhonghao.

One article is enough, as long as you read it thoroughly, plus the fonts I shared, you can draw inferences from one instance, completely replace the fonts on any Android phone that can be rooted, and realize multi-thickness calling.

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

1. Getting to know the configuration file

Android 4.4 and before the font configuration file: fallback_fonts.xml

Configuration files for Android 5.0-6.0: fonts.xml and fallback_fonts.xml

Configuration file after Android 7.0: fonts.xml

These configuration files are all under the system/etc path. Android 5.0-6.0 is a transitional stage, and there are 2 configuration files at the same time.

Google's code notes for Android 5.0-6.0 say 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.

In other words, 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, we need to modify both. 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 a calling list of font families, and there is almost no room for expansion;

The new version of fonts.xml is accurate to the weight of the font, which can be used more, and 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.

2. Interpret 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 an ordinary txt editor to modify, yes prone to problems.

Let's open fallback_fonts.xml first, 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 again, this one is much more powerful, after all, it only appeared after Android 5.0, we change the font by changing this, it's like a miracle.

</family>

<family>

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

</family>

<family>

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

</family>

<family>

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

</family>

<family>

<font weight="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, Arial for regular, and Kai for italic. This will exhaust the typesetting effect of many books and newspapers.

3. Modify the 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:

<family name="sans-serif">

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

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

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

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

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

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

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

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

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

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

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

<font weight="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, 400 weight corresponds to the normal weight, 700 weight corresponds to the most commonly used bold font, and 300 weight corresponds to the most commonly used thin font.

A Chinese replacement font, if it includes the above 3 weights, the typesetting effect is already unsatisfactory (this idiom means barely satisfactory, no matter how it is, it means satisfaction, and many illiterate authors of novels use it as dissatisfaction. It's just insulting to the gentleman).

For example, write like this:

<family>

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

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

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

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

</family>

Thin NotoSansSC-Light.otf, Regular NotoSansSC-Regular.otf, Italic Kaiti.ttf, Bold NotoSansSC-Bold.otf are all specified files, and then drop the font file with the same name corresponding to the file name under system/fonts, Restart the phone and it's OK.

However, general Chinese does not need to define italics by itself. The system will render italics where italic Chinese is required. After all, there is basically no such 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] Chinese font customization -->

<family lang="zh-Hans">

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

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

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

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

</family>

<family lang="zh-Hant">

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

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

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

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

</family>

<!-- //~~[Feature][Tranquil Rain][2017/01/13][Font] Chinese font customization -->

There are a total of 2 large sections, namely 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 also Korean and Japanese configurations under the original text. We don’t need to change them, just use the original files of the system. So, if you change fonts strictly according to the configuration files, whether there are Korean or Japanese in the font files does not matter. Not very necessary.

4. Configuration file for Android 7.0

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

<family>

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

</family>

<family>

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

</family>

<family>

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

</family>

<family>

<font weight="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, Duokan Reading will call the Chinese characters in Japanese...

And NotoSansCJK-Regular.ttc has problems with the Japanese Chinese characters in the Japanese environment. For example, "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] Chinese font customization -->

<family lang="zh-Hans">

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

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

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

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

</family>

<family lang="zh-Hant">

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

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

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

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

</family>

<!-- //~~[Feature][Tranquil Rain][2017/01/13][Font] Chinese font customization -->

<family>

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

</family>

<family>

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

</family>

<family>

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

</family>

<family>

<font weight="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 read the Android 7.0 ROM of the HTC 10 international version. His official letter has two characters in black and thick, and it is exactly the same as my modification.

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 gifts for me, this can be considered), you must learn to do it yourself, and you can change things in a minute after learning .

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

Add one more point, 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), at this time, open some The app 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:

1. Font rendering does not strictly follow fonts.xml to implement multi-word weight mounting. After replacing multi-word weights, it will automatically become disgusting pseudo-bold

2. Webpage loading efficiency, some takeaway red envelope collection pages go through WeChat login verification, often the first time it will freeze, and the second time it can be accessed normally

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+.

Browser Kernel Problem Solutions

The built-in web browsers (webview) of WeChat and QQ, as well as various browsers at the core of the QQ browser, have the following problems:

1. Font rendering does not strictly follow fonts.xml to implement multi-weight loading, and after replacing multiple weights, it will automatically become disgusting pseudo-bold

2. Webpage loading efficiency, some takeaway red envelope collection pages go through WeChat login verification, often the first time will be stuck, and the second time will be able to access normally

If you want to solve the above problems, you can switch to the Chrome kernel.

Visit http://debugtbs.qq.com/

After opening, choose to clear the TBS kernel, and then force the system kernel to be enabled. After restarting, choose to view the kernel version. If it shows 0, it has been forced to switch to the system webview kernel.

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%20deeply%20interprets%20the%20Android%20font%20mechanism%20and%20handles%20font%20replacement%20and%20thickness%20classification%20for%20Android%20phones.html

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

Related Suggestion