Repository navigation
Conversation
A token that names no single file ("Roboto") now picks up every weight
file bundled for it (Roboto-Regular, Roboto-Bold, ...) as one Compose
FontFamily, so font-bold and font-semibold select the real cut instead
of Compose faking bold from one regular file.
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.
On Android, a custom font only ever comes in one weight.
A font file holds one weight:
Nunito-Regular.ttf,Nunito-Bold.ttf, and so on. Today the Android renderer builds a font from a single file, so:font="Nunito-Regular"+font-bolddoesn't loadNunito-Bold.ttf. Android fakes the bold by thickening the regular letters, andfont-medium/font-semiboldlook the same as regular or as the fake bold.font="Nunito"(the family name) finds no file calledNunito.ttf, so the text silently falls back to the system font.iOS doesn't have this problem, so the same Blade looks different on the two platforms.
This PR: when a font name has no file of its own, the Android resolver collects every weight file of that family (
Nunito-Regular,-Medium,-SemiBold,-Bold,-ExtraBold, and alsoThin/Light/Blackwhen present) into one font.font="Nunito"plus the usualfont-*weight classes then use the real cuts, the way the font was designed. Nothing changes for a name that matches a file (font="Nunito-Bold"still loads that file), so existing apps are not affected.Why it helps everyone: apps that bundle a brand font get proper bold, semibold and medium text on Android, matching iOS, without one font alias per weight. It is also a way around Android phones whose maker replaces the system font and ignores app weights (Xiaomi's HyperOS does this with MiSans): bundle a family once, and the weights work on every phone.
To reproduce, bundle the Nunito weights in
resources/fonts/(Nunito-Regular.ttf,Nunito-Medium.ttf,Nunito-SemiBold.ttf,Nunito-Bold.ttf,Nunito-ExtraBold.ttf):Before / after (Android emulator, API 36). Before, the left column fakes every weight from one file and the right column falls back to the system font. After, the right column uses the real Nunito weights: