1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SVX_XPOLY_HXX
20 #define INCLUDED_SVX_XPOLY_HXX
22 #include <basegfx/polygon/b2dpolypolygon.hxx>
23 #include <svx/svxdllapi.h>
24 #include <o3tl/cow_wrapper.hxx>
25 #include <tools/poly.hxx>
26 #include <tools/degree.hxx>
29 namespace tools
{ class Rectangle
; }
37 #define XPOLYPOLY_APPEND 0xFFFF
38 #define XPOLY_APPEND 0xFFFF
41 // Class XPolygon has a point-array and a flag-array, which contains information about a particular point
45 class SVXCORE_DLLPUBLIC XPolygon final
47 o3tl::cow_wrapper
< ImpXPolygon
> pImpXPolygon
;
49 // auxiliary functions for Bezier conversion
50 void SubdivideBezier(sal_uInt16 nPos
, bool bCalcFirst
, double fT
);
51 void GenBezArc(const Point
& rCenter
, tools::Long nRx
, tools::Long nRy
,
52 tools::Long nXHdl
, tools::Long nYHdl
, Degree100 nStart
, Degree100 nEnd
,
53 sal_uInt16 nQuad
, sal_uInt16 nFirst
);
54 static bool CheckAngles(Degree100
& nStart
, Degree100 nEnd
, Degree100
& nA1
, Degree100
& nA2
);
57 XPolygon( sal_uInt16 nSize
=16 );
58 XPolygon( const XPolygon
& );
59 XPolygon( XPolygon
&& );
60 XPolygon( const tools::Polygon
& rPoly
);
61 XPolygon( const tools::Rectangle
& rRect
, tools::Long nRx
= 0, tools::Long nRy
= 0 );
62 XPolygon( const Point
& rCenter
, tools::Long nRx
, tools::Long nRy
,
63 Degree100 nStartAngle
= 0_deg100
, Degree100 nEndAngle
= 36000_deg100
,
68 sal_uInt16
GetSize() const;
70 void SetPointCount( sal_uInt16 nPoints
);
71 sal_uInt16
GetPointCount() const;
73 void Insert( sal_uInt16 nPos
, const Point
& rPt
, PolyFlags eFlags
);
74 void Insert( sal_uInt16 nPos
, const XPolygon
& rXPoly
);
75 void Remove( sal_uInt16 nPos
, sal_uInt16 nCount
);
76 void Move( tools::Long nHorzMove
, tools::Long nVertMove
);
77 tools::Rectangle
GetBoundRect() const;
79 const Point
& operator[]( sal_uInt16 nPos
) const;
80 Point
& operator[]( sal_uInt16 nPos
);
81 XPolygon
& operator=( const XPolygon
& );
82 XPolygon
& operator=( XPolygon
&& );
83 bool operator==( const XPolygon
& rXPoly
) const;
85 PolyFlags
GetFlags( sal_uInt16 nPos
) const;
86 void SetFlags( sal_uInt16 nPos
, PolyFlags eFlags
);
87 bool IsControl(sal_uInt16 nPos
) const;
88 bool IsSmooth(sal_uInt16 nPos
) const;
90 // distance between two points
91 double CalcDistance(sal_uInt16 nP1
, sal_uInt16 nP2
);
94 void CalcSmoothJoin(sal_uInt16 nCenter
, sal_uInt16 nDrag
, sal_uInt16 nPnt
);
95 void CalcTangent(sal_uInt16 nCenter
, sal_uInt16 nPrev
, sal_uInt16 nNext
);
96 void PointsToBezier(sal_uInt16 nFirst
);
99 void Scale(double fSx
, double fSy
);
100 void Distort(const tools::Rectangle
& rRefRect
, const XPolygon
& rDistortedRect
);
102 // #116512# convert to basegfx::B2DPolygon and return
103 basegfx::B2DPolygon
getB2DPolygon() const;
105 // #116512# constructor to convert from basegfx::B2DPolygon
106 // #i76339# made explicit
107 explicit XPolygon(const basegfx::B2DPolygon
& rPolygon
);
110 // Class XPolyPolygon; like PolyPolygon, composed of XPolygons instead of Polygons
112 class ImpXPolyPolygon
;
114 class XPolyPolygon final
116 o3tl::cow_wrapper
< ImpXPolyPolygon
> pImpXPolyPolygon
;
120 XPolyPolygon( const XPolyPolygon
& );
121 XPolyPolygon( XPolyPolygon
&& );
125 void Insert( XPolygon
&& rXPoly
);
126 void Insert( const XPolyPolygon
& rXPoly
);
127 void Remove( sal_uInt16 nPos
);
128 const XPolygon
& GetObject( sal_uInt16 nPos
) const;
131 sal_uInt16
Count() const;
133 tools::Rectangle
GetBoundRect() const;
135 const XPolygon
& operator[]( sal_uInt16 nPos
) const
136 { return GetObject( nPos
); }
137 XPolygon
& operator[]( sal_uInt16 nPos
);
139 XPolyPolygon
& operator=( const XPolyPolygon
& );
140 XPolyPolygon
& operator=( XPolyPolygon
&& );
143 void Distort(const tools::Rectangle
& rRefRect
, const XPolygon
& rDistortedRect
);
145 // #116512# convert to basegfx::B2DPolyPolygon and return
146 basegfx::B2DPolyPolygon
getB2DPolyPolygon() const;
148 // #116512# constructor to convert from basegfx::B2DPolyPolygon
149 // #i76339# made explicit
150 explicit XPolyPolygon(const basegfx::B2DPolyPolygon
& rPolyPolygon
);
153 #endif // INCLUDED_SVX_XPOLY_HXX
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */