From c9e6ad1c35b5fbe4c06c09142b4886d13555803a Mon Sep 17 00:00:00 2001 From: Makoto Kato Date: Wed, 1 Nov 2023 05:46:50 +0000 Subject: [PATCH] Bug 628825 - Don't break line by Break After. r=TYLin,jfkthame Legacy segmenter breaks line by some Break After properties. But UAX#14 rule doesn't break Break After (BA) at force. So I would like to remove some legacy rules that isn't ASCII white space from `nsLineBreaker`. Differential Revision: https://phabricator.services.mozilla.com/D192174 --- dom/base/nsLineBreaker.cpp | 12 ++--- dom/base/nsLineBreaker.h | 10 ++++ .../word-break-break-all-ethiopic.html.ini | 2 - .../line-breaking/line-breaking-028.html | 46 +++++++++++++++++++ 4 files changed, 62 insertions(+), 8 deletions(-) delete mode 100644 testing/web-platform/meta/css/css-text/word-break/word-break-break-all-ethiopic.html.ini create mode 100644 testing/web-platform/tests/css/css-text/line-breaking/line-breaking-028.html diff --git a/dom/base/nsLineBreaker.cpp b/dom/base/nsLineBreaker.cpp index b44c7343d752..ffc224fc278c 100644 --- a/dom/base/nsLineBreaker.cpp +++ b/dom/base/nsLineBreaker.cpp @@ -252,7 +252,7 @@ nsresult nsLineBreaker::AppendText(nsAtom* aHyphenationLanguage, NS_ASSERTION(!mAfterBreakableSpace && !mBreakHere, "These should not be set"); - while (offset < aLength && !IsSpace(aText[offset])) { + while (offset < aLength && !IsSegmentSpace(aText[offset])) { mCurrentWord.AppendElement(aText[offset]); if (!mCurrentWordMightBeBreakable && !IsNonBreakableChar(aText[offset], mLegacyBehavior)) { @@ -306,7 +306,7 @@ nsresult nsLineBreaker::AppendText(nsAtom* aHyphenationLanguage, offset = aLength; while (offset > start) { --offset; - if (IsSpace(aText[offset])) { + if (IsSegmentSpace(aText[offset])) { break; } } @@ -323,7 +323,7 @@ nsresult nsLineBreaker::AppendText(nsAtom* aHyphenationLanguage, for (;;) { char16_t ch = aText[offset]; - bool isSpace = IsSpace(ch); + bool isSpace = IsSegmentSpace(ch); bool isBreakableSpace = isSpace && !(aFlags & BREAK_SUPPRESS_INSIDE); if (aSink && !noBreaksNeeded) { @@ -442,7 +442,7 @@ nsresult nsLineBreaker::AppendText(nsAtom* aHyphenationLanguage, NS_ASSERTION(!mAfterBreakableSpace && !mBreakHere, "These should not be set"); - while (offset < aLength && !IsSpace(aText[offset])) { + while (offset < aLength && !IsSegmentSpace(aText[offset])) { mCurrentWord.AppendElement(aText[offset]); if (!mCurrentWordMightBeBreakable && !IsNonBreakableChar(aText[offset], mLegacyBehavior)) { @@ -486,7 +486,7 @@ nsresult nsLineBreaker::AppendText(nsAtom* aHyphenationLanguage, offset = aLength; while (offset > start) { --offset; - if (IsSpace(aText[offset])) { + if (IsSegmentSpace(aText[offset])) { break; } } @@ -496,7 +496,7 @@ nsresult nsLineBreaker::AppendText(nsAtom* aHyphenationLanguage, for (;;) { uint8_t ch = aText[offset]; - bool isSpace = IsSpace(ch); + bool isSpace = IsSegmentSpace(ch); bool isBreakableSpace = isSpace && !(aFlags & BREAK_SUPPRESS_INSIDE); if (aSink) { diff --git a/dom/base/nsLineBreaker.h b/dom/base/nsLineBreaker.h index 6701cc756931..6e409cea6dda 100644 --- a/dom/base/nsLineBreaker.h +++ b/dom/base/nsLineBreaker.h @@ -242,6 +242,16 @@ class nsLineBreaker { const char16_t* aTextStart, const char16_t* aTextLimit, uint8_t* aBreakState); + inline constexpr bool IsSegmentSpace(char16_t u) const { + if (mLegacyBehavior) { + return nsLineBreaker::IsSpace(u); + } + + return u == 0x0020 || // SPACE u + u == 0x0009 || // CHARACTER TABULATION + u == 0x000D; // CARRIAGE RETURN + } + AutoTArray mCurrentWord; // All the items that contribute to mCurrentWord AutoTArray mTextItems; diff --git a/testing/web-platform/meta/css/css-text/word-break/word-break-break-all-ethiopic.html.ini b/testing/web-platform/meta/css/css-text/word-break/word-break-break-all-ethiopic.html.ini deleted file mode 100644 index 4cd08ee4c345..000000000000 --- a/testing/web-platform/meta/css/css-text/word-break/word-break-break-all-ethiopic.html.ini +++ /dev/null @@ -1,2 +0,0 @@ -[word-break-break-all-ethiopic.html] - expected: FAIL diff --git a/testing/web-platform/tests/css/css-text/line-breaking/line-breaking-028.html b/testing/web-platform/tests/css/css-text/line-breaking/line-breaking-028.html new file mode 100644 index 000000000000..c82d4762a597 --- /dev/null +++ b/testing/web-platform/tests/css/css-text/line-breaking/line-breaking-028.html @@ -0,0 +1,46 @@ + + + +CSS Text — line breaking around Break After and Exclamation + + + + + + + + + +
+
X፡!
+
X !
+
X !
+
X !
+
+ + + +
+ + +