From 894b4911ffb96ff667fdeb3aec7922316ab7230a Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 28 Oct 2021 09:27:29 +0200 Subject: 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 --- include/editeng/editeng.hxx | 3 ++- include/editeng/outliner.hxx | 6 +++--- include/editeng/svxfont.hxx | 3 ++- include/o3tl/span.hxx | 5 +++++ include/vcl/metaact.hxx | 13 ++++++++----- include/vcl/outdev.hxx | 11 ++++++----- include/vcl/pdfwriter.hxx | 2 +- 7 files changed, 27 insertions(+), 16 deletions(-) (limited to 'include') diff --git a/include/editeng/editeng.hxx b/include/editeng/editeng.hxx index db50eb2ac5ec..3006e178783c 100644 --- a/include/editeng/editeng.hxx +++ b/include/editeng/editeng.hxx @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -497,7 +498,7 @@ public: virtual void DrawingText( const Point& rStartPos, const OUString& rText, sal_Int32 nTextStart, sal_Int32 nTextLen, - const tools::Long* pDXArray, const SvxFont& rFont, + o3tl::span pDXArray, const SvxFont& rFont, sal_Int32 nPara, sal_uInt8 nRightToLeft, const EEngineData::WrongSpellVector* pWrongSpellVector, const SvxFieldData* pFieldData, diff --git a/include/editeng/outliner.hxx b/include/editeng/outliner.hxx index 5003a671d35e..98fc4ff41667 100644 --- a/include/editeng/outliner.hxx +++ b/include/editeng/outliner.hxx @@ -395,7 +395,7 @@ public: sal_Int32 mnTextLen; sal_Int32 mnPara; const SvxFont& mrFont; - const tools::Long* mpDXArray; + o3tl::span mpDXArray; const EEngineData::WrongSpellVector* mpWrongSpellVector; const SvxFieldData* mpFieldData; @@ -421,7 +421,7 @@ public: sal_Int32 nTxtLen, const SvxFont& rFnt, sal_Int32 nPar, - const tools::Long* pDXArr, + o3tl::span pDXArr, const EEngineData::WrongSpellVector* pWrongSpellVector, const SvxFieldData* pFieldData, const css::lang::Locale* pLocale, @@ -813,7 +813,7 @@ public: void DrawingText( const Point& rStartPos, const OUString& rText, sal_Int32 nTextStart, sal_Int32 nTextLen, - const tools::Long* pDXArray, const SvxFont& rFont, + o3tl::span pDXArray, const SvxFont& rFont, sal_Int32 nPara, sal_uInt8 nRightToLeft, const EEngineData::WrongSpellVector* pWrongSpellVector, const SvxFieldData* pFieldData, diff --git a/include/editeng/svxfont.hxx b/include/editeng/svxfont.hxx index fb0b8dbc97de..eabffc4f6301 100644 --- a/include/editeng/svxfont.hxx +++ b/include/editeng/svxfont.hxx @@ -20,6 +20,7 @@ #define INCLUDED_EDITENG_SVXFONT_HXX #include +#include #include #include #include @@ -95,7 +96,7 @@ public: const sal_Int32 nIdx = 0, const sal_Int32 nLen = SAL_MAX_INT32) const; void QuickDrawText( OutputDevice *pOut, const Point &rPos, const OUString &rTxt, - const sal_Int32 nIdx = 0, const sal_Int32 nLen = SAL_MAX_INT32, const tools::Long* pDXArray = nullptr ) const; + const sal_Int32 nIdx = 0, const sal_Int32 nLen = SAL_MAX_INT32, o3tl::span pDXArray = {} ) const; Size QuickGetTextSize( const OutputDevice *pOut, const OUString &rTxt, const sal_Int32 nIdx, const sal_Int32 nLen, std::vector* pDXArray = nullptr ) const; diff --git a/include/o3tl/span.hxx b/include/o3tl/span.hxx index 8af8ba846b65..087d1f9d69c3 100644 --- a/include/o3tl/span.hxx +++ b/include/o3tl/span.hxx @@ -25,6 +25,7 @@ namespace o3tl { using std::span; } #include #include #include +#include namespace o3tl { @@ -57,6 +58,10 @@ public: assert(a != nullptr || len == 0); } + /** for assigning from span to span */ + constexpr span (const span::type>& other) noexcept + : data_(other.data()), size_(other.size()) {} + constexpr bool empty() const noexcept { return size_ == 0; } constexpr iterator begin() const noexcept { return data_; } diff --git a/include/vcl/metaact.hxx b/include/vcl/metaact.hxx index ed74de84d5cd..43251d0facc2 100644 --- a/include/vcl/metaact.hxx +++ b/include/vcl/metaact.hxx @@ -24,6 +24,7 @@ #include +#include #include #include #include @@ -505,8 +506,7 @@ private: Point maStartPt; OUString maStr; - std::unique_ptr - mpDXAry; + std::vector<::tools::Long> maDXAry; sal_Int32 mnIndex; sal_Int32 mnLen; @@ -516,7 +516,10 @@ public: MetaTextArrayAction(); MetaTextArrayAction( const MetaTextArrayAction& rAction ); MetaTextArrayAction( const Point& rStartPt, const OUString& rStr, - const tools::Long* pDXAry, sal_Int32 nIndex, + const std::vector& rDXAry, sal_Int32 nIndex, + sal_Int32 nLen ); + MetaTextArrayAction( const Point& rStartPt, const OUString& rStr, + o3tl::span pDXAry, sal_Int32 nIndex, sal_Int32 nLen ); virtual void Execute( OutputDevice* pOut ) override; @@ -530,12 +533,12 @@ public: const OUString& GetText() const { return maStr; } sal_Int32 GetIndex() const { return mnIndex; } sal_Int32 GetLen() const { return mnLen; } - tools::Long* GetDXArray() const { return mpDXAry.get(); } + const std::vector & GetDXArray() const { return maDXAry; } void SetPoint(const Point& rPt) { maStartPt = rPt; } void SetText(const OUString& rStr) { maStr = rStr; } void SetIndex(sal_Int32 rIndex) { mnIndex = rIndex; } void SetLen(sal_Int32 rLen) { mnLen = rLen; } - void SetDXArray(std::unique_ptr aArray); + void SetDXArray(std::vector aArray); }; class SAL_DLLPUBLIC_RTTI MetaStretchTextAction final : public MetaAction diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx index ed9e38f9fdbd..0075015dee28 100644 --- a/include/vcl/outdev.hxx +++ b/include/vcl/outdev.hxx @@ -21,6 +21,7 @@ #include +#include #include #include #include @@ -969,7 +970,7 @@ public: */ bool GetTextBoundRect( tools::Rectangle& rRect, const OUString& rStr, sal_Int32 nBase = 0, sal_Int32 nIndex = 0, sal_Int32 nLen = -1, - sal_uLong nLayoutWidth = 0, const tools::Long* pDXArray = nullptr, + sal_uLong nLayoutWidth = 0, o3tl::span pDXArray = {}, const SalLayoutGlyphs* pGlyphs = nullptr ) const; tools::Rectangle ImplGetTextBoundRect( const SalLayout& ) const; @@ -980,12 +981,12 @@ public: bool GetTextOutlines( PolyPolyVector&, const OUString& rStr, sal_Int32 nBase = 0, sal_Int32 nIndex = 0, sal_Int32 nLen = -1, - sal_uLong nLayoutWidth = 0, const tools::Long* pDXArray = nullptr ) const; + sal_uLong nLayoutWidth = 0, o3tl::span pDXArray = {} ) const; bool GetTextOutlines( basegfx::B2DPolyPolygonVector &rVector, const OUString& rStr, sal_Int32 nBase, sal_Int32 nIndex = 0, sal_Int32 nLen = -1, - sal_uLong nLayoutWidth = 0, const tools::Long* pDXArray = nullptr ) const; + sal_uLong nLayoutWidth = 0, o3tl::span pDXArray = {} ) const; OUString GetEllipsisString( const OUString& rStr, tools::Long nMaxWidth, @@ -1050,7 +1051,7 @@ public: float approximate_digit_width() const; void DrawTextArray( const Point& rStartPt, const OUString& rStr, - const tools::Long* pDXAry, + o3tl::span pDXAry, sal_Int32 nIndex = 0, sal_Int32 nLen = -1, SalLayoutFlags flags = SalLayoutFlags::NONE, @@ -1236,7 +1237,7 @@ public: std::unique_ptr ImplLayout( const OUString&, sal_Int32 nIndex, sal_Int32 nLen, const Point& rLogicPos = Point(0,0), tools::Long nLogicWidth=0, - const tools::Long* pLogicDXArray=nullptr, SalLayoutFlags flags = SalLayoutFlags::NONE, + o3tl::span pLogicDXArray={}, SalLayoutFlags flags = SalLayoutFlags::NONE, vcl::text::TextLayoutCache const* = nullptr, const SalLayoutGlyphs* pGlyphs = nullptr) const; SAL_DLLPRIVATE vcl::text::ImplLayoutArgs ImplPrepareLayoutArgs( OUString&, const sal_Int32 nIndex, const sal_Int32 nLen, diff --git a/include/vcl/pdfwriter.hxx b/include/vcl/pdfwriter.hxx index 3601c88501f9..5a566937e373 100644 --- a/include/vcl/pdfwriter.hxx +++ b/include/vcl/pdfwriter.hxx @@ -746,7 +746,7 @@ The following structure describes the permissions used in PDF security FontLineStyle eUnderline, FontLineStyle eOverline ); void DrawTextArray( const Point& rStartPt, const OUString& rStr, - const tools::Long* pDXAry, + o3tl::span pDXAry, sal_Int32 nIndex, sal_Int32 nLen ); void DrawStretchText( const Point& rStartPt, sal_uLong nWidth, -- cgit