Skip to content

Conversation

@jiahaog
Copy link
Member

@jiahaog jiahaog commented Aug 22, 2025

Before this change, load loads fonts in a non-deterministic order. After this change, it loads the fonts sequentially.

See cl/797583429 for the full context. We found that the order of how fonts load for a specific font family actually affects runtime behavior, and the current non-deterministic order of loading fonts leads to flakiness.

Consider the following:

  • foo.ttf has glyphs 'A' and 'B'
  • foo-italic.ttf only has glyph 'B'

If addFont(foo-italic.ttf) is called before addFont(foo.ttf), the font loader will load foo-italic.ttf first and use that as the base font. When looking for the 'A' glyph, it may will look for the glyph only in foo-italic.ttf, which doesn't have it, and will show an incorrect empty placeholder glyph.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Aug 22, 2025
@jiahaog jiahaog force-pushed the font-load-ordering branch from 87f37d9 to d106b2a Compare August 22, 2025 04:13
@jiahaog jiahaog marked this pull request as ready for review August 22, 2025 05:16
Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for this. Sorry it appeared to have fallen through the review queue. 🙏

@Piinks Piinks added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 22, 2025
@auto-submit
Copy link
Contributor

auto-submit bot commented Sep 22, 2025

autosubmit label was removed for flutter/flutter/174253, because - The status or check suite Linux firebase_release_smoke_test has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 22, 2025
@Piinks Piinks added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 22, 2025
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 22, 2025
@auto-submit
Copy link
Contributor

auto-submit bot commented Sep 22, 2025

autosubmit label was removed for flutter/flutter/174253, because - The status or check suite Linux web_long_running_tests_5_5 has failed. Please fix the issues identified (or deflake) before re-applying this label.

@Piinks Piinks added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 22, 2025
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 22, 2025
@auto-submit
Copy link
Contributor

auto-submit bot commented Sep 22, 2025

autosubmit label was removed for flutter/flutter/174253, because - The status or check suite Linux_android_emu_vulkan_stable android_engine_vulkan_tests has failed. Please fix the issues identified (or deflake) before re-applying this label.

@Piinks Piinks added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 23, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Sep 23, 2025
Merged via the queue into flutter:master with commit 4ab132f Sep 23, 2025
83 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 23, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 23, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 23, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 23, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 23, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 23, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 23, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 23, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 23, 2025
@jiahaog jiahaog deleted the font-load-ordering branch September 23, 2025 22:25
@jiahaog
Copy link
Member Author

jiahaog commented Sep 23, 2025

Thanks!

auto-submit bot pushed a commit to flutter/packages that referenced this pull request Sep 24, 2025
…10067)

Manual roll requested by [email protected]

flutter/flutter@9ff2767...4a04204

2025-09-23 [email protected] Simplify asserts in `FlutterMutatorTest` (flutter/flutter#175730)
2025-09-23 [email protected] Improve code quality in `AccessibilityBridgeTest.java` (flutter/flutter#175718)
2025-09-23 [email protected] Fix linter issues in `VsyncWaiterTest` Capital L for long values (flutter/flutter#175780)
2025-09-23 [email protected] Fix wrong order of asserts arguments (flutter/flutter#175726)
2025-09-23 [email protected] Simplify test asserts and use lambdas  (flutter/flutter#175727)
2025-09-23 [email protected] Remove unused imports, fix assertion order, add non null annotations to `ImageReaderPlatformViewRenderTargetTest.java` (flutter/flutter#175723)
2025-09-23 [email protected] Remove unnecessary `String.valueOf` in `KeyboardManager.java` (flutter/flutter#175502)
2025-09-23 [email protected] Fix outdated link of `intl` package to point to the correct new location  (flutter/flutter#174498)
2025-09-23 [email protected] Roll Packages from 45c9a84 to 3413b65 (4 revisions) (flutter/flutter#175854)
2025-09-23 [email protected] Fix typo in tests `README` (flutter/flutter#175788)
2025-09-23 [email protected] Update maximum known Gradle version to 9.1.0 (flutter/flutter#175543)
2025-09-23 [email protected] Roll Dart SDK from 9e943fe076c8 to 14b4ced3022a (5 revisions) (flutter/flutter#175843)
2025-09-23 [email protected] Document how to hide counter in TextField.maxLength (flutter/flutter#175797)
2025-09-23 [email protected] [a11y-app] Fix Autocomplete semantics label (flutter/flutter#175409)
2025-09-23 [email protected] Roll Fuchsia Linux SDK from CcCe3HpQtBYhTZscb... to naeytagBIBEpKgZNZ... (flutter/flutter#175824)
2025-09-23 [email protected] Roll Skia from a38a531dec1d to cabeab8cb22c (16 revisions) (flutter/flutter#175822)
2025-09-23 [email protected] Load fonts in the order addFont is called (flutter/flutter#174253)
2025-09-22 [email protected] Roll pub packages (flutter/flutter#175545)
2025-09-22 [email protected] Remove `name` field form `SupportedPlatform` enum (flutter/flutter#175611)
2025-09-22 [email protected] [web] Cleanup opportunities post renderer unification (flutter/flutter#174659)
2025-09-22 [email protected] Update `KeyChannelResponder.java`  to use method reference  (flutter/flutter#175510)
2025-09-22 [email protected] Update docs/engine/contributing/Compiling-the-engine.md with macOS build steps (flutter/flutter#175716)
2025-09-22 [email protected] [ Widget Preview ] Allow for custom `Preview` annotations, add support for runtime transformations (flutter/flutter#175535)
2025-09-22 [email protected] Remove unnecessary public modifier in `KeyboardManager.java` (flutter/flutter#175500)
2025-09-22 [email protected] bump robolectric and java to 21 (flutter/flutter#175550)
2025-09-22 [email protected] Fix: Update docs tool tag to sample in ImageProvider (flutter/flutter#175256)
2025-09-22 [email protected]  Roll Packages from 3d5c419 to 45c9a84 (flutter/flutter#175794)
2025-09-21 [email protected] Correctly implement PlatformViews' cursors on Web (flutter/flutter#174300)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Jaineel-Mamtora pushed a commit to Jaineel-Mamtora/flutter_forked that referenced this pull request Sep 24, 2025
Before this change, `load` loads fonts in a non-deterministic order.
After this change, it loads the fonts sequentially.

See cl/797583429 for the full context. We found that the order of how
fonts load for a specific font family actually affects runtime behavior,
and the current non-deterministic order of loading fonts leads to
flakiness.

Consider the following:

- foo.ttf has glyphs 'A' and 'B'
- foo-italic.ttf only has glyph 'B'

If `addFont(foo-italic.ttf)` is called before `addFont(foo.ttf)`, the
font loader will load `foo-italic.ttf` first and use that as the base
font. When looking for the 'A' glyph, it may will look for the glyph
only in `foo-italic.ttf`, which doesn't have it, and will show an
incorrect empty placeholder glyph.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

---------

Co-authored-by: Kate Lovett <[email protected]>
@jason-simmons
Copy link
Member

Note that this was necessary in the cl/797583429 case because the italic TTF file used there did not contain the correct data indicating that it is an italic font.

The scoring algorithm in SkFontStyleSet::matchStyleCSS3 will search for the typeface whose attributes most closely match the specified text style. Ordinarily, if the text style does not request italics, then the algorithm will prefer the regular typeface over the italic typeface.

However, in this situation the italic font asset was missing data like the OS/2.fsSelection italic bit and the post.italicAngle value. So the scoring algorithm did not know it was an italic font and assigned it the same score as the regular font. If both fonts have the same score, then matchStyleCSS3 will default to the font that comes first in the iteration order.

Ideally the tables within that font should be fixed. But this PR will ensure that the results are consistent if there is an error in the font that produces the wrong scores.

@jiahaog
Copy link
Member Author

jiahaog commented Sep 30, 2025

Thanks for looking it and sharing the root cause!

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 12, 2025
reidbaker pushed a commit to AbdeMohlbi/flutter that referenced this pull request Dec 10, 2025
Before this change, `load` loads fonts in a non-deterministic order.
After this change, it loads the fonts sequentially.

See cl/797583429 for the full context. We found that the order of how
fonts load for a specific font family actually affects runtime behavior,
and the current non-deterministic order of loading fonts leads to
flakiness.

Consider the following:

- foo.ttf has glyphs 'A' and 'B'
- foo-italic.ttf only has glyph 'B'

If `addFont(foo-italic.ttf)` is called before `addFont(foo.ttf)`, the
font loader will load `foo-italic.ttf` first and use that as the base
font. When looking for the 'A' glyph, it may will look for the glyph
only in `foo-italic.ttf`, which doesn't have it, and will show an
incorrect empty placeholder glyph.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

---------

Co-authored-by: Kate Lovett <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants