[Breaking change] Load platform fonts fallback to avoid squares instead of glyphs - #44
Closed
MaximeRougieux wants to merge 7 commits into
Closed
[Breaking change] Load platform fonts fallback to avoid squares instead of glyphs#44MaximeRougieux wants to merge 7 commits into
MaximeRougieux wants to merge 7 commits into
Conversation
A font bundled by a dependency is exposed by the font manifest as `packages/my_theme/Roboto`, and `loadFonts()` only registered it under that name. A widget styled with `TextStyle(fontFamily: 'Roboto', package: 'my_theme')` — or a theme defaulting to that family — asks for the bare `Roboto` instead, so no font was found and the text rendered as placeholder blocks in the goldens. Register both names. `loadFonts()` now returns the families it registered, which is also what lets the tests assert on it without shared state. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The families a widget gets when it specifies no font — `Roboto` on Android, `CupertinoSystemText` on iOS, `Segoe UI` on Windows — are declared in no `pubspec.yaml`: they either ship with the Flutter SDK or belong to the host OS. `loadFonts()` could not find them in the font manifest, so a `DatePickerDialog` or a `CupertinoButton` rendered as placeholder blocks in the goldens. The list is gathered from `Typography` and `CupertinoTextThemeData` instead of being hardcoded, so it follows the SDK. The families the SDK ships are loaded from its font cache, found through `FLUTTER_ROOT` or by walking up from the test executable. The ones only the OS can provide are aliased to the typeface the SDK ships: the glyphs then differ from a real device, but the goldens stay readable. Opt out with `setLoadPlatformFallbackFonts(false)`. `FontLoadingPolicy` holds what is registered on top of the manifest, and with it the arbitration introduced here: a dependency font does not claim the bare name of a platform default the SDK ships a font for. It usually bundles a single weight of such a family while the SDK ships all of them, and on a device it would not shadow the platform font either. The SDK font files are sorted before being registered: a directory listing comes back in file system order, which differs between APFS, ext4 and NTFS, and goldens must not depend on the machine that generated them. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A missing font is invisible until someone looks at the golden and notices the blocks, which is exactly what a reviewer skims past. Before taking the snapshot, `expectGolden` now collects the families the tree asks for, compares them against the ones `loadFonts()` registered, and reports the difference. A family is only reported when none of the fallbacks of the style is covered either, since the engine would have a real font to use in that case. Warnings are on by default and emitted once per family. Turn them into failures — recommended on CI once the suite is clean — or silence them with `setMissingFontsBehavior`. `findUnregisteredFontFamilies` and `reportUnregisteredFontFamilies` take what they need and return what they found, so the state that has to survive between `flutter_test_config.dart` and a test file lives in the configuration the package already exposes rather than in globals of their own. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The matrix only covered the three example apps, so nothing under `test/` ever ran on CI. Format and analyze are left out of this job for now: the package sources still carry pre-existing analyzer infos. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Goldens that contained placeholder blocks change with this version, hence the minor bump rather than a patch. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
Author
|
Closed in favor of several PRs |
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.
This PR adds the following changes :
Both behavior are optional and can be opted-out (though they are on by default)