Android Fabric text measurement uses Typeface.DEFAULT instead of the system default used for rendering, clipping last glyphs with bold system fonts
还没有人认领这个 Issue。
- 主要语言
- C++
- 星标
- 127k
- 派生
- 25.3k
- 平均合并
- 1 天 23 小时
- 30 天内合并 PR
- 4
描述
Summary
When Android system default font is bolded/replaced (e.g. Xiaomi MiSans Pro Bold / 'full bold' setting), auto-width components are measured with Typeface.DEFAULT while rendering uses the TextView default typeface which inherits the system font configuration. The measured width is therefore too small, and the last glyph can be clipped or missing.
Example: English renders as Englis on Xiaomi with the system-wide bold font enabled.
Environment
- React Native 0.78.3 (Fabric / Bridgeless)
- Android 16 (API 36), Xiaomi HyperOS with system font set to
MiSans Pro Bold - Reproduced on multiple Xiaomi devices
Root cause
TextLayoutManager.updateTextPaint() resets the paint typeface to null (Typeface.DEFAULT) when no explicit font family/weight/style is set, while ReactTextView renders with the TextView default typeface which carries the system bold/replacement config. Different metrics and advances mean measurement is narrower than what is actually drawn.
On device, same 48px text:
| ascent | descent | line height | |
|---|---|---|---|
measurement paint (Typeface.DEFAULT) |
-45 | 3 | 1.0em |
| rendering TextView (system bold) | -50 | 14 | 1.33em |
English (7 glyphs): measured width 53.33dp (only 6 glyphs laid out), drawn width 56.67dp (7 glyphs). The final h is dropped.
Suggested fix
Make the measurement typeface the same source as rendering when no explicit font family/weight/style is set. A local patch that uses the system/default TextView typeface for measurement fixes the issue and was verified on 5 Android devices.
Additional context
This analysis and the local fix were produced with the assistance of an AI coding agent (Codex). Please review independently.
Related
- #49886 (text metrics mismatch / descender clipping)
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
Start with TextLayoutManager.updateTextPaint() and compare its typeface handling with the ReactTextView rendering path. Reproduce the issue using an Android device with a bold or replacement system font and an auto-width Text component. Done means measurement uses the same default typeface as rendering and the final glyph is no longer clipped.
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- android, react-native
- 领域
- mobile-dev
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 55/100