diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-10-28 09:27:29 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-10-29 12:38:51 +0200 |
commit | 894b4911ffb96ff667fdeb3aec7922316ab7230a (patch) | |
tree | 3942ed8088c058b70bb79984b186c5156284abf4 /cppcanvas | |
parent | 5b0ae3b59cd2cccfb72d991657366eb2a69bff49 (diff) |
pass DX array around using o3tl::span instead of pointer
so we get bounds checking in debug mode
Note that I cannot just pass around the std::vectors
involved because there is a place in editeng which
calls with a subset of a vector.
Change-Id: I5088a139593c27bf9cbe5d843ab4b0048ac6d508
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124330
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'cppcanvas')
-rw-r--r-- | cppcanvas/source/inc/implrenderer.hxx | 2 | ||||
-rw-r--r-- | cppcanvas/source/mtfrenderer/implrenderer.cxx | 16 | ||||
-rw-r--r-- | cppcanvas/source/mtfrenderer/textaction.cxx | 15 | ||||
-rw-r--r-- | cppcanvas/source/mtfrenderer/textaction.hxx | 2 |
4 files changed, 18 insertions, 17 deletions
diff --git a/cppcanvas/source/inc/implrenderer.hxx b/cppcanvas/source/inc/implrenderer.hxx index 93b68f9410ad..2a77639e4ae8 100644 --- a/cppcanvas/source/inc/implrenderer.hxx +++ b/cppcanvas/source/inc/implrenderer.hxx @@ -192,7 +192,7 @@ namespace cppcanvas::internal const OUString& rString, int nIndex, int nLength, - const tools::Long* pCharWidths, + o3tl::span<const tools::Long> pCharWidths, const ActionFactoryParameters& rParms, bool bSubsettable ); diff --git a/cppcanvas/source/mtfrenderer/implrenderer.cxx b/cppcanvas/source/mtfrenderer/implrenderer.cxx index 308e4be259dc..8c530c193cb4 100644 --- a/cppcanvas/source/mtfrenderer/implrenderer.cxx +++ b/cppcanvas/source/mtfrenderer/implrenderer.cxx @@ -858,7 +858,7 @@ namespace cppcanvas::internal const OUString& rString, int nIndex, int nLength, - const ::tools::Long* pCharWidths, + o3tl::span<const ::tools::Long> pCharWidths, const ActionFactoryParameters& rParms, bool bSubsettableActions ) { @@ -996,16 +996,16 @@ namespace cppcanvas::internal { ::tools::Long nInterval = ( nWidth - nStrikeoutWidth * nLen ) / nLen; nStrikeoutWidth += nInterval; - ::tools::Long* pStrikeoutCharWidths = new ::tools::Long[nLen]; + std::vector<::tools::Long> aStrikeoutCharWidths(nLen); for ( int i = 0;i<nLen; i++) { - pStrikeoutCharWidths[i] = nStrikeoutWidth; + aStrikeoutCharWidths[i] = nStrikeoutWidth; } for ( int i = 1;i< nLen; i++ ) { - pStrikeoutCharWidths[ i ] += pStrikeoutCharWidths[ i-1 ]; + aStrikeoutCharWidths[ i ] += aStrikeoutCharWidths[ i-1 ]; } pStrikeoutTextAction = @@ -1019,7 +1019,7 @@ namespace cppcanvas::internal aStrikeoutText.makeStringAndClear(), 0/*nStartPos*/, nLen, - pStrikeoutCharWidths, + { aStrikeoutCharWidths.data(), aStrikeoutCharWidths.size() }, rParms.mrVDev, rParms.mrCanvas, rState, @@ -2464,7 +2464,7 @@ namespace cppcanvas::internal sText, pAct->GetIndex(), nLen, - nullptr, + {}, rFactoryParms, bSubsettableActions ); } @@ -2485,7 +2485,7 @@ namespace cppcanvas::internal sText, pAct->GetIndex(), nLen, - pAct->GetDXArray(), + { pAct->GetDXArray().data(), pAct->GetDXArray().size() }, rFactoryParms, bSubsettableActions ); } @@ -2593,7 +2593,7 @@ namespace cppcanvas::internal sText, pAct->GetIndex(), nLen, - aDXArray.data(), + { aDXArray.data(), aDXArray.size() }, rFactoryParms, bSubsettableActions ); } diff --git a/cppcanvas/source/mtfrenderer/textaction.cxx b/cppcanvas/source/mtfrenderer/textaction.cxx index 6af8984534e0..735bcb685555 100644 --- a/cppcanvas/source/mtfrenderer/textaction.cxx +++ b/cppcanvas/source/mtfrenderer/textaction.cxx @@ -157,7 +157,7 @@ namespace cppcanvas::internal rLayoutWidth = *(std::max_element(rOffsets.begin(), rOffsets.end())); } - uno::Sequence< double > setupDXArray( const ::tools::Long* pCharWidths, + uno::Sequence< double > setupDXArray( o3tl::span<const ::tools::Long> rCharWidths, sal_Int32 nLen, const OutDevState& rState ) { @@ -169,6 +169,7 @@ namespace cppcanvas::internal // array, by circumventing integer-based // OutDev-mapping const double nScale( rState.mapModeTransform.get(0,0) ); + ::tools::Long const * pCharWidths = rCharWidths.data(); for( int i = 0; i < nLen; ++i ) { // TODO(F2): use correct scale direction @@ -190,7 +191,7 @@ namespace cppcanvas::internal rVDev.GetTextArray( rText, &aCharWidths, nStartPos, nLen ); - return setupDXArray( aCharWidths.data(), nLen, rState ); + return setupDXArray( { aCharWidths.data(), aCharWidths.size() }, nLen, rState ); } ::basegfx::B2DPoint adaptStartPoint( const ::basegfx::B2DPoint& rStartPoint, @@ -1965,7 +1966,7 @@ namespace cppcanvas::internal const OUString& rText, sal_Int32 nStartPos, sal_Int32 nLen, - const ::tools::Long* pDXArray, + o3tl::span<const ::tools::Long> pDXArray, VirtualDevice& rVDev, const CanvasSharedPtr& rCanvas, const OutDevState& rState, @@ -2038,7 +2039,7 @@ namespace cppcanvas::internal } const uno::Sequence< double > aCharWidthSeq( - pDXArray ? + !pDXArray.empty() ? setupDXArray( pDXArray, nLen, rState ) : setupDXArray( rText, nStartPos, @@ -2095,7 +2096,7 @@ namespace cppcanvas::internal const OUString& rText, sal_Int32 nStartPos, sal_Int32 nLen, - const ::tools::Long* pDXArray, + o3tl::span<const ::tools::Long> pDXArray, VirtualDevice& rVDev, const CanvasSharedPtr& rCanvas, const OutDevState& rState, @@ -2137,7 +2138,7 @@ namespace cppcanvas::internal // convert DX array to device coordinate system (and // create it in the first place, if pDXArray is NULL) const uno::Sequence< double > aCharWidths( - pDXArray ? + !pDXArray.empty() ? setupDXArray( pDXArray, nLen, rState ) : setupDXArray( rText, nStartPos, @@ -2154,7 +2155,7 @@ namespace cppcanvas::internal // no DX array, and no need to subset - no need to store // DX array, then. - if( !pDXArray && !bSubsettable ) + if( pDXArray.empty() && !bSubsettable ) { // effects, or not? if( !rState.textOverlineStyle && diff --git a/cppcanvas/source/mtfrenderer/textaction.hxx b/cppcanvas/source/mtfrenderer/textaction.hxx index aabad2245727..4cbdd46284bf 100644 --- a/cppcanvas/source/mtfrenderer/textaction.hxx +++ b/cppcanvas/source/mtfrenderer/textaction.hxx @@ -67,7 +67,7 @@ namespace cppcanvas::internal const OUString& rText, sal_Int32 nStartPos, sal_Int32 nLen, - const ::tools::Long* pDXArray, + o3tl::span<const ::tools::Long> pDXArray, VirtualDevice& rVDev, const CanvasSharedPtr& rCanvas, const OutDevState& rState, |