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

Commit 805b145

Browse files
authored
[web] Improve line breaker test exceptions (#37244)
* [web] Improve line breaker test exceptions * always break after spaces * explain reason for modifications
1 parent 449fcc8 commit 805b145

File tree

2 files changed

+68
-113
lines changed

2 files changed

+68
-113
lines changed

lib/web_ui/lib/src/engine/text/line_breaker.dart

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ List<LineBreakFragment> _computeLineBreakFragments(String text) {
127127
int? codePoint = getCodePoint(text, 0);
128128
LineCharProperty? curr = lineLookup.findForChar(codePoint);
129129

130-
// When there's a sequence of spaces, this variable contains the base property
131-
// i.e. the property of the character preceding the sequence.
132-
LineCharProperty baseOfSpaceSequence = LineCharProperty.WJ;
133-
134130
// When there's a sequence of combining marks, this variable contains the base
135131
// property i.e. the property of the character preceding the sequence.
136132
LineCharProperty baseOfCombiningMarks = LineCharProperty.AL;
@@ -146,6 +142,9 @@ List<LineBreakFragment> _computeLineBreakFragments(String text) {
146142
type == LineBreakType.endOfText ? text.length : index;
147143
assert(fragmentEnd >= fragmentStart);
148144

145+
// Uncomment the following line to help debug line breaking.
146+
// print('{$fragmentStart:$fragmentEnd} [$debugRuleNumber] -- $type');
147+
149148
if (prev1 == LineCharProperty.SP) {
150149
trailingSpaces++;
151150
} else if (_isHardBreak(prev1) || prev1 == LineCharProperty.CR) {
@@ -244,13 +243,6 @@ List<LineBreakFragment> _computeLineBreakFragments(String text) {
244243
break;
245244
}
246245

247-
// Establish the base for the space sequence.
248-
if (prev1 != LineCharProperty.SP) {
249-
// When the text/line starts with SP, we should treat the beginning of text/line
250-
// as if it were a WJ (word joiner).
251-
baseOfSpaceSequence = prev1 ?? LineCharProperty.WJ;
252-
}
253-
254246
// Do not break before spaces or zero width space.
255247
// LB7: × SP
256248
// × ZW
@@ -259,11 +251,17 @@ List<LineBreakFragment> _computeLineBreakFragments(String text) {
259251
continue;
260252
}
261253

254+
// Break after spaces.
255+
// LB18: SP ÷
256+
if (prev1 == LineCharProperty.SP) {
257+
setBreak(LineBreakType.opportunity, 18);
258+
continue;
259+
}
260+
262261
// Break before any character following a zero-width space, even if one or
263262
// more spaces intervene.
264263
// LB8: ZW SP* ÷
265-
if (prev1 == LineCharProperty.ZW ||
266-
baseOfSpaceSequence == LineCharProperty.ZW) {
264+
if (prev1 == LineCharProperty.ZW) {
267265
setBreak(LineBreakType.opportunity, 8);
268266
continue;
269267
}
@@ -343,6 +341,8 @@ List<LineBreakFragment> _computeLineBreakFragments(String text) {
343341
// The above is a quote from unicode.org. In our implementation, we did the
344342
// following modification: When there are spaces present, we consider it a
345343
// line break opportunity.
344+
//
345+
// We made this modification to match the browser behavior.
346346
if (prev1 != LineCharProperty.SP &&
347347
(curr == LineCharProperty.CL ||
348348
curr == LineCharProperty.CP ||
@@ -358,6 +358,8 @@ List<LineBreakFragment> _computeLineBreakFragments(String text) {
358358
//
359359
// The above is a quote from unicode.org. In our implementation, we did the
360360
// following modification: Allow breaks when there are spaces.
361+
//
362+
// We made this modification to match the browser behavior.
361363
if (prev1 == LineCharProperty.OP) {
362364
setBreak(LineBreakType.prohibited, 14);
363365
continue;
@@ -368,6 +370,8 @@ List<LineBreakFragment> _computeLineBreakFragments(String text) {
368370
//
369371
// The above is a quote from unicode.org. In our implementation, we did the
370372
// following modification: Allow breaks when there are spaces.
373+
//
374+
// We made this modification to match the browser behavior.
371375
if (prev1 == LineCharProperty.QU && curr == LineCharProperty.OP) {
372376
setBreak(LineBreakType.prohibited, 15);
373377
continue;
@@ -376,31 +380,29 @@ List<LineBreakFragment> _computeLineBreakFragments(String text) {
376380
// Do not break between closing punctuation and a nonstarter, even with
377381
// intervening spaces.
378382
// LB16: (CL | CP) SP* × NS
379-
if ((prev1 == LineCharProperty.CL ||
380-
baseOfSpaceSequence == LineCharProperty.CL ||
381-
prev1 == LineCharProperty.CP ||
382-
baseOfSpaceSequence == LineCharProperty.CP) &&
383+
//
384+
// The above is a quote from unicode.org. In our implementation, we did the
385+
// following modification: Allow breaks when there are spaces.
386+
//
387+
// We made this modification to match the browser behavior.
388+
if ((prev1 == LineCharProperty.CL || prev1 == LineCharProperty.CP) &&
383389
curr == LineCharProperty.NS) {
384390
setBreak(LineBreakType.prohibited, 16);
385391
continue;
386392
}
387393

388394
// Do not break within ‘——’, even with intervening spaces.
389395
// LB17: B2 SP* × B2
390-
if ((prev1 == LineCharProperty.B2 ||
391-
baseOfSpaceSequence == LineCharProperty.B2) &&
392-
curr == LineCharProperty.B2) {
396+
//
397+
// The above is a quote from unicode.org. In our implementation, we did the
398+
// following modification: Allow breaks when there are spaces.
399+
//
400+
// We made this modification to match the browser behavior.
401+
if (prev1 == LineCharProperty.B2 && curr == LineCharProperty.B2) {
393402
setBreak(LineBreakType.prohibited, 17);
394403
continue;
395404
}
396405

397-
// Break after spaces.
398-
// LB18: SP ÷
399-
if (prev1 == LineCharProperty.SP) {
400-
setBreak(LineBreakType.opportunity, 18);
401-
continue;
402-
}
403-
404406
// Do not break before or after quotation marks, such as ‘”’.
405407
// LB19: × QU
406408
// QU ×

0 commit comments

Comments
 (0)