LibreOffice Module basegfx (master) 1
b2dpolygon.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#pragma once
21
22#include <memory>
23#include <ostream>
24#include <vector>
25
26#include <sal/types.h>
27#include <o3tl/cow_wrapper.hxx>
30
31class ImplB2DPolygon;
32
33namespace basegfx
34{
35 class B2DPoint;
36 class B2DRange;
37 class B2DHomMatrix;
38 class B2DCubicBezier;
39 class B2DVector;
40 class SystemDependentData;
41 class SystemDependentDataManager;
42 typedef std::shared_ptr<SystemDependentData> SystemDependentData_SharedPtr;
43}
44
45namespace basegfx
46{
48 {
49 public:
51
52 private:
53 // internal data.
55
56 public:
58 B2DPolygon();
59 B2DPolygon(const B2DPolygon& rPolygon);
61 B2DPolygon(const B2DPolygon& rPolygon, sal_uInt32 nIndex, sal_uInt32 nCount);
62 B2DPolygon(std::initializer_list<basegfx::B2DPoint> rPoints);
63
65
67 B2DPolygon& operator=(const B2DPolygon& rPolygon);
69
71 void makeUnique();
72
74 bool operator==(const B2DPolygon& rPolygon) const;
75 bool operator!=(const B2DPolygon& rPolygon) const;
76
78 sal_uInt32 count() const;
79
81 basegfx::B2DPoint const & getB2DPoint(sal_uInt32 nIndex) const;
82 void setB2DPoint(sal_uInt32 nIndex, const basegfx::B2DPoint& rValue);
83
85 void insert(sal_uInt32 nIndex, const basegfx::B2DPoint& rPoint, sal_uInt32 nCount = 1);
86 void append(const basegfx::B2DPoint& rPoint, sal_uInt32 nCount);
87 void append(const basegfx::B2DPoint& rPoint);
88 void reserve(sal_uInt32 nCount);
89
91 basegfx::B2DPoint getPrevControlPoint(sal_uInt32 nIndex) const;
92 basegfx::B2DPoint getNextControlPoint(sal_uInt32 nIndex) const;
93 void setPrevControlPoint(sal_uInt32 nIndex, const basegfx::B2DPoint& rValue);
94 void setNextControlPoint(sal_uInt32 nIndex, const basegfx::B2DPoint& rValue);
95 void setControlPoints(sal_uInt32 nIndex, const basegfx::B2DPoint& rPrev, const basegfx::B2DPoint& rNext);
96
98 void resetPrevControlPoint(sal_uInt32 nIndex);
99 void resetNextControlPoint(sal_uInt32 nIndex);
100 void resetControlPoints();
101
103 void appendBezierSegment(const basegfx::B2DPoint& rNextControlPoint,
104 const basegfx::B2DPoint& rPrevControlPoint,
105 const basegfx::B2DPoint& rPoint);
106
109 void appendQuadraticBezierSegment(const basegfx::B2DPoint& rQuadControlPoint,
110 const basegfx::B2DPoint& rPoint);
111
113 bool areControlPointsUsed() const;
114 bool isPrevControlPointUsed(sal_uInt32 nIndex) const;
115 bool isNextControlPointUsed(sal_uInt32 nIndex) const;
116 B2VectorContinuity getContinuityInPoint(sal_uInt32 nIndex) const;
117
131 void getBezierSegment(sal_uInt32 nIndex, B2DCubicBezier& rTarget) const;
132
162 B2DPolygon const & getDefaultAdaptiveSubdivision() const;
163
191 B2DRange const & getB2DRange() const;
192
208 void append(const B2DPolygon& rPoly, sal_uInt32 nIndex = 0, sal_uInt32 nCount = 0);
209
211 void remove(sal_uInt32 nIndex, sal_uInt32 nCount = 1);
212
214 void clear();
215
217 bool isClosed() const;
218 void setClosed(bool bNew);
219
221 void flip();
222
224 bool hasDoublePoints() const;
225
227 void removeDoublePoints();
228
230 void transform(const basegfx::B2DHomMatrix& rMatrix);
231
232 // exclusive management op's for SystemDependentData at B2DPolygon
233 template<class T>
234 std::shared_ptr<T> getSystemDependentData() const
235 {
236 return std::static_pointer_cast<T>(getSystemDependantDataInternal(typeid(T).hash_code()));
237 }
238
239 template<class T, class... Args>
240 std::shared_ptr<T> addOrReplaceSystemDependentData(Args&&... args) const
241 {
242 std::shared_ptr<T> r = std::make_shared<T>(std::forward<Args>(args)...);
243
244 // tdf#129845 only add to buffer if a relevant buffer time is estimated
245 if(r->calculateCombinedHoldCyclesInSeconds() > 0)
246 {
248 addOrReplaceSystemDependentDataInternal(r2);
249 }
250
251 return r;
252 }
253
254 private:
255 void addOrReplaceSystemDependentDataInternal(SystemDependentData_SharedPtr& rData) const;
256 SystemDependentData_SharedPtr getSystemDependantDataInternal(size_t hash_code) const;
257 const basegfx::B2DVector& getPrevControlVector(sal_uInt32 nIndex) const;
258 const basegfx::B2DVector& getNextControlVector(sal_uInt32 nIndex) const;
259 };
260
261 // typedef for a vector of B2DPolygons
262 typedef ::std::vector< B2DPolygon > B2DPolygonVector;
263
264 template< typename charT, typename traits >
265 inline std::basic_ostream<charT, traits> & operator <<(
266 std::basic_ostream<charT, traits> & stream, const B2DPolygon& poly )
267 {
268 stream << "<" << poly.count() << ":";
269 for (sal_uInt32 i = 0; i < poly.count(); i++)
270 {
271 if (i > 0)
272 stream << "--";
273 stream << poly.getB2DPoint(i);
274 }
275 stream << ">";
276
277 return stream;
278 }
279
280} // end of namespace basegfx
281
282/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define BASEGFX_DLLPUBLIC
Definition: basegfxdllapi.h:35
Base Point class with two double values.
Definition: b2dpoint.hxx:42
std::shared_ptr< T > getSystemDependentData() const
Definition: b2dpolygon.hxx:234
B2DPolygon(const B2DPolygon &rPolygon)
B2DPolygon & operator=(const B2DPolygon &rPolygon)
assignment operator
basegfx::B2DPoint const & getB2DPoint(sal_uInt32 nIndex) const
Coordinate interface.
o3tl::cow_wrapper< ImplB2DPolygon > ImplType
Definition: b2dpolygon.hxx:50
std::shared_ptr< T > addOrReplaceSystemDependentData(Args &&... args) const
Definition: b2dpolygon.hxx:240
sal_uInt32 count() const
member count
B2DPolygon(B2DPolygon &&rPolygon)
B2DPolygon & operator=(B2DPolygon &&rPolygon)
A two-dimensional interval over doubles.
Definition: b2drange.hxx:54
Base Point class with two double values.
Definition: b2dvector.hxx:40
Reference< XOutputStream > stream
B2VectorContinuity getContinuityInPoint(const B2DPolygon &rCandidate, sal_uInt32 nIndex)
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &stream, BColor const &color)
Definition: bcolor.hxx:176
B2VectorContinuity
Descriptor for the mathematical continuity of two 2D Vectors.
Definition: b2enums.hxx:41
::std::vector< B2DPolygon > B2DPolygonVector
Definition: b2dpolygon.hxx:262
std::shared_ptr< SystemDependentData > SystemDependentData_SharedPtr
Definition: b2dpolygon.hxx:41
OUStringBuffer & remove(OUStringBuffer &rIn, sal_Unicode c)
int i
args
#define SAL_WARN_UNUSED
bool operator!=(const XclExpString &rLeft, const XclExpString &rRight)
bool operator==(const XclFontData &rLeft, const XclFontData &rRight)