-
Notifications
You must be signed in to change notification settings - Fork 6k
[canvaskit] Generate fallback font data file #34729
[canvaskit] Generate fallback font data file #34729
Conversation
| // 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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>['); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
yjbanov
left a comment
There was a problem hiding this 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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe make it a computeUnicodeRanges() method?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Generates fallback font data by downloading and analyzing all known "Noto Sans" fonts.
Fixes flutter/flutter#101738
Pre-launch Checklist
writing and running engine tests.
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.