系统版本号:Android 4.2.2_r1

本文主要是在Android中加入思源字体的过程记录。

思源字体是Google和Adobe在2014.07.18公布的中文字体。

1.获取思源字体(Google:Noto Sans CJK; Adobe:Source Han Sans)。

2.解压后例如以下几个才是思源字体。

  • NotoSansHans-Regular.otf    常规
  • NotoSansHans-Black.otf      黑体
  • NotoSansHans-DemiLight.otf
  • NotoSansHans-Medium.otf
  • NotoSansHans-Thin.otf
  • NotoSansHans-Bold.otf        加粗
  • NotoSansHans-Light.otf

注:这里说下otf,意为opentype和ttf(truetype)是兼容的。

3.安装体验

因为Android中仅仅使用到常规和加粗体,这里也仅仅以这两个做实验(同一时候也有容量的考虑)。在高PPI(分辨率)的屏幕上也许仅仅是感觉到字形变了,在低分辨率的屏幕上变的更加清晰了。前后对照:

之前:

之后:

(上传到这里就不清晰了,真是怪,点击链接看原图更为清晰)

  1) 将NotoSansHans-Regular.otf NotoSansHans-Bold.otf放到/system/fonts/文件夹下。

  2) 将例如以下fallback_fonts.xml放到/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 the

default system. The file should then be placed in /vendor/etc/fallback_fonts.xml. Note

that in your makefile, this directory should 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 configurations 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 at

which that family of fonts should be inserted in the fallback font list, where the

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 the

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 previously). 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 languages (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 to

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 for

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 等等会造成启动不了的问题,所以仅仅加入前两个足矣。

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

同一时候也有做好的字库加xml在这里下载,还原的时将这三个文件删除就可以。

4.以源代码方式加入

假设须要在制作rom时就能够自己主动加入默认中文字体,思路和上边的类似,下面是git log信息。

commit xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Author: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

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/fonts.mk b/frameworks/base/data/fonts/fonts.mk

index 875795a..490c6e6 100755

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

+++ b/frameworks/base/data/fonts/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>

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

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

</fileset>

</family>

+

+<!-- Italic 等等会造成启动不了的问题。所以仅仅加入前两个足矣。

<family>

<fileset>

-            <file>MyOtherFont.ttf</file>

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

---->

须要强调一点。关于字体拷贝。经过測试发现须要同一时候改动Android.mk和fonts.mk才干够完毕拷贝。Google是以Apache License, version 2.0协议公布的,所以大可不必操心会有律师函的问题,在高版本号的Android中这套字体已经是内置到Android中了。DroidSansFallback.ttf并非全然指中文字体,因为之前并没有开发出专心的中文字体,眼下处理方法是把所以临时不规范的字体都放入了DroidSansFallback.ttf中,Fallback是备胎的意思。全部的胎都爆了才会使用这个。

參考:《关于Android的字体》。低版本号的Android參考《Android 怎样添加新的字库》 <完>

Android中加入思源字体/NotoSansCJK/SourceHanSans的更多相关文章

  1. 网页使用思源字体 CSS

    在知乎上再次看到这门字体的提问,想想中文字体过得多么艰辛,中文软件过得多么艰辛. 思源字体 2014年7月,Adobe与Google宣布推出一款新的开源字体思源黑体, 有七种字体粗细(ExtraLig ...

  2. PHP计算思源字体宽度, 并把文字绘制到图片上

    2019-6-19 9:18:54 星期三 思源字体是一套开源的字体, 那字体宽度是多少呢? 测试场景, 将包含汉字, 数字, 大小写字符的一段文字写到图片中去, 但不能出现超出的情况,  这就要计算 ...

  3. Android中通过typeface设置字体

    Android系统默认支持三种字体,分别为:“sans”, “serif”, “monospace",除此之外还可以使用其他字体文件(*.ttf)方法一:XML中使用android默认字体 ...

  4. Android中快速实现自定义字体!

    前言:我们都知道,Android中默认的字体是黑体,而大多数app也都是使用的这种字体,但我们发现,大多数app中,个别地方字体非常好看,例如app的标题栏,菜单栏等地方,那他们是怎么做到的呢?有两种 ...

  5. Android 中使用自定义字体的方法

    1.Android系统默认支持三种字体,分别为:“sans”, “serif”, “monospace 2.在Android中可以引入其他字体 . <?xml version="1.0 ...

  6. 转--Android中自定义字体的实现方法

    1.Android系统默认支持三种字体,分别为:“sans”, “serif”, “monospace 2.在Android中可以引入其他字体 . 复制代码 代码如下: <?xml versio ...

  7. androidStudio中如何加载字体资源?

    在android中字体的格式总是不能尽善尽美的显示出来 ,  于是要求我们使用一些有美感的字体,加载的方式(就像HTML的字体一样),我们需要通过加载字体的方式来使用android中不曾提供的字体; ...

  8. 深入理解Android中View

    文章目录   [隐藏] 一.View是什么? 二.View创建的一个概述: 三.View的标志(Flag)系统 四.MeasureSpec 五.几个重要方法简介 5.1 onFinishInflate ...

  9. Android中Canvas绘图基础详解(附源码下载) (转)

    Android中Canvas绘图基础详解(附源码下载) 原文链接  http://blog.csdn.net/iispring/article/details/49770651   AndroidCa ...

随机推荐

  1. JAVA面向对象编程深入理解图

  2. Android开发进度04

    1,今日:目标:实现登录和注册功能 2,昨天:完成登录和注册的界面以及后台数据库的操作 3,收获:会使用SQlite数据库的操作语句 4,问题:登录时出现问题(登录不上去)

  3. Java 中关于default 访问权限的讨论

    Java中关于成员变量访问权限问题一般书中会给出如下表格: 简单地描述一下表中的内容:用private 修饰的成员变量只能在类内部访问:用default修饰的成员变量可以再内部访问,也可以被同个包(同 ...

  4. OpenRail中地形模型特征的含义

    点或点高程 点(附有 X.Y.Z 数据)与任何其他点之间没有功能关系.对开阔地形的随机测量拍摄可以被当做随机点的例子.点图元,如单元.圆圈和文字串是典型的 MICROSTATION 图元,用于用图表定 ...

  5. ZOJ 3288 Domination

    D - Domination Time Limit:8000MS     Memory Limit:131072KB     64bit IO Format:%lld & %llu Descr ...

  6. Spring+mybatis+struts框架整合的配置具体解释

    学了非常久的spring+mybatis+struts.一直都是单个的用他们,或者是两两组合用过,今天总算整合到一起了,配置起来有点麻烦.可是配置完一次之后.就轻松多了,那么框架整合配置具体解释例如以 ...

  7. 前端project师养成记:开发环境搭建(Sublime Text必备插件推荐)

    为了让自己更像一个前端project师,决定从开发环境開始武装自己. 本文将介绍前段project师开发的一些利器的安装步骤,主要包含了: 1.Node.js的安装 2.Grunt的安装及经常使用插件 ...

  8. Android使用有道翻译API实如今线翻译功能

    在Android应用中,加入在线翻译的功能,这里调用的是有道翻译的API. 使用有道翻译API.首先要申请一个key,申请地址为:path=data-mode">有道翻译API申请地址 ...

  9. WebRTC代码走读(八):代码文件夹结构

    转载注明出处http://blog.csdn.net/wanghorse ├── ./base //基础平台库,包含线程.锁.socket等 ├── ./build //编译脚本.gyp ├── ./ ...

  10. POJ 1949 DP?

    题意: 有n个家务,第i个家务需要一定时间来完成,并且第i个任务必须在它 "前面的" 某些任务完成之后才能开始. 给你任务信息,问你最短需要多少时间来完成任务. 输入: 第一行n个 ...