About Android Fonts

Source: Internet
Author: User

Http://blog.chinaunix.net/uid-26926660-id-3325421.html

 

I. Background

Try to make it easier.

II. Analysis

2.1.Font position in the file system:

/System/fonts/where TTF files are font files for the font files under the source code/frameworks/data/fonts/

DroidSans-Bold.ttf bold unlined font (Latin letters, etc)

Droidsans. TTF regular unlined fonts (Latin letters, etc)

Droidsansfallback. TTF regular unlined font (Chinese characters, etc)

Droidsansmono. TTF-wide unlined font (Latin letters, etc)

DroidSerif-Bold.ttf bold line font (Latin letters, etc)

DroidSerif-BoldItalic.ttf bold + italic line font (Latin letters, etc)

DroidSerif-Italic.ttf italic line font (Latin letters, etc)

Regular DroidSerif-Regular.ttf font (Latin letters, etc)

Clockopia. TTF (font used to display digital clocks, not required)

In frameworks/fonts/, there are three XML files: fallback_fonts.xml, system_fonts.xml, and vendor_fonts.xml. The first two files are finally compiled into the system.

 

There are two ways to change the font: one is to forcibly replace the default font of the system, that is, rename the font you want to replace to droidsansfallback. TTF, replace the original one in/system/fonts/. Another method is to define
For us, the first method is too violent and there is no choice. Therefore, the second method is more feasible.

The brute force replacement method will not be mentioned. Now let's talk about the vendor's font method:

2.2.vendor fonts method:

Suppose you want to add a font file in XXXXX. TTF format:

Follow the methods described in the android Use Case vendor_fonts.xml file to create a fallback_fonts.xml file in the/vendor/etc/directory, for example

<Familyset>

<Family order = "9">

<Fileset>

<File> XXXXX. TTF </File>

</Fileset>

</Family>

</Familyset>

Here, family order indicates the position to be replaced by the inserted vendor font, that is, the first 10th families (starting from 0) described in/system/etc/fallback_fonts.xml, that is, droidsansfallback. TTF. copy to/system/Fonts

3. Summary:

This time, I am not talking nonsense, but I would like to remind you that most of the fonts are copyrighted, so be careful when using others' fonts, this is also the reason why Android does not add the font selection column in settings. If you use another character library and do not pay the protection fee, and the product has bought a lot of money, haha, the attorney's letter is estimated to be on the way.

 

------------------------------------

Android font modification: For 4.0 (ICS)

Http://www.douban.com/note/222712555/

This article is intended for my log last year, "the methods on the Internet are outdated! You can use a font to display Android, English, Chinese, and Japanese. You know! . The original article is about 2. in the era of X, the usage of font files has reached 4.x( the latest version of 4.1 has not been tested yet, and it is estimated that it has not changed much). Both Chinese and English fonts have changed significantly. A new log is required.
4. The most significant change after X is the addition of the Roboto family, which has four variants: regular, bold, italic, and bolditalic. There are two more italics than the original droidsans. The original droidsans family still exists, but it has been directed to the Roboto family. It is invalid to modify the original file.
Since no separate italics and separate italics are available for Chinese fonts, we recommend that you replace them in Chinese and English separately so that the English fonts are italic and italic, at the same time, there are more independent combinations of Chinese and English.
To replace the English font, we need to prepare four fonts (many fonts have independent italics, which are easy to find) to replace the following four files:
Roboto-Regular.ttf
Roboto-Italic.ttf
Roboto-Bold.ttf
Roboto-BoldItalic.ttf
For the preparations and operations for replacement, see the log referenced in the first article.
For Chinese, 4. x is still a droidsansfallback. TTF. Some firmware names may be droidsansfallbackfull. TTF names. We need to replace the most bulky ones. I personally have high requirements on fonts, and I also like to use the independent bold for Chinese and Japanese characters. Therefore, I have explored the independent bold for further gains.
You can find the fallback_fonts.xml file in the/system/etc directory by using the rootexplorer. This is the configuration file for the new language text after 4.x. You can use NotePad to open and modify it. Users familiar with Linux will be familiar with this file structure, and define the font family and different variants. We can find that China, Japan, and South Korea are still encoded as follows:
<Family>
<Fileset>
<File> droidsansfallback. TTF </File>
</Fileset>
</Family>
That is to say, the system did not prepare bold words for us. Don't be discouraged. We found that the beginning of the file has a bold statement:
<Family>
<Fileset>
<File> DroidSansHebrew-Regular.ttf </File>
<File> DroidSansHebrew-Bold.ttf </File>
</Fileset>
</Family>
This is Hebrew, and Google has made it an independent bold. We followed the preceding statement and added a new line following <File> droidsansfallback. TTF </File>:
<File> DroidSansFallback-Bold.ttf </File>
Save. Overwrite the file with the same name in the original directory with the rootexplorer and set the permission.
Then we name the General Chinese body and the bold text as droidsansfallback. TTF and DroidSansFallback-Bold.ttf overwrite the original font and change the overwrite font and the permissions of the newly added DroidSansFallback-Bold.ttf as in my previous tutorial.
After this work is done, you can restart to check the effect. This ensures that the English text is replaced with the bold text, which is pleasing to the eye for the font controllers.
Of course, the above fallback_fonts.xml can theoretically add unlimited font families. For example, the font I just replaced is only in Chinese and Japanese (many fonts do not have Korean), and I will define a new family like droidsanskorean. TTF and DroidSansKorean-Bold.ttf (casually named) and then the new font theory can also continue fallback, the order of fallback is fallback_fonts.xml in the Upper and Lower Order Decision.
Because my mobile phone is too small, I did not try to verify the above hypothesis. Interested users can try it on their own.
The results are basically the same as those in the previous tutorial, so there will be no illustrations.

----------------------------------------------

Actual Operation:

After modifying the relevant file, you need to restart the machine or restart Android, that is, enter stop; start in the ADB shell.

1. According to the online materials, the model can be added to droidsansfallback. TTF, which is theoretically displayed in flash, air (APK developed based on air), webpages, and other places.

In fact, non-self-built words cannot be displayed. Later, the following comments are displayed in/system/etc/fallback_fonts.xml:

    <!-- Note: complex scripts (i.e. those requiring shaping in Harfbuzz) have         a cumulative limit of 64k glyphs. Thus, if they are placed after the         large fonts such as DroidSansFallback, they are likely to render         incorrectly. Please use caution when putting fonts toward the end of         the list.    -->

It means that the total number of Modulo files cannot exceed 64 KB, And the modulo files after the large modulo files (such as droidsansfallback. TTF) may be abnormal.

We have tried to add the self-created model to droidsansfallback. TTF, which leads to more files to 8 Mb. It turns out to be more than 4 MB, and a lot of text cannot be displayed.

This is the same as deleting droidsansfallback. TTF directly.

 

2. For the above reason, use a small model file instead, which only contains the self-created model. The self-created model file used in the test is about 1 m.

Add the file/vendor/etc/fallback_fonts.xml. For details about the format, see/system/etc/fallback_fonts.xml. The content is as follows:

<?xml version="1.0" encoding="utf-8"?><familyset>    <family order="14">        <fileset>            <file>diy.ttf</file>        </fileset>    </family></familyset>

Push the DIY. TTF font file to/system/fonts/. Order = "14" refers to/system/etc/fallback_fonts.xml to ensure that the order is before droidsansfallback. TTF.
However, the test results still do not work, and the self-creation model in Web pages, Flash, and air cannot be displayed. I don't know where the error is, or the system does not support it.

3. The above method does not work. We plan to directly modify/system/etc/fallback_fonts.xml and add the following before droidsansfallback. TTF:

 <family>        <fileset>            <file>diy.ttf</file>        </fileset>    </family>    <family>        <fileset>            <file>DroidSansFallback.ttf</file>        </fileset>    </family>

Similarly, you need to push DIY. TTF to/system/fonts. At this time, the self-built words in the webpage and flash can be displayed normally, but the self-built words in the air cannot be displayed.

4. Add the self-made model to the Roboto-Regular.ttf:

Add the self-built model to the/system/fonts/Roboto-Regular.ttf, restart the machine, air, flash in the self-built word to see the normal display. However, the self-built words on the Web page cannot be displayed.

 

5. Based on the experiment results, you need to use two methods at the same time:

A. Add the modulo file/system/fonts/DIY. TTF and modify/system/etc/fallback_fonts.xml accordingly;

B. Add the self-built model to/system/fonts/Roboto-Regular.ttf.

In this way, the webpage, Flash, and air are displayed normally.

 

Other knowledge:

The system model must be placed under/system/fonts/. The required model must be configured in/system/etc/system_fonts.xml and/system/etc/fallback_fonts.xml.

The system first searches for the fonts listed in system_fonts.xml, followed by fallback_fonts.xml.

If bold italics are required, you must also display the self-created words.
Roboto-Italic.ttf
Roboto-Light.ttf
Roboto-LightItalic.ttf
Roboto-Regular.ttf
Roboto-Thin.ttf
Roboto-ThinItalic.ttf

This operation is performed on the android4.2 machine. The system model list is as follows:

AndroidClock.ttfAndroidClock_Highlight.ttfAndroidClock_Solid.ttfAndroidEmoji.ttfAnjaliNewLipi-light.ttfClockopia.ttfDroidNaskh-Regular.ttfDroidNaskh-Regular-SystemUI.ttfDroidSansArmenian.ttfDroidSansDevanagari-Regular.ttfDroidSansEthiopic-Regular.ttfDroidSansFallback.ttfDroidSansGeorgian.ttfDroidSansHebrew-Bold.ttfDroidSansHebrew-Regular.ttfDroidSansMono.ttfDroidSansTamil-Bold.ttfDroidSansTamil-Regular.ttfDroidSansThai.ttfDroidSerif-Bold.ttfDroidSerif-BoldItalic.ttfDroidSerif-Italic.ttfDroidSerif-Regular.ttfLohit-Bengali.ttfLohit-Kannada.ttfLohit-Telugu.ttfMTLmr3m.ttfNanumGothic.ttfRoboto-Bold.ttfRoboto-BoldItalic.ttfRobotoCondensed-Bold.ttfRobotoCondensed-BoldItalic.ttfRobotoCondensed-Italic.ttfRobotoCondensed-Regular.ttfRoboto-Italic.ttfRoboto-Light.ttfRoboto-LightItalic.ttfRoboto-Regular.ttfRoboto-Thin.ttfRoboto-ThinItalic.ttf

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.