From 9e075acf2bf1ce6c43fdf5b601507ee0663bd691 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 21 May 2021 11:25:12 +0200 Subject: sw: eliminate recently added static_cast() calls This was added in commit 301278b656e76b6f42af5cf8a6f5c6c02acfffeb (sw: allow the height of a line to be larger than 65536 twips, 2021-05-20) to fix -Werror,-Wsign-compare problems, but o3tl::narrowing() is a better way to handle this, as that way the integer conversion is still implicit, which allows detecting integer truncation at runtime (with suitable compiler flags). Change-Id: I2f62420457e3d053e6fbc3b787b3c224c6f0586c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115903 Tested-by: Jenkins Reviewed-by: Miklos Vajna --- sw/source/core/text/frmcrsr.cxx | 2 +- sw/source/core/text/frmform.cxx | 4 ++-- sw/source/core/text/frmpaint.cxx | 2 +- sw/source/core/text/inftxt.cxx | 4 ++-- sw/source/core/text/itrcrsr.cxx | 2 +- sw/source/core/text/itrform2.cxx | 8 ++++---- sw/source/core/text/itrpaint.cxx | 10 +++++----- sw/source/core/text/itrtxt.cxx | 2 +- sw/source/core/text/porfld.cxx | 8 ++++---- sw/source/core/text/pormulti.cxx | 8 ++++---- sw/source/core/text/porrst.cxx | 2 +- 11 files changed, 26 insertions(+), 26 deletions(-) (limited to 'sw/source') diff --git a/sw/source/core/text/frmcrsr.cxx b/sw/source/core/text/frmcrsr.cxx index 21af2c622af1..ce29c020fa4a 100644 --- a/sw/source/core/text/frmcrsr.cxx +++ b/sw/source/core/text/frmcrsr.cxx @@ -590,7 +590,7 @@ bool SwTextFrame::GetModelPositionForViewPoint_(SwPosition* pPos, const Point& r // See comment in AdjustFrame() SwTwips nMaxY = getFrameArea().Top() + getFramePrintArea().Top() + getFramePrintArea().Height(); aLine.TwipsToLine( rPoint.Y() ); - while( aLine.Y() + static_cast(aLine.GetLineHeight()) > nMaxY ) + while( aLine.Y() + o3tl::narrowing(aLine.GetLineHeight()) > nMaxY ) { if( !aLine.Prev() ) break; diff --git a/sw/source/core/text/frmform.cxx b/sw/source/core/text/frmform.cxx index 5aade6a0169b..d461c938739c 100644 --- a/sw/source/core/text/frmform.cxx +++ b/sw/source/core/text/frmform.cxx @@ -1200,7 +1200,7 @@ bool SwTextFrame::FormatLine( SwTextFormatter &rLine, const bool bPrev ) bOldHyph == pNew->IsEndHyph(); if ( bUnChg && !bPrev ) { - const tools::Long nWidthDiff = nOldWidth > static_cast(pNew->Width()) + const tools::Long nWidthDiff = nOldWidth > o3tl::narrowing(pNew->Width()) ? nOldWidth - pNew->Width() : pNew->Width() - nOldWidth; @@ -1254,7 +1254,7 @@ bool SwTextFrame::FormatLine( SwTextFormatter &rLine, const bool bPrev ) rLine.SetUnclipped( false ); } } - SwTwips nRght = std::max( nOldWidth, static_cast(pNew->Width()) + + SwTwips nRght = std::max( nOldWidth, o3tl::narrowing(pNew->Width()) + pNew->GetHangingMargin() ); SwViewShell *pSh = getRootFrame()->GetCurrShell(); const SwViewOption *pOpt = pSh ? pSh->GetViewOptions() : nullptr; diff --git a/sw/source/core/text/frmpaint.cxx b/sw/source/core/text/frmpaint.cxx index 93007bfcf539..76630fc573f6 100644 --- a/sw/source/core/text/frmpaint.cxx +++ b/sw/source/core/text/frmpaint.cxx @@ -356,7 +356,7 @@ void SwTextFrame::PaintExtraData( const SwRect &rRect ) const SwTextPainter aLine( const_cast(this), &aInf ); bool bNoDummy = !aLine.GetNext(); // Only one empty line! - while( aLine.Y() + static_cast(aLine.GetLineHeight()) <= rRect.Top() ) + while( aLine.Y() + o3tl::narrowing(aLine.GetLineHeight()) <= rRect.Top() ) { if( !aLine.GetCurr()->IsDummy() && ( rLineInf.IsCountBlankLines() || diff --git a/sw/source/core/text/inftxt.cxx b/sw/source/core/text/inftxt.cxx index 261a171d3d6d..344ccede8962 100644 --- a/sw/source/core/text/inftxt.cxx +++ b/sw/source/core/text/inftxt.cxx @@ -1023,13 +1023,13 @@ void SwTextPaintInfo::DrawRedArrow( const SwLinePortion &rPor ) const { aRect.Pos().AdjustY(20 - GetAscent() ); aRect.Pos().AdjustX(20 ); - if( aSize.Height() > static_cast(rPor.Height()) ) + if( aSize.Height() > o3tl::narrowing(rPor.Height()) ) aRect.Height( rPor.Height() ); cChar = CHAR_LEFT_ARROW; } else { - if( aSize.Height() > static_cast(rPor.Height()) ) + if( aSize.Height() > o3tl::narrowing(rPor.Height()) ) aRect.Height( rPor.Height() ); aRect.Pos().AdjustY( -(aRect.Height() + 20) ); aRect.Pos().AdjustX( -(aRect.Width() + 20) ); diff --git a/sw/source/core/text/itrcrsr.cxx b/sw/source/core/text/itrcrsr.cxx index c8c2803cb9b0..b728a6ce98ff 100644 --- a/sw/source/core/text/itrcrsr.cxx +++ b/sw/source/core/text/itrcrsr.cxx @@ -1051,7 +1051,7 @@ void SwTextCursor::GetCharRect_( SwRect* pOrig, TextFrameIndex const nOfst, nPorHeight = nPorAscent; pOrig->Height( nPorHeight + static_cast(pPor)->GetDropDescent() ); - if( static_cast(nTmpHeight) < pOrig->Height() ) + if( o3tl::narrowing(nTmpHeight) < pOrig->Height() ) { nTmpAscent = nPorAscent; nTmpHeight = sal_uInt16( pOrig->Height() ); diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx index 504a13668fb2..c61e05ea0ab9 100644 --- a/sw/source/core/text/itrform2.cxx +++ b/sw/source/core/text/itrform2.cxx @@ -2365,7 +2365,7 @@ void SwTextFormatter::CalcFlyWidth( SwTextFormatInfo &rInf ) nAscent = pLast->GetAscent(); nHeight = pLast->Height(); - if ( static_cast(m_pCurr->GetRealHeight()) > nHeight ) + if ( o3tl::narrowing(m_pCurr->GetRealHeight()) > nHeight ) nTop += m_pCurr->GetRealHeight() - nHeight; else // Important for fixed space between lines @@ -2496,7 +2496,7 @@ void SwTextFormatter::CalcFlyWidth( SwTextFormatInfo &rInf ) if( nH < SAL_MAX_UINT16 ) pFly->Height( sal_uInt16( nH ) ); } - if( nAscent < static_cast(pFly->Height()) ) + if( nAscent < o3tl::narrowing(pFly->Height()) ) pFly->SetAscent( sal_uInt16(nAscent) ); else pFly->SetAscent( pFly->Height() ); @@ -2512,7 +2512,7 @@ void SwTextFormatter::CalcFlyWidth( SwTextFormatInfo &rInf ) else { pFly->Height( sal_uInt16(aInter.Height()) ); - if( nAscent < static_cast(pFly->Height()) ) + if( nAscent < o3tl::narrowing(pFly->Height()) ) pFly->SetAscent( sal_uInt16(nAscent) ); else pFly->SetAscent( pFly->Height() ); @@ -2609,7 +2609,7 @@ SwFlyCntPortion *SwTextFormatter::NewFlyCntPortion( SwTextFormatInfo &rInf, { nAscent = rInf.GetLast()->GetAscent(); } - else if( static_cast(nAscent) > nFlyAsc ) + else if( o3tl::narrowing(nAscent) > nFlyAsc ) nFlyAsc = nAscent; Point aBase( GetLeftMargin() + rInf.X(), Y() + nAscent ); diff --git a/sw/source/core/text/itrpaint.cxx b/sw/source/core/text/itrpaint.cxx index 88c8236887ad..8ff1067abd0d 100644 --- a/sw/source/core/text/itrpaint.cxx +++ b/sw/source/core/text/itrpaint.cxx @@ -83,14 +83,14 @@ SwLinePortion *SwTextPainter::CalcPaintOfst( const SwRect &rPaint ) { SwLinePortion *pLast = nullptr; // 7529 and 4757: not <= nPaintOfst - while( pPor && static_cast(GetInfo().X() + pPor->Width() + (pPor->Height()/2)) + while( pPor && o3tl::narrowing(GetInfo().X() + pPor->Width() + (pPor->Height()/2)) < nPaintOfst ) { if( pPor->InSpaceGrp() && GetInfo().GetSpaceAdd() ) { tools::Long nTmp = GetInfo().X() +pPor->Width() + pPor->CalcSpacing( GetInfo().GetSpaceAdd(), GetInfo() ); - if( static_cast(nTmp + (pPor->Height()/2)) >= nPaintOfst ) + if( o3tl::narrowing(nTmp + (pPor->Height()/2)) >= nPaintOfst ) break; GetInfo().X( nTmp ); GetInfo().SetIdx( GetInfo().GetIdx() + pPor->GetLen() ); @@ -192,7 +192,7 @@ void SwTextPainter::DrawTextLine( const SwRect &rPaint, SwSaveClip &rClip, if( GetInfo().GetPos().X() < rPaint.Left() || GetInfo().GetPos().Y() < rPaint.Top() || - GetInfo().GetPos().Y() + static_cast(nTmpHeight) > rPaint.Top() + rPaint.Height() ) + GetInfo().GetPos().Y() + o3tl::narrowing(nTmpHeight) > rPaint.Top() + rPaint.Height() ) { bClip = false; rClip.ChgClip( rPaint, m_pFrame, m_pCurr->HasUnderscore() ); @@ -347,7 +347,7 @@ void SwTextPainter::DrawTextLine( const SwRect &rPaint, SwSaveClip &rClip, // A safety distance of half the height is added, so that // TTF-"f" isn't overlapping into the page margin. if( bClip && - static_cast(GetInfo().X() + pPor->Width() + ( pPor->Height() / 2 )) > nMaxRight ) + o3tl::narrowing(GetInfo().X() + pPor->Width() + ( pPor->Height() / 2 )) > nMaxRight ) { bClip = false; rClip.ChgClip( rPaint, m_pFrame, m_pCurr->HasUnderscore() ); @@ -480,7 +480,7 @@ void SwTextPainter::DrawTextLine( const SwRect &rPaint, SwSaveClip &rClip, SwTwips nDiff = GetInfo().Y() + nTmpHeight - nTmpAscent - GetTextFrame()->getFrameArea().Bottom(); if( ( nDiff > 0 && (GetEnd() < TextFrameIndex(GetInfo().GetText().getLength()) || - ( nDiff > static_cast(nTmpHeight)/2 && GetPrevLine() ) ) ) || + ( nDiff > o3tl::narrowing(nTmpHeight)/2 && GetPrevLine() ) ) ) || (nDiff >= 0 && bNextUndersized) ) { diff --git a/sw/source/core/text/itrtxt.cxx b/sw/source/core/text/itrtxt.cxx index 88c09c47e7ce..8e49e490f7e1 100644 --- a/sw/source/core/text/itrtxt.cxx +++ b/sw/source/core/text/itrtxt.cxx @@ -299,7 +299,7 @@ sal_uInt32 SwTextCursor::AdjustBaseLine( const SwLineLayout& rLine, void SwTextIter::TwipsToLine( const SwTwips y) { - while( m_nY + static_cast(GetLineHeight()) <= y && Next() ) + while( m_nY + o3tl::narrowing(GetLineHeight()) <= y && Next() ) ; while( m_nY > y && Prev() ) ; diff --git a/sw/source/core/text/porfld.cxx b/sw/source/core/text/porfld.cxx index 6f576983ab55..26f3dcf56c98 100755 --- a/sw/source/core/text/porfld.cxx +++ b/sw/source/core/text/porfld.cxx @@ -594,10 +594,10 @@ bool SwNumberPortion::Format( SwTextFormatInfo &rInf ) // Height has to be changed if ( rInf.IsMulti() ) { - if ( static_cast(Height()) < nDiff ) + if ( o3tl::narrowing(Height()) < nDiff ) Height( sal_uInt16( nDiff ) ); } - else if( static_cast(Width()) < nDiff ) + else if( o3tl::narrowing(Width()) < nDiff ) Width( sal_uInt16(nDiff) ); } return bFull; @@ -868,7 +868,7 @@ bool SwGrfNumPortion::Format( SwTextFormatInfo &rInf ) SetHide( true ); } - if( static_cast(Width()) < nDiff ) + if( o3tl::narrowing(Width()) < nDiff ) Width( sal_uInt16(nDiff) ); return bFull; } @@ -1257,7 +1257,7 @@ bool SwCombinedPortion::Format( SwTextFormatInfo &rInf ) Height( Height() + nMainAscent - GetAscent() ); SetAscent( nMainAscent ); } - if( static_cast(Height()) < nMainAscent + nMainDescent ) + if( o3tl::narrowing(Height()) < nMainAscent + nMainDescent ) Height( nMainAscent + nMainDescent ); // We calculate the x positions of the characters in both lines... diff --git a/sw/source/core/text/pormulti.cxx b/sw/source/core/text/pormulti.cxx index 37c5a4e48594..0a6bd2b596dc 100644 --- a/sw/source/core/text/pormulti.cxx +++ b/sw/source/core/text/pormulti.cxx @@ -399,7 +399,7 @@ void SwDoubleLinePortion::FormatBrackets( SwTextFormatInfo &rInf, SwTwips& nMaxW m_pBracket->nAscent = rInf.GetAscent(); m_pBracket->nHeight = aSize.Height(); pTmpFnt->SetActual( nActualScr ); - if( nMaxWidth > static_cast(aSize.Width()) ) + if( nMaxWidth > o3tl::narrowing(aSize.Width()) ) { m_pBracket->nPreWidth = aSize.Width(); nMaxWidth -= aSize.Width(); @@ -428,7 +428,7 @@ void SwDoubleLinePortion::FormatBrackets( SwTextFormatInfo &rInf, SwTwips& nMaxW } if( aSize.Height() > m_pBracket->nHeight ) m_pBracket->nHeight = aSize.Height(); - if( nMaxWidth > static_cast(aSize.Width()) ) + if( nMaxWidth > o3tl::narrowing(aSize.Width()) ) { m_pBracket->nPostWidth = aSize.Width(); nMaxWidth -= aSize.Width(); @@ -2168,7 +2168,7 @@ bool SwTextFormatter::BuildMultiPortion( SwTextFormatInfo &rInf, // Setting this to the portion width ( = rMulti.Width() ) // can make GetTextBreak inside SwTextGuess::Guess return too small // values. Therefore we add some extra twips. - if( nActWidth > nTmpX + static_cast(rMulti.Width()) + 6 ) + if( nActWidth > nTmpX + o3tl::narrowing(rMulti.Width()) + 6 ) nActWidth = nTmpX + rMulti.Width() + 6; nMaxWidth = nActWidth; nActWidth = ( 3 * nMaxWidth + nMinWidth + 3 ) / 4; @@ -2519,7 +2519,7 @@ SwTextCursorSave::SwTextCursorSave( SwTextCursor* pCursor, { pCursor->m_nStart = nCurrStart; pCursor->m_pCurr = &pMulti->GetRoot(); - while( pCursor->Y() + static_cast(pCursor->GetLineHeight()) < nY && + while( pCursor->Y() + o3tl::narrowing(pCursor->GetLineHeight()) < nY && pCursor->Next() ) ; // nothing nWidth = pCursor->m_pCurr->Width(); diff --git a/sw/source/core/text/porrst.cxx b/sw/source/core/text/porrst.cxx index d8d48f3671dc..21a51e135b85 100644 --- a/sw/source/core/text/porrst.cxx +++ b/sw/source/core/text/porrst.cxx @@ -642,7 +642,7 @@ void SwControlCharPortion::Paint( const SwTextPaintInfo &rInf ) const Point aOldPos = rInf.GetPos(); Point aNewPos( aOldPos ); - auto const deltaX((static_cast(Width()) / 2) - mnHalfCharWidth); + auto const deltaX((o3tl::narrowing(Width()) / 2) - mnHalfCharWidth); switch (rInf.GetFont()->GetOrientation(rInf.GetTextFrame()->IsVertical()).get()) { case 0: -- cgit