diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-05-21 17:44:32 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-05-21 21:09:57 +0200 |
commit | 2634bc59092b24217d984a5845365d703bdb08d2 (patch) | |
tree | a3b7324d54aefb57d5f012c7aeb1b80d07fce75b /sw/source/core/text/porfld.cxx | |
parent | c912c4b02b2dc4cd5aa62d77e92e1731c6cbde65 (diff) |
sw: replace most static_cast<sal_uInt16>() calls with o3tl::narrowing()
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: I499abda3be6943e8c111c56df390e72939586221
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115948
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw/source/core/text/porfld.cxx')
-rw-r--r-- | sw/source/core/text/porfld.cxx | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/sw/source/core/text/porfld.cxx b/sw/source/core/text/porfld.cxx index 26f3dcf56c98..4d589427850c 100644 --- a/sw/source/core/text/porfld.cxx +++ b/sw/source/core/text/porfld.cxx @@ -785,7 +785,7 @@ SwGrfNumPortion::SwGrfNumPortion( m_nYPos = 0; m_eOrient = text::VertOrientation::TOP; } - Width( static_cast<sal_uInt16>(rGrfSize.Width() + 2 * GRFNUM_SECURE) ); + Width( o3tl::narrowing<sal_uInt16>(rGrfSize.Width() + 2 * GRFNUM_SECURE) ); m_nFixWidth = Width(); m_nGrfHeight = rGrfSize.Height() + 2 * GRFNUM_SECURE; Height( sal_uInt16(m_nGrfHeight) ); @@ -834,7 +834,7 @@ bool SwGrfNumPortion::Format( SwTextFormatInfo &rInf ) if( bFull ) { - Width( rInf.Width() - static_cast<sal_uInt16>(rInf.X()) ); + Width( rInf.Width() - o3tl::narrowing<sal_uInt16>(rInf.X()) ); if( bFly ) { SetLen(TextFrameIndex(0)); @@ -1170,7 +1170,7 @@ bool SwCombinedPortion::Format( SwTextFormatInfo &rInf ) { rInf.GetOut()->SetFont( rInf.GetFont()->GetFnt( m_aScrType[i] ) ); m_aWidth[ m_aScrType[i] ] = - static_cast<sal_uInt16>(2 * rInf.GetOut()->GetFontMetric().GetFontSize().Width() / 3); + o3tl::narrowing<sal_uInt16>(2 * rInf.GetOut()->GetFontMetric().GetFontSize().Width() / 3); } } } @@ -1217,7 +1217,7 @@ bool SwCombinedPortion::Format( SwTextFormatInfo &rInf ) SwDrawTextInfo aDrawInf(pSh, *rInf.GetOut(), m_aExpand, i, 1); Size aSize = aTmpFont.GetTextSize_( aDrawInf ); const sal_uInt16 nAsc = aTmpFont.GetAscent( pSh, *rInf.GetOut() ); - m_aPos[ i ] = static_cast<sal_uInt16>(aSize.Width()); + m_aPos[ i ] = o3tl::narrowing<sal_uInt16>(aSize.Width()); if( i == nTop ) // enter the second line { m_nLowPos = nMaxDescent; @@ -1232,7 +1232,7 @@ bool SwCombinedPortion::Format( SwTextFormatInfo &rInf ) if( nAsc > nMaxAscent ) nMaxAscent = nAsc; if( aSize.Height() - nAsc > nMaxDescent ) - nMaxDescent = static_cast<sal_uInt16>(aSize.Height() - nAsc); + nMaxDescent = o3tl::narrowing<sal_uInt16>(aSize.Height() - nAsc); } // for one or two characters we double the width of the portion if( nCount < 3 ) @@ -1295,7 +1295,7 @@ bool SwCombinedPortion::Format( SwTextFormatInfo &rInf ) { if( rInf.GetLineStart() == rInf.GetIdx() && (!rInf.GetLast()->InFieldGrp() || !static_cast<SwFieldPortion*>(rInf.GetLast())->IsFollow() ) ) - Width( static_cast<sal_uInt16>( rInf.Width() - rInf.X() ) ); + Width( o3tl::narrowing<sal_uInt16>( rInf.Width() - rInf.X() ) ); else { Truncate(); |