Learn about font fonts for Android

Source: Internet
Author: User
Tags skia


Introduction to Android FontsThe Android system supports three fonts by default: "Sans", "serif", "monospace".

Android.graphic.typeface Font class:
constants for this class are statically defined, first for the font type (typeface) name
Typefacedefault
Typeface Default_bold
Typeface monospace
Typefacesans_serif
Typeface SERIF

font style name
Intbold
int Bold_italic
int ITALIC
int NORMAL

Setting the font for TextView can specify a typeface object through the Settypeface method in TextView, because the Android font class is relatively simple and we list all member methods:
Statictypeface Create (Typeface family, int style)//static method, parameter one for the font type here is the static definition of Typeface, such as Arial, parametric two styles, such as bold, italic

Statictypeface Create (string familyname, int style)//static method, parameter one is the font name string, parameter two is style ibid, here we recommend using the method above.

Statictypeface Createfromasset (Assetmanager Mgr, String path)//static method, parameter one is the Assetmanager object, mainly used to remove the font from the APK's assets folder, Parameter two is relative to the path of the plug-in font file in the Assets folder under Android engineering.

Statictypeface createfromfile (file path)//static method, which constructs a font from the file system, where the parameter can be a font file in SDcard

Statictypeface createfromfile (String path)//static method, constructs the font from the specified path

Statictypeface defaultfromstyle (int style)//static method, returns the default font style

Intgetstyle ()//Get current font style

Finalboolean isbold ()//Determines whether the current is bold

Finalboolean isitalic ()//Determine if the current style is italic

how Android Fonts work
Android fonts are implemented by the Android 2D graphics engine Skia and load the system fonts in the Zygote preloading classes.
related files are: SkTypeface.cpp and Skfonthost_android.cpp, which is the Skia for Android platform fonts.


The main variables are:

struct Fontinitrec {

Const char* Ffilename;

Const char* const* fnames; null-terminated List

};

struct Familyrec {

familyrec* Fnext;

sktypeface* Ffaces[5];

};

uint32_t Gfallbackfonts[sk_array_count (gsystemfonts) +1];

load_system_fonts () @skFontHost_android. cpp

Load all the fonts in the system and assign a unique ID to each font, and divide the font into two types: Familyfonts and fallbackfonts,skpaint the ID of the font (TYPEFACE) that is set by the application ultimately implements the display of the character.


Replace the android default kanji font

on Android, Droidsans is the default font and contains only Western characters, which are called by the application by default .while Droidsansfallback contains East Asian characters, when the characters that need to be displayed do not exist in the Droidsans font (such as: Kanji),
that is, when there is no corresponding encoded character, the system will go to the droidsansfallback to find the corresponding encoded characters, if found,
It is displayed using the Droidsansfallback font and cannot be displayed on the screen if the character corresponding to the encoding is still not found.

The steps to replace the default Chinese font are:

1, the young Circle Font Library Youyuan.ttf renamed to Droidsansfallback.ttf, covering the Android source code in frameworks/base/data/fonts directory Droidsansfallback.ttf file

2. Recompile the Android system

3, compile the SDK. In the generated SDK, the Android default Chinese font has been replaced with a young round font. The lack of this method is to remove the original Chinese font of the Android system
Add a default font to your Android system in the Android system, the default Chinese font is only one: Droidsansfallback.ttf, if you want to set the desired Chinese font in the Android app, In addition to introducing font files through the assets directory in your application, you can also add an android default font.


The steps to add are as follows:

1, in the Frameworks/base/data/fonts directory to add font files, such as Driod-kaishu.ttf;

2, in the Skia to increase the regular script this font, the need to modify the main files are skFontHost.cpp, skTypeface.cpp, Typeface.java, etc.;

3, in the Java layer to add regular script font-related APIs, the file needs to be modified mainly Typeface.java and Textview.java;

4. Compiling the SDK

5. Import the newly generated SDK into eclipse and set up the fonts you added in eclipse with Settypeface (Typeface.kaishu) and android:typeface= ("Kaishu")

Learn about font fonts for Android

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.