fix(toolbar): center CJK text vertically in tool buttons - #2064
Conversation
|
Seems that the patch couldn't fix the issue, I can still reproduce it with LineageOS 23. |
TextView centers text by font metrics, but CJK glyphs occupy only part of the font box, so labels like 中 sit visually lower than latin text. Disable includeFontPadding and offset the label by the difference between the font box center and the actual glyph bounds, so any text centers visually regardless of font or system. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
f018b6c to
e5a2a79
Compare
|
This is the second option. Both options (includeFontPadding=false, and this visual-bounds centering) work on VIVO OriginOS 6. This second option is the more robust one — it centers by the actual glyph bounds, but I don't have other OS to test with , e.g. LineageOS 23. Hope it helps. |
|
Both options failed with LineageOS 23, please revert to the first option if the issue is fixed with your OS. The first option is more elegant than the second. I found the regression with LineageOS too in #2062, maybe there is bug in LineageOS instead of Trime. |
|
@Bambooin I've get the problem fixed and make more improvements on my local branch. This is a good patch and I may pick it to my commit, however I still want to submit my PR to fix it instead. |
|
The biggest cause of the issue is that unlike ImageView, when text size is fixed and paddings are too large, TextView will crop the text content, but ImageView will scale the drawable first. So the better way to fix the issue is to make TextView scaleable, i.e. replace normal TextView with AutoSacleTextView here, and then exclude font padding. |
Summary
Toolbar tool buttons using CJK labels (e.g.
option_styles: ["中", "En"]) render the CJK glyph visually lower than latin text, so it does not line up with the surrounding icon buttons.Root cause
The label
TextView(ToolButton.kt) centers text by font metrics, but CJK glyphs occupy only part of the font box. With the defaultincludeFontPadding = true(and even with it disabled), the visible 中 glyph sits below the box center because its visual bounds differ from the font metrics, and this differs per font/system.Fix
Disable the extra font padding, then offset the label by the difference between the font-box center and the actual glyph bounds:
This computes the offset per glyph from the active typeface, so it centers any text visually regardless of font or system.
Verification
includeFontPadding = false+Gravity.CENTER) also works on VIVO OriginOS 6.ContentType.TEXTtool buttons; icon buttons are untouched.Closes #2062