Add the source font/NotoSansCJK/SourceHanSans to Android and the source font to android

Source: Internet
Author: User

Add the source font/NotoSansCJK/SourceHanSans to Android and the source font to android

System Version: Android 4.2.2 _ r1

This document describes how to add the source font in Android. The source font is a Chinese font released by Google and Adobe on January 18.

1. Get the Source font (Google: Noto Sans CJK; Adobe: Source Han Sans ).

2. After decompression, the following are the source fonts.

  • NotoSansHans-Regular.otf routine
  • NotoSansHans-Black.otf black body
  • NotoSansHans-DemiLight.otf
  • NotoSansHans-Medium.otf
  • NotoSansHans-Thin.otf
  • Bold NotoSansHans-Bold.otf
  • NotoSansHans-Light.otf

Note: otf indicates that opentype and ttf (truetype) are compatible.

3. installation experience

Because Android only uses regular and bold words, this experiment is only used here (and also has capacity considerations). On the screen of high PPI (resolution), you may just feel the font has changed, on a low-resolution screen, it becomes clearer. comparison:

Before:


After:


(It is really strange that it is not clear to upload it here. It is clearer to click the link to see the source image)

1) Put the NotoSansHans-Regular.otf NotoSansHans-Bold.otf under the/system/fonts/directory.

2) Put the following fallback_fonts.xml under/vendor/etc.

<? Xml version = "1.0" encoding = "UTF-8"?>

<! --

Vendor-provided fallback fonts

 

This file can be edited to add references to fonts that are not installed or referenced in

Default system. The file shoshould then be placed in/vendor/etc/fallback_fonts.xml. Note

That in your makefile, this directory shocould be referenced as $ (TARGET_COPY_OUT_VENDOR)/etc /:

 

PRODUCT_COPY_FILES + = \

Frameworks/base/data/fonts/vendor_fonts.xml: $ (TARGET_COPY_OUT_VENDOR)/etc/fallback_fonts.xml

 

For example, vendors might want to build deployments for locales that are

Better served by fonts which either handle glyphs not supported in the default fonts or which

Handle these glyphs differently than the default fallback fonts.

Each entry in this list is a "family", which consists of a list of "files"

(The filenames for that family). The files objects are

Provided in the order of the styles supported for that family: regular, bold, italic, and

Bold-italic. Only providing one font means that all styles will be rendered with that font.

Providing two means that these two fonts will render regular and bold fonts (italics will

Be mapped to these two fonts ).

 

There is also an optional "order" attribute on the Family tag. This specifies the index

Which that family of fonts shocould be inserted in the fallback font list, where

Default fallback fonts on the system (in/system/etc/fallback_fonts.xml) start at index 0.

If no 'order' attribute is supplied, that family will be inserted either at the end of

Current fallback list (if no order was supplied for any previous family in this file) or

After the previous family (if there was an order specified previusly). Typically, vendors

May want to supply an order for the first family that puts this set of fonts at the appropriate

Place in the overall fallback fonts. The order of this list determines which fallback font

Will be used to support any glyphs that are not handled by the default system fonts.

 

Han ages (Chinese, Japanese, and Korean) share a common range of unicode characters;

Their ordering in the fallback or vendor files gives priority to the first in the list.

Language-specific ordering can be configured by adding a BCP 47-style "lang" attribute

A "file" element; fonts matching the language of text being drawn will be prioritised over

All others.

 

The sample configuration below is an example of how one might provide two families of fonts

That get inserted at the first and second (0 and 1) position in the overall fallback fonts.

 

See/system/etc/system_fonts.xml and/system/etc/fallback_fonts.xml for more information

And to understand the order in which the default system fonts are loaded and structured

Lookup.

-->

 

<! -- Sample fallback font additions to the default fallback list. These fonts will be added

To the top two positions of the fallback list, since the first has an order of 0. -->

<Familyset>

<Family order = "0">

<Fileset>

<File> NotoSansHans-Regular.otf </file>

<File> NotoSansHans-Bold.otf </file>

</Fileset>

</Family>

 

<! -- Italic and so on will cause startup failure, so only the first two are enough.

<Family>

<Fileset>

<File> NotoSansHans-Regular.otf </file>

<File> NotoSansHans-Italic.otf </file>

<File> NotoSansHans-Bolditalic.otf </file>

<File> NotoSansHans-Black.otf </file>

<File> NotoSansHans-DemiLight.otf </file>

<File> NotoSansHans-Light.otf </file>

<File> NotoSansHans-Medium.otf </file>

<File> NotoSansHans-Thin.otf </file>

</Fileset>

</Family>

-->

</Familyset>

At the same time, you can download the font library and xml, and delete the three files when restoring them.

4. Add as source code

If you need to automatically add the default Chinese font when creating the rom, the idea is similar to the above. The following is the git log information.

Commit xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Author: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Date: Mon Aug 18 15:44:24 2014 + 0800

 

Add Noto Sans CJK fonts for Chinese

 

Diff -- git a/device/rockchip/rk30sdk/device. mk B/device/rockchip/rk30sdk/device. mk

Index 8befd40 .. b4e2822 100755

--- A/device/rockchip/rk30sdk/device. mk

++ B/device/rockchip/rk30sdk/device. mk

@-119,6 + 119,10 @ PRODUCT_COPY_FILES + = \

+ # Fonts

+ PRODUCT_COPY_FILES + = \

+ Frameworks/base/data/fonts/vendor_fonts.xml: $ (TARGET_COPY_OUT_VENDOR)/etc/fallback_fonts.xml

Diff -- git a/frameworks/base/data/fonts/Android. mk B/frameworks/base/data/fonts/Android. mk

Index e02e95a .. 0b4bc6c 100755

--- A/frameworks/base/data/fonts/Android. mk

++ B/frameworks/base/data/fonts/Android. mk

@-157,6 + 157,8 @ font_src_files + = \

DroidSansHebrew-Regular.ttf \

DroidSansHebrew-Bold.ttf \

DroidSansThai. ttf \

+ NotoSansHans-Regular.otf \

+ NotoSansHans-Bold.otf \

DroidSansArmenian. ttf \

DroidSansGeorgian. ttf \

AndroidEmoji. ttf

Diff -- git a/frameworks/base/data/fonts/NotoSansHans-Bold.otf B/frameworks/base/data/fonts/NotoSansHans-Bold.otf

New file mode 100644

Index 0000000 .. 006372e

Binary files/dev/null and B/frameworks/base/data/fonts/NotoSansHans-Bold.otf differ

Diff -- git a/frameworks/base/data/fonts/NotoSansHans-Regular.otf B/frameworks/base/data/fonts/NotoSansHans-Regular.otf

New file mode 100644

Index 0000000 .. 923f89c

Binary files/dev/null and B/frameworks/base/data/fonts/NotoSansHans-Regular.otf differ

Diff -- git a/frameworks/base/data/fonts. mk B/frameworks/base/data/fonts. mk

Index 875795a .. 490c6e6 100755

--- A/frameworks/base/data/fonts. mk

++ B/frameworks/base/data/fonts. mk

@-38,6 + 38,8 @ PRODUCT_PACKAGES: = \

DroidSansHebrew-Regular.ttf \

DroidSansHebrew-Bold.ttf \

DroidSansThai. ttf \

+ NotoSansHans-Regular.otf \

+ NotoSansHans-Bold.otf \

DroidSerif-Regular.ttf \

DroidSerif-Bold.ttf \

DroidSerif-Italic.ttf \

Diff -- git a/frameworks/base/data/fonts/vendor_fonts.xml B/frameworks/base/data/fonts/vendor_fonts.xml

Index 8690ee1 .. fba0c88 100755

--- A/frameworks/base/data/fonts/vendor_fonts.xml

++ B/frameworks/base/data/fonts/vendor_fonts.xml

@-45, 17 + 45, 26 @@

 

<! -- Sample fallback font additions to the default fallback list. These fonts will be added

To the top two positions of the fallback list, since the first has an order of 0. -->

-<! --

<Familyset>

<Family order = "0">

<Fileset>

-<File> MyFont. ttf </file>

+ NotoSansHans-Regular.otf

+ NotoSansHans-Bold.otf

</Fileset>

</Family>

+

+ <! -- Italic and so on will cause startup failure, so only the first two are enough.

<Family>

<Fileset>

-<File> mytherfont. ttf </file>

+ NotoSansHans-Regular.otf

+ NotoSansHans-Italic.otf

+ NotoSansHans-Bolditalic.otf

+ NotoSansHans-Black.otf

+ NotoSansHans-DemiLight.otf

+ NotoSansHans-Light.otf

+ NotoSansHans-Medium.otf

+ NotoSansHans-Thin.otf

</Fileset>

</Family>

+ -->

</Familyset>

---->

It should be emphasized that the copy of the font must be modified simultaneously by modifying Android. mk and fonts. mk. Google is released based on Apache License and version 2.0, so you don't have to worry about the issue of attorney letter. In the high version of Android, this font is already built into Android. DroidSansFallback. ttf does not fully refer to Chinese fonts. Since the concentrated Chinese fonts have not been developed before, the current solution is to put the nonstandard fonts into DroidSansFallback. in ttf, Fallback indicates a spare tire, which is used only when all tires are aborted.

Refer to: about Android font. For earlier Android versions, refer to "how to add a new font library for Android". <End>




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.