Bug 1719535 - Part 9. Trim ASCII space at the tail for content serializer. r=TYLin

XML/Plain text Serializer uses line break segmenter to wrap text. New
segmenter that is compatible with UAX#14 has different rules for old segmenter.

Old segmenter have break opportunity before ASCII space, but UAX#14 doesn't
have it (https://www.unicode.org/reports/tr14/#LB7).

So we have to trim ASCII space at the tail for text wrap.

Depends on D167677

Differential Revision: https://phabricator.services.mozilla.com/D180773
This commit is contained in:
Makoto Kato
2023-08-07 06:23:59 +00:00
parent c98e87fe62
commit 178aa5a5c8
2 changed files with 26 additions and 1 deletions

View File

@@ -131,7 +131,19 @@ int32_t nsPlainTextSerializer::CurrentLine::FindWrapIndexForContent(
// mContent until we find a width less than or equal to wrap column.
uint32_t width = 0;
intl::LineBreakIteratorUtf16 lineBreakIter(mContent);
while (const Maybe<uint32_t> nextGoodSpace = lineBreakIter.Next()) {
while (Maybe<uint32_t> nextGoodSpace = lineBreakIter.Next()) {
// Trim space at the tail. UAX#14 doesn't have break opportunity for
// ASCII space at the tail.
const Maybe<uint32_t> originalNextGoodSpace = nextGoodSpace;
while (*nextGoodSpace > 0 &&
mContent.CharAt(*nextGoodSpace - 1) == 0x20) {
nextGoodSpace = Some(*nextGoodSpace - 1);
}
if (*nextGoodSpace == 0) {
// Restore the original nextGoodSpace.
nextGoodSpace = originalNextGoodSpace;
}
width += GetUnicharStringWidth(Span<const char16_t>(
mContent.get() + goodSpace, *nextGoodSpace - goodSpace));
if (prefixwidth + width > aWrapColumn) {

View File

@@ -1560,6 +1560,19 @@ bool nsXMLContentSerializer::AppendWrapped_NonWhitespaceSequence(
MOZ_ASSERT(nextWrapPosition.isSome(),
"We should've exited the loop when reaching the end of "
"text in the previous iteration!");
// Trim space at the tail. UAX#14 doesn't have break opportunity
// for ASCII space at the tail.
const Maybe<uint32_t> originalNextWrapPosition = nextWrapPosition;
while (*nextWrapPosition > 0 &&
subSeq.at(*nextWrapPosition - 1) == 0x20) {
nextWrapPosition = Some(*nextWrapPosition - 1);
}
if (*nextWrapPosition == 0) {
// Restore the original nextWrapPosition.
nextWrapPosition = originalNextWrapPosition;
}
if (aSequenceStart + *nextWrapPosition > aPos) {
break;
}