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

[web] Use v8BreakIterator where possible #37317

Merged
merged 3 commits into from
Nov 8, 2022

Conversation

mdebbar
Copy link
Contributor

@mdebbar mdebbar commented Nov 4, 2022

This PR introduces the usage of Chromium's v8BreakIterator to find line breaks in text. This should lead to more correct line breaking, especially around South Eastern Asian languages that need dictionaries for correct line breaks.

Related to flutter/flutter#112820

@mdebbar mdebbar requested a review from yjbanov November 4, 2022 16:03
@flutter-dashboard flutter-dashboard bot added the platform-web Code specifically for the web engine label Nov 4, 2022
class DomIntl {}

extension DomIntlExtension on DomIntl {
/// This is a Chrome-only API for segmenting text.
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically V8, not Chrome. It's also available in Edge, Opera, Samsung, Brave, etc.

}

@override
List<LineBreakFragment> fragment() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be abstract?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup. Good catch.

const LineBreakFragmenter(super.text);
abstract class LineBreakFragmenter extends TextFragmenter {
factory LineBreakFragmenter(String text) {
if (domWindow.Intl.v8BreakIterator != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would there be any value in running tests in the non-v8BreakIterator mode in Chrome? If so, we may need a way to override this in tests.

Copy link
Contributor Author

@mdebbar mdebbar Nov 8, 2022

Choose a reason for hiding this comment

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

We are running all line breaker tests with both our fragmenter and v8BreakIterator. That should be good enough IMHO.

Other text tests are testing other aspects of text layout, not line breaks specifically. So I don't think there's value in running non-v8BreakIterator mode in Chrome. We could always change this in the future of course.

// Calculate trailing newlines and spaces.
for (int i = fragmentStart; i < fragmentEnd; i++) {
final int codeUnit = text.codeUnitAt(i);
if (_kNewlines.contains(codeUnit)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This may be a premature optimization, but is there a way to avoid list iteration in most cases by checking that the code unit is not even in the new line or space character code range?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which iteration do you want to avoid? I'm assuming Set.contains() is constant, is it not the case?

Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't realize they were constants, so assumed .contains would scan. LGTM.

// Calculate trailing newlines and spaces.
for (int i = fragmentStart; i < fragmentEnd; i++) {
final int codeUnit = text.codeUnitAt(i);
if (_kNewlines.contains(codeUnit)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't realize they were constants, so assumed .contains would scan. LGTM.

@mdebbar mdebbar added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 8, 2022
@auto-submit auto-submit bot merged commit c24ae18 into flutter:main Nov 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 9, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 9, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 9, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 9, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 9, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 9, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 9, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 9, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 9, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 9, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 9, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 9, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 9, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 9, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 9, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 9, 2022
naudzghebre pushed a commit to naudzghebre/engine that referenced this pull request Nov 9, 2022
* [web] Use v8BreakIterator where possible

* address review comments
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 9, 2022
zanderso pushed a commit to flutter/flutter that referenced this pull request Nov 9, 2022
…115008)

* de0b58e82 clang-tidy: added the ability to shard jobs (flutter/engine#37265)

* 8aefb8b61 Roll Dart SDK from d97d5ad98893 to b22b36c0f52e (1 revision) (flutter/engine#37400)

* 2f043090f Roll Skia from aef6d301c0b5 to 0c8127b3dd7d (6 revisions) (flutter/engine#37402)

* dc7cb20ad Fix boolean json property. (flutter/engine#37403)

* 512fa40b6 Adding release_build:true property to windows builders. (flutter/engine#37397)

* 0af87071f Add test for image readback (flutter/engine#37401)

* c6f26e035 Update display_list_image_filter_unittests to be permit Skia roll (flutter/engine#37327)

* 4e9e97b4b Roll Skia from 0c8127b3dd7d to 8b19fb0f57d4 (1 revision) (flutter/engine#37409)

* 42c2940ff Pass the correct name for gclient variables in ci.yaml (flutter/engine#37429)

* 2e2a2fd97 Revert "Roll Skia from 0c8127b3dd7d to 8b19fb0f57d4 (1 revision) (#37409)" (flutter/engine#37430)

* 02cb78905 Roll Fuchsia Mac SDK from sa5bVGimNo3JwLV27... to d4l6A1aPw6Z0YjxmA... (flutter/engine#37432)

* c24ae1872 [web] Use v8BreakIterator where possible (flutter/engine#37317)

* 306b0fe9c Add rects to accumulator rather than bounds (flutter/engine#37435)

* c76035429 Roll Dart SDK from b22b36c0f52e to c15cdb978761 (2 revisions) (flutter/engine#37437)
schwa423 pushed a commit to schwa423/engine that referenced this pull request Nov 16, 2022
* [web] Use v8BreakIterator where possible

* address review comments
shogohida pushed a commit to shogohida/flutter that referenced this pull request Dec 7, 2022
…lutter#115008)

* de0b58e82 clang-tidy: added the ability to shard jobs (flutter/engine#37265)

* 8aefb8b61 Roll Dart SDK from d97d5ad98893 to b22b36c0f52e (1 revision) (flutter/engine#37400)

* 2f043090f Roll Skia from aef6d301c0b5 to 0c8127b3dd7d (6 revisions) (flutter/engine#37402)

* dc7cb20ad Fix boolean json property. (flutter/engine#37403)

* 512fa40b6 Adding release_build:true property to windows builders. (flutter/engine#37397)

* 0af87071f Add test for image readback (flutter/engine#37401)

* c6f26e035 Update display_list_image_filter_unittests to be permit Skia roll (flutter/engine#37327)

* 4e9e97b4b Roll Skia from 0c8127b3dd7d to 8b19fb0f57d4 (1 revision) (flutter/engine#37409)

* 42c2940ff Pass the correct name for gclient variables in ci.yaml (flutter/engine#37429)

* 2e2a2fd97 Revert "Roll Skia from 0c8127b3dd7d to 8b19fb0f57d4 (1 revision) (flutter#37409)" (flutter/engine#37430)

* 02cb78905 Roll Fuchsia Mac SDK from sa5bVGimNo3JwLV27... to d4l6A1aPw6Z0YjxmA... (flutter/engine#37432)

* c24ae1872 [web] Use v8BreakIterator where possible (flutter/engine#37317)

* 306b0fe9c Add rects to accumulator rather than bounds (flutter/engine#37435)

* c76035429 Roll Dart SDK from b22b36c0f52e to c15cdb978761 (2 revisions) (flutter/engine#37437)
@mdebbar mdebbar deleted the v8BreakIterator branch January 17, 2023 18:35
gspencergoog pushed a commit to gspencergoog/flutter that referenced this pull request Jan 19, 2023
…lutter#115008)

* de0b58e82 clang-tidy: added the ability to shard jobs (flutter/engine#37265)

* 8aefb8b61 Roll Dart SDK from d97d5ad98893 to b22b36c0f52e (1 revision) (flutter/engine#37400)

* 2f043090f Roll Skia from aef6d301c0b5 to 0c8127b3dd7d (6 revisions) (flutter/engine#37402)

* dc7cb20ad Fix boolean json property. (flutter/engine#37403)

* 512fa40b6 Adding release_build:true property to windows builders. (flutter/engine#37397)

* 0af87071f Add test for image readback (flutter/engine#37401)

* c6f26e035 Update display_list_image_filter_unittests to be permit Skia roll (flutter/engine#37327)

* 4e9e97b4b Roll Skia from 0c8127b3dd7d to 8b19fb0f57d4 (1 revision) (flutter/engine#37409)

* 42c2940ff Pass the correct name for gclient variables in ci.yaml (flutter/engine#37429)

* 2e2a2fd97 Revert "Roll Skia from 0c8127b3dd7d to 8b19fb0f57d4 (1 revision) (flutter#37409)" (flutter/engine#37430)

* 02cb78905 Roll Fuchsia Mac SDK from sa5bVGimNo3JwLV27... to d4l6A1aPw6Z0YjxmA... (flutter/engine#37432)

* c24ae1872 [web] Use v8BreakIterator where possible (flutter/engine#37317)

* 306b0fe9c Add rects to accumulator rather than bounds (flutter/engine#37435)

* c76035429 Roll Dart SDK from b22b36c0f52e to c15cdb978761 (2 revisions) (flutter/engine#37437)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App platform-web Code specifically for the web engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants