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>
28 namespace tools
{ class Rectangle
; }
36 #define XPOLYPOLY_APPEND 0xFFFF
37 #define XPOLY_APPEND 0xFFFF
40 // Class XPolygon has a point-array and a flag-array, which contains information about a particular point
44 class SVX_DLLPUBLIC XPolygon final
46 o3tl::cow_wrapper
< ImpXPolygon
> pImpXPolygon
;
48 // auxiliary functions for Bezier conversion
49 void SubdivideBezier(sal_uInt16 nPos
, bool bCalcFirst
, double fT
);
50 void GenBezArc(const Point
& rCenter
, long nRx
, long nRy
,
51 long nXHdl
, long nYHdl
, sal_uInt16 nStart
, sal_uInt16 nEnd
,
52 sal_uInt16 nQuad
, sal_uInt16 nFirst
);
53 static bool CheckAngles(sal_uInt16
& nStart
, sal_uInt16 nEnd
, sal_uInt16
& nA1
, sal_uInt16
& nA2
);
56 XPolygon( sal_uInt16 nSize
=16 );
57 XPolygon( const XPolygon
& );
58 XPolygon( XPolygon
&& );
59 XPolygon( const tools::Polygon
& rPoly
);
60 XPolygon( const tools::Rectangle
& rRect
, long nRx
= 0, long nRy
= 0 );
61 XPolygon( const Point
& rCenter
, long nRx
, long nRy
,
62 sal_uInt16 nStartAngle
= 0, sal_uInt16 nEndAngle
= 3600,
67 sal_uInt16
GetSize() const;
69 void SetPointCount( sal_uInt16 nPoints
);
70 sal_uInt16
GetPointCount() const;
72 void Insert( sal_uInt16 nPos
, const Point
& rPt
, PolyFlags eFlags
);
73 void Insert( sal_uInt16 nPos
, const XPolygon
& rXPoly
);
74 void Remove( sal_uInt16 nPos
, sal_uInt16 nCount
);
75 void Move( long nHorzMove
, long nVertMove
);
76 tools::Rectangle
GetBoundRect() const;
78 const Point
& operator[]( sal_uInt16 nPos
) const;
79 Point
& operator[]( sal_uInt16 nPos
);
80 XPolygon
& operator=( const XPolygon
& );
81 XPolygon
& operator=( XPolygon
&& );
82 bool operator==( const XPolygon
& rXPoly
) const;
84 PolyFlags
GetFlags( sal_uInt16 nPos
) const;
85 void SetFlags( sal_uInt16 nPos
, PolyFlags eFlags
);
86 bool IsControl(sal_uInt16 nPos
) const;
87 bool IsSmooth(sal_uInt16 nPos
) const;
89 // distance between two points
90 double CalcDistance(sal_uInt16 nP1
, sal_uInt16 nP2
);
93 void CalcSmoothJoin(sal_uInt16 nCenter
, sal_uInt16 nDrag
, sal_uInt16 nPnt
);
94 void CalcTangent(sal_uInt16 nCenter
, sal_uInt16 nPrev
, sal_uInt16 nNext
);
95 void PointsToBezier(sal_uInt16 nFirst
);
98 void Scale(double fSx
, double fSy
);
99 void Distort(const tools::Rectangle
& rRefRect
, const XPolygon
& rDistortedRect
);
101 // #116512# convert to basegfx::B2DPolygon and return
102 basegfx::B2DPolygon
getB2DPolygon() const;
104 // #116512# constructor to convert from basegfx::B2DPolygon
105 // #i76339# made explicit
106 explicit XPolygon(const basegfx::B2DPolygon
& rPolygon
);
109 // Class XPolyPolygon; like PolyPolygon, composed of XPolygons instead of Polygons
111 class ImpXPolyPolygon
;
113 class SVX_DLLPUBLIC XPolyPolygon final
115 o3tl::cow_wrapper
< ImpXPolyPolygon
> pImpXPolyPolygon
;
119 XPolyPolygon( const XPolyPolygon
& );
120 XPolyPolygon( XPolyPolygon
&& );
124 void Insert( XPolygon
&& rXPoly
);
125 void Insert( const XPolyPolygon
& rXPoly
);
126 void Remove( sal_uInt16 nPos
);
127 const XPolygon
& GetObject( sal_uInt16 nPos
) const;
130 sal_uInt16
Count() const;
132 tools::Rectangle
GetBoundRect() const;
134 const XPolygon
& operator[]( sal_uInt16 nPos
) const
135 { return GetObject( nPos
); }
136 XPolygon
& operator[]( sal_uInt16 nPos
);
138 XPolyPolygon
& operator=( const XPolyPolygon
& );
139 XPolyPolygon
& operator=( XPolyPolygon
&& );
142 void Distort(const tools::Rectangle
& rRefRect
, const XPolygon
& rDistortedRect
);
144 // #116512# convert to basegfx::B2DPolyPolygon and return
145 basegfx::B2DPolyPolygon
getB2DPolyPolygon() const;
147 // #116512# constructor to convert from basegfx::B2DPolyPolygon
148 // #i76339# made explicit
149 explicit XPolyPolygon(const basegfx::B2DPolyPolygon
& rPolyPolygon
);
152 #endif // INCLUDED_SVX_XPOLY_HXX
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */