question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android line-height clipping off center + affected by font ascent/descent values

See original GitHub issue

Description

The line spacing and alignment of <Text> components on Android appears to be incorrectly affected by the ascent/descent metrics of the font metadata. Here is a comparison of OpenSans being rendered on both iOS and Android:

screen shot 2017-03-23 at 2 57 03 pm

The stock “OpenSans” font has cut off descenders with lineheight=30, while on iOS it is centered. The cyan “OpenSans*” font is modified (using FontForge) to have reduced ascent/descent vertical metrics:

image

This causes the lines to be closer together than the specified lineheight (which differs from the correct rendering on iOS).

Reproduction Steps and Sample Code

See https://github.com/chromakode/react-native-lineheight-demo for the demo app and fonts pictured above.

Solution

I suspect that logic in CustomLineHeightSpan.java is the cause of this bug. I haven’t had a chance to dig deeper yet, but it looks like the off-center rendering is caused when fm.bottom = fm.descent = 0 in the first branch. The way that these metrics are clipped should probably be changed to bring the behavior more in line with iOS.

Additional Information

  • React Native version: 0.42.3
  • Platform: Android
  • Development Operating System: macOS
  • Dev tools: iOS 10.2; Android SDK Tools 25.3.1

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:17
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
hramoscommented, May 25, 2017

Re-opening. It would be great to see a PR that addresses this.

1reaction
scottmascommented, Nov 13, 2017

Would be great to see progress on this. It’s still an outstanding issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fixing Font Padding in Compose Text - Medium
To fix all tall fonts clipping issues that could happen from turning includeFontPadding off in Compose, we apply additional padding when ...
Read more >
How to properly set line height for Android? - Stack Overflow
I'll explain this from Android Developer perspective. Line height usually means text size + "padding" top/bottom.
Read more >
Font Development Best Practices: Line Metrics - GitHub Pages
It is important to set all eight of these values sensibly in order to minimize inconsistencies and problems in line spacing and clipping...
Read more >
Deep dive CSS: font metrics, line-height and vertical-align
Explores line-height and vertical-align properties, as well as the font metrics. Understand how text is rendered on screen, and how to control it...
Read more >
Line height behavior – Figma Help Center
Every Text layer will now calculate Line height percentage, as a percentage of the Font Size. We won't apply the updated text rendering...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found