搜索插件、代码仓与 APP 分类

GitHub 代码仓LastMonopoly/chinese_font_library

chinese_font_library

用于渲染中文字体的辅助包,包括跨平台中文字体族回退和动态字体加载。

chinese_font_library 项目封面
星标
88
复刻
8
最近推送(UTC)
2026年8月18日
项目状态
未归档

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

chinese_font_library

chinese_font_library 意在优化中文字体的跨平台渲染,目前支持:

  • 多字重的渲染
  • 动态加载字体

Sponsor

庞征博引 — 想学的,慢慢都会

本项目由 庞征博引 赞助:把复杂主题拆成一篇篇 5–10 分钟的阅读,边读边问,按自己的节奏慢慢学懂。

Requirements

chinese_font_library Flutter Dart
1.3.0 >=3.41.0 >=3.11.0
1.2.0 >=3.22.0 >=2.19.0

Flutter 3.41 起,框架会自动把 TextStyle.fontWeight 映射到可变字体的 wght 轴, 本包也随之改用 FontWeight.value,因此 FontWeight(550) 这类非整百字重不再被向下取整。

Install

dependencies:
  chinese_font_library: ^1.3.0

Features

多字重的渲染

Flutter 使用的系统默认字体多为西文字体,因此不同平台下的中文字体通常渲染为 normal 字重或 bold 字重,且 bold 字重为计算后得到的字重,并非原生 bold 字重,严重影响观感。

解决方案为使用 .useSystemChineseFont() 修改已有的 textStyle:

Text(
  '你好世界 hello world',
  style: const TextStyle(fontWeight: FontWeight.w100).useSystemChineseFont(),
)

或者使用 .useSystemChineseFont() 修改已有的 textTheme:

return MaterialApp(
  theme: ThemeData(
    textTheme: yourCustomTextTheme.useSystemChineseFont(Brightness.light),
  ),
);

也可以使用 .useSystemChineseFont() 修改已有的 themeData:

return MaterialApp(
  theme: yourCustomThemeData.useSystemChineseFont(Brightness.light),
);

动态加载字体

如果您不满足于系统内置的中文字体,想使用自己精选的中文字体,而中文字体通常体积较大,放在安装包中并非最佳选择。

解决方案为通过网络动态加载字体,仅需下载一次:

DynamicFont.url(
  fontFamily: 'CustomFontFromWeb',
  url:
      'https://raw.githubusercontent.com/LastMonopoly/chinese_font_library/master/example/assets/SmileySans-Oblique.ttf',
).load();

也支持从 asset 与本地文件加载:

DynamicFont.asset(fontFamily: 'CustomFont', key: 'assets/MyFont.ttf').load();
DynamicFont.file(fontFamily: 'CustomFont', filepath: '/path/to/MyFont.ttf').load();

Results

Font weights demo from multiple devices

Roadmap

如有任何意见或建议,请在 Github 上联系我。(❔ 表示尚未在真机上验证)

iOS 华为 鸿蒙 小米 miui macOS Windows Web html 荣耀 Vivo Oppo Linux
✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ❔

Reference

Flutter 小技巧之玩转字体渲染和问题修复

Contributions

LiTang0908

X-HAN GitHub avatar
GitHub 作者

X-HAN ↗

语言DartC++CMakeHTMLSwiftCJavaObjective-CKotlin

分类

此仓库发布的插件

使用的依赖

依赖清单 5 项

如何选择适合项目的代码仓?

先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。

  1. 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
  2. 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
  3. 使用前在 GitHub 核对 README、许可证与 Issues。

来源与维护

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗