Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@harryterkelsen
Copy link
Contributor

@harryterkelsen harryterkelsen commented Jul 18, 2022

Generates fallback font data by downloading and analyzing all known "Noto Sans" fonts.

Fixes flutter/flutter#101738

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 and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@harryterkelsen harryterkelsen added the Work in progress (WIP) Not ready (yet) for review! label Jul 18, 2022
@flutter-dashboard flutter-dashboard bot added platform-fuchsia platform-web Code specifically for the web engine labels Jul 18, 2022
// Returns `true` if this font has a glyph for the given [codeunit].
bool contains(int codeunit) {
// The list of codeunit ranges is sorted.
for (final CodeunitRange range in unicodeRanges) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the worst case length of the unicodeRanges list? If it's sorted, can we use binary search instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

sb.writeln('const List<NotoFont> fallbackFonts = <NotoFont>[');
for (final String family in fallbackFonts) {
sb.writeln(' NotoFont(\'$family\', \'${urlForFamily[family]!}\', '
'<CodeunitRange>[');
Copy link
Contributor

Choose a reason for hiding this comment

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

We should check the code size impact of encoding ranges this way. Perhaps encoding ranges as a flat list of <int>[start1, end1, start2, end2, ..., startN, endN] numbers would produce significantly more compact code? I imagine the time difference in initializing the objects would be trivial.

Another thing is, looking at how these ranges are used in NotoFont.contains I wonder if we should actually store it as two flat lists of numbers, rangeStarts and rangeEnds, something like:

final NotoFont notoSans = NotoFont(
  rangeStarts: <int>[1, 5, 11],
  rangeEnds:   <int>[3, 7, 17],
);

Then the contains method could binary search rangeStarts and rangeEnds (should be super fast to binary search flat lists of numbers), and if both searches land on the same range index, then we know that the font contains the code unit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

..addCommand(BuildCommand())
..addCommand(CleanCommand())
..addCommand(CreateSimulatorCommand())
..addCommand(GenerateFallbackFontDataCommand())
Copy link
Contributor

Choose a reason for hiding this comment

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

This is more of a roll process, similar to canvaskit_roller.dart or browser_roller.dart, than something part of our normal dev cycle. So I'm not sure if a felt command is needed, but I don't feel strongly about it.

More importantly, let's document it in our README.md. The best place would we next to our existing "Rolling X" sections.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@yjbanov yjbanov left a comment

Choose a reason for hiding this comment

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

LGTM assuming I'm wrong about the bug in the binary search.

// A sorted list of Unicode range end points.
final List<int> _rangeEnds;

List<CodeunitRange> get unicodeRanges {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

min = mid;
}
}
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the while loop never considers the last range (because there's no rangeStart that is greater that codeunit after the last range), so before returning false this might need to check if the last range contains the code unit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@harryterkelsen harryterkelsen merged commit 3e9fcf4 into flutter:main Aug 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 19, 2022
bdero added a commit that referenced this pull request Aug 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 19, 2022
zanderso pushed a commit that referenced this pull request Aug 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

platform-fuchsia platform-web Code specifically for the web engine Work in progress (WIP) Not ready (yet) for review!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Web canvaskit] Does not render Thai Text on Edge browser

2 participants