sw/source/core/text/inftxt.cxx | 56 ++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 36 deletions(-)
New commits: commit 06824845cc0a1b48d87554091bcac5aad8d60b4a Author: Justin Luth <jl...@mail.com> AuthorDate: Fri May 12 15:40:54 2023 -0400 Commit: Justin Luth <jl...@mail.com> CommitDate: Sat May 13 02:18:51 2023 +0200 NFC tdf#130363 sw layout: cleanup MS Word compatibility trailing blanks Cleaning up the code separately so my change can be better understood. Change-Id: Ib756eb8c86f0c515056fba3e9af61cf645a19365 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151715 Tested-by: Jenkins Reviewed-by: Justin Luth <jl...@mail.com> diff --git a/sw/source/core/text/inftxt.cxx b/sw/source/core/text/inftxt.cxx index 895d2aba2dd7..dcb1657d2801 100644 --- a/sw/source/core/text/inftxt.cxx +++ b/sw/source/core/text/inftxt.cxx @@ -1216,35 +1216,30 @@ void SwTextPaintInfo::DrawBackBrush( const SwLinePortion &rPor ) const { bool draw = false; bool full = false; - SwLinePortion *pPos = const_cast<SwLinePortion *>(&rPor); + const sal_Int32 nMaxLen = GetText().getLength(); + const sal_Int32 nCurrPorEnd(GetIdx() + rPor.GetLen()); + const SwLinePortion* pPos = &rPor; TextFrameIndex nIdx = GetIdx(); - TextFrameIndex nLen; do { - nLen = pPos->GetLen(); - for (TextFrameIndex i = nIdx; i < (nIdx + nLen); ++i) + const sal_Int32 nEndPos = std::min(sal_Int32(nIdx + pPos->GetLen()), nMaxLen); + for (sal_Int32 i = sal_Int32(nIdx); i < nEndPos; ++i) { - if (i < TextFrameIndex(GetText().getLength()) - && GetText()[sal_Int32(i)] == CH_TXTATR_NEWLINE) - { - if ( i >= (GetIdx() + rPor.GetLen()) ) - { - goto drawcontinue; - } - } - if (i >= TextFrameIndex(GetText().getLength()) - || GetText()[sal_Int32(i)] != CH_BLANK) + if (i < nMaxLen && i >= nCurrPorEnd && GetText()[i] == CH_TXTATR_NEWLINE) + goto drawcontinue; + + if (i == nMaxLen || GetText()[i] != CH_BLANK) { draw = true; - if ( i >= (GetIdx() + rPor.GetLen()) ) + if (i >= nCurrPorEnd) { full = true; goto drawcontinue; } } } - nIdx += nLen; + nIdx += pPos->GetLen(); pPos = pPos->GetNextPortion(); } while ( pPos ); @@ -1255,36 +1250,25 @@ void SwTextPaintInfo::DrawBackBrush( const SwLinePortion &rPor ) const if ( !full ) { - pPos = const_cast<SwLinePortion *>(&rPor); - nIdx = GetIdx(); - - nLen = pPos->GetLen(); - for (TextFrameIndex i = nIdx + nLen - TextFrameIndex(1); - i >= nIdx; --i) + const sal_Int32 nLastPos = std::min(nCurrPorEnd, nMaxLen) - 1; + for (sal_Int32 i = nLastPos; TextFrameIndex(i) >= GetIdx(); --i) { - if (i < TextFrameIndex(GetText().getLength()) - && GetText()[sal_Int32(i)] == CH_TXTATR_NEWLINE) - { + if (GetText()[i] == CH_TXTATR_NEWLINE) continue; - } - if ((i + TextFrameIndex(1) ).get() > GetText().getLength()) - // prevent crash by not passing bad data down to GetTextSize->SwDrawTextInfo - SAL_WARN("sw", "something dodgy, clamping text index to prevent crash"); - else if (i >= TextFrameIndex(GetText().getLength()) - || GetText()[sal_Int32(i)] != CH_BLANK) + + if (GetText()[i] != CH_BLANK) { - sal_uInt16 nOldWidth = rPor.Width(); - sal_uInt16 nNewWidth = GetTextSize(m_pOut, nullptr, - GetText(), nIdx, (i + TextFrameIndex(1) - nIdx)).Width(); + const sal_uInt16 nOldWidth = rPor.Width(); + const sal_uInt16 nNewWidth + = GetTextSize(m_pOut, nullptr, GetText(), GetIdx(), + TextFrameIndex(i + 1) - GetIdx()).Width(); const_cast<SwLinePortion&>(rPor).Width( nNewWidth ); CalcRect( rPor, nullptr, &aIntersect, true ); const_cast<SwLinePortion&>(rPor).Width( nOldWidth ); if ( !aIntersect.HasArea() ) - { return; - } break; }