summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2021-10-28 09:27:29 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-10-29 12:38:51 +0200
commit894b4911ffb96ff667fdeb3aec7922316ab7230a (patch)
tree3942ed8088c058b70bb79984b186c5156284abf4 /include
parent5b0ae3b59cd2cccfb72d991657366eb2a69bff49 (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 'include')
-rw-r--r--include/editeng/editeng.hxx3
-rw-r--r--include/editeng/outliner.hxx6
-rw-r--r--include/editeng/svxfont.hxx3
-rw-r--r--include/o3tl/span.hxx5
-rw-r--r--include/vcl/metaact.hxx13
-rw-r--r--include/vcl/outdev.hxx11
-rw-r--r--include/vcl/pdfwriter.hxx2
7 files changed, 27 insertions, 16 deletions
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 <com/sun/star/i18n/WordType.hpp>
#include <com/sun/star/i18n/CharacterIteratorMode.hpp>
+#include <o3tl/span.hxx>
#include <svl/typedwhich.hxx>
#include <editeng/editdata.hxx>
#include <editeng/editstat.hxx>
@@ -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<const tools::Long> 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<const tools::Long> 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<const tools::Long> 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<const tools::Long> 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 <editeng/svxenum.hxx>
+#include <o3tl/span.hxx>
#include <tools/long.hxx>
#include <vcl/font.hxx>
#include <editeng/editengdllapi.h>
@@ -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<const tools::Long> pDXArray = {} ) const;
Size QuickGetTextSize( const OutputDevice *pOut, const OUString &rTxt,
const sal_Int32 nIdx, const sal_Int32 nLen, std::vector<tools::Long>* 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 <cassert>
#include <cstddef>
#include <iterator>
+#include <type_traits>
namespace o3tl {
@@ -57,6 +58,10 @@ public:
assert(a != nullptr || len == 0);
}
+ /** for assigning from span<T> to span<const T> */
+ constexpr span (const span<typename std::remove_const<T>::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 <config_options.h>
+#include <o3tl/span.hxx>
#include <rtl/ref.hxx>
#include <salhelper/simplereferenceobject.hxx>
#include <tools/poly.hxx>
@@ -505,8 +506,7 @@ private:
Point maStartPt;
OUString maStr;
- std::unique_ptr<tools::Long[]>
- 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<tools::Long>& rDXAry, sal_Int32 nIndex,
+ sal_Int32 nLen );
+ MetaTextArrayAction( const Point& rStartPt, const OUString& rStr,
+ o3tl::span<const tools::Long> 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<tools::Long> & 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<tools::Long[]> aArray);
+ void SetDXArray(std::vector<tools::Long> 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 <sal/config.h>
+#include <o3tl/span.hxx>
#include <tools/gen.hxx>
#include <tools/ref.hxx>
#include <tools/solar.h>
@@ -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<const tools::Long> 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<const tools::Long> 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<const tools::Long> 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<const tools::Long> pDXAry,
sal_Int32 nIndex = 0,
sal_Int32 nLen = -1,
SalLayoutFlags flags = SalLayoutFlags::NONE,
@@ -1236,7 +1237,7 @@ public:
std::unique_ptr<SalLayout>
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<const tools::Long> 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<const tools::Long> pDXAry,
sal_Int32 nIndex,
sal_Int32 nLen );
void DrawStretchText( const Point& rStartPt, sal_uLong nWidth,