Android8.1系统字体

需求:替换系统字体

分析:

过程:frameworks/base/data/fonts/fonts.xml

            external/roboto-fonts/

            noto-fonts/other/



关于字体上层主要在 

frameworks/base/graphics/java/android/graphics/Typeface.java

static {

final ArrayMap systemFontMap =new ArrayMap<>();

final ArrayMap systemFallbackMap =new ArrayMap<>();

buildSystemFallback("/system/etc/fonts.xml","/system/fonts/", systemFontMap,

systemFallbackMap);

sSystemFontMap = Collections.unmodifiableMap(systemFontMap);

sSystemFallbackMap = Collections.unmodifiableMap(systemFallbackMap);

setDefault(sSystemFontMap.get(DEFAULT_FAMILY));

// Set up defaults and typefaces exposed in public API

    DEFAULT        =create((String)null,0);

DEFAULT_BOLD    =create((String)null, Typeface.BOLD);

SANS_SERIF      =create("sans-serif",0);

SERIF          =create("serif",0);

MONOSPACE      =create("monospace",0);

sDefaults =new Typeface[] {

DEFAULT,

DEFAULT_BOLD,

create((String)null, Typeface.ITALIC),

create((String)null, Typeface.BOLD_ITALIC),

};

}

static代码块 是系统typeface的初始化

DEFAULT 、DEFAULT_BOLD 、SANS_SERIF、SERIF、MONOSPACE

因为DEFAULT_FAMILY ="sans-serif"  所以DEFAULT = SANS_SERIF    DEFAULT_BOLD = SANS_SERIF + BOLD

所以先介绍下三种familyName的含义

sans-serif:区别于“serif”,没有"笔锋",笔画粗细也基本差不多

serif:带“笔锋”,而且根据横竖斜的宽度也不一样

monospace:打印用字体,属于“sans-serif”,每个字母等间距


其次介绍下"font-weight",

weight指的是粗细”

那么默认的weight是多少?


===>>>Typeface.java 

create(null,0);

nativeCreateFromTypeface(ni, style)

===>>>Typeface.cpp

frameworks/base/core/jni/android/graphics/Typeface.cpp

Typeface* face = Typeface::createRelative(family, (SkTypeface::Style)style);

===>>>Typeface.cpp

frameworks/base/libs/hwui/hwui/Typeface.cpp

Typeface* Typeface::createRelative(Typeface* src, SkTypeface::Style style) {

    Typeface* resolvedFace = Typeface::resolveDefault(src);

Typeface* hwTypeface = new Typeface();

    hwTypeface->fFontCollection = collection;

    hwTypeface->fSkiaStyle = SkTypeface::kNormal;

    hwTypeface->fBaseWeight = SkFontStyle::kNormal_Weight;

    hwTypeface->fStyle = minikin::FontStyle(4 /* weight */, false /* italic */);

    Typeface::setDefault(hwTypeface);

===>>>SkFontStyle.h

external/skia/include/core/SkFontStyle.h

enum Weight {

        kInvisible_Weight  =    0,

        kThin_Weight        =  100,

        kExtraLight_Weight  =  200,

        kLight_Weight      =  300,

        kNormal_Weight      =  400,

        kMedium_Weight      =  500,

        kSemiBold_Weight    =  600,

        kBold_Weight        =  700,

        kExtraBold_Weight  =  800,

        kBlack_Weight      =  900,

        kExtraBlack_Weight  = 1000,

    };


所以默认的weight是400

再根据frameworks/base/data/fonts/fonts.mk    找到Roboto-Regular.ttf  才是默认的自体文件

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



其中要注意ttc文件

```

1234

```

<family lang="zh-Hans">

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

    </family>

    <!-- TODO: Add Bopo -->

    <family lang="zh-Hant">

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

    </family>

    <family lang="ja">

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

    </family>

    <family lang="ko">

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

    </family>

```

最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom阅读 3,492评论 0赞 3
  • 即将自己要做的某类事的步骤清单化,既可省时,也可以省力,因此,要建立自己的做事清单,清单必须要可执行。 比如查理芒...
    老菜头_dca8阅读 384评论 0赞 0
  • 上次我们去寒假班学架子鼓,因为是寒假工,我也是我也是刚过去的,全都是一些不认识的同学。所以我就有点不好意思...
    学习就好阅读 781评论 0赞 0
  • 1.健康. 记得上大学的时候,有位老师总说一句话:“你不能管理自己,那就被人管理。”现在想想对疾病也是一样的态度,...
    晓晨_888阅读 123评论 0赞 0
  • 老大还是老大啊,这个世界每天都是在变的,所以不要用我们自己看到的来概括全部,我的未来在哪里,寻梦,做自己。
    王汪忘往阅读 80评论 0赞 0

友情链接更多精彩内容