Fix Android text size on displays with a different density - #57935
Open
matinzd wants to merge 4 commits into
Open
Fix Android text size on displays with a different density#57935matinzd wants to merge 4 commits into
matinzd wants to merge 4 commits into
Conversation
[ANDROID] [FIXED] - Measure and draw text at the surface's display density, not the primary display's
matinzd
force-pushed
the
feat-per-surface-text-scale-android
branch
from
August 13, 2026 15:01
8d247ca to
c743f86
Compare
matinzd
marked this pull request as ready for review
August 13, 2026 15:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes Android text rendering on secondary displays with a different density from the primary display.
Previously, text could render too large and overflow its layout because Fabric used the current display's density, while the Java text pipeline used the primary display's density.
The change makes the text pipeline use the density of the display where the surface is actually rendered.
For example, on a device with a 2.625x primary display and a 1.0x external display, a 16sp label could be laid out as 42px but mounted into a 16px box. With this change, both measurement and rendering use the 1.0x display density, so the text fits correctly.
This applies to scenarios such as:
On single-display devices, behavior remains unchanged.
The fix is behind
enablePerSurfaceTextScaleAndroidand is off by default.Related: #57183, #56129, #56894, #55659, and the discussion on #56895.
Changelog
[Android] [Fixed] - Text now uses the density of the display it is rendered on, preventing oversized and clipped text on displays with different densities.
How to test
Test Plan
Verified with unit tests and on a Pixel 9 AVD using a 2.625x primary display and a 1.0x virtual secondary display.
Before: text was rendered too large and clipped.
Screen.Recording.2026-08-13.at.09.25.29.mov
After: text renders at the correct size and fits within its layout.
Screen.Recording.2026-08-13.at.11.39.00.mov
Primary display: unchanged.