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
This commit is contained in:
Makoto Kato 2023-11-01 05:46:50 +00:00
Родитель 11d085b63c
Коммит c9e6ad1c35
4 изменённых файлов: 62 добавлений и 8 удалений

Просмотреть файл

@ -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<char16_t>(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<uint8_t>(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) {

Просмотреть файл

@ -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<char16_t, 100> mCurrentWord;
// All the items that contribute to mCurrentWord
AutoTArray<TextItem, 2> mTextItems;

Просмотреть файл

@ -1,2 +0,0 @@
[word-break-break-all-ethiopic.html]
expected: FAIL

Просмотреть файл

@ -0,0 +1,46 @@
<!doctype html>
<html>
<meta charset="utf-8">
<title>CSS Text — line breaking around Break After and Exclamation</title>
<meta name=assert content="When white-space allows wrapping, line breaking behavior defined for BA and EX line-breaking classes in [UAX14] must be honored.">
<link rel=help href="https://www.w3.org/TR/css-text-3/#line-breaking">
<link rel=help href="https://bugzilla.mozilla.org/show_bug.cgi?id=628825">
<link rel=author title="Makoto Kato" href="mailto:m_kato@ga2.so-net.ne.jp">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
.test > div {
font-family: monospace;
font-size: 25px;
width: 1ch;
line-height: 30px;
}
</style>
<body>
<div class="test">
<div id="nonbreakable1">X&#x1361;!</div>
<div id="nonbreakable2">X&#x1680;!</div>
<div id="nonbreakable3">X&#x2009;!</div>
<div id="nonbreakable4">X&#x205F;!</div>
</div>
<script>
test(function() {
assert_true(document.getElementById('nonbreakable1').offsetHeight <= 35);
}, "U+0x1361 (BA) and U+0x0021 (EX)");
test(function() {
assert_true(document.getElementById('nonbreakable2').offsetHeight <= 35);
}, "U+0x1680 (BA) and U+0x0021 (EX)");
test(function() {
assert_true(document.getElementById('nonbreakable3').offsetHeight <= 35);
}, "U+0x2009 (BA) and U+0x0021 (EX)");
test(function() {
assert_true(document.getElementById('nonbreakable4').offsetHeight <= 35);
}, "U+0x205F (BA) and U+0x0021 (EX)");
</script>
<div id='log'></div>
</body>
</html>