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>
29 namespace tools
{ class PolyPolygon
; }
32 #define XPOLYPOLY_APPEND 0xFFFF
33 #define XPOLY_APPEND 0xFFFF
36 // point-styles in XPolygon:
37 // NORMAL : start-/endpoint of a curve or a line
38 // SMOOTH : smooth transition between curves
39 // SYMMTR : smooth and symmetrical transition between curves
40 // CONTROL: control handles of a Bezier curve
42 enum XPolyFlags
{ XPOLY_NORMAL
, XPOLY_SMOOTH
, XPOLY_CONTROL
, XPOLY_SYMMTR
};
44 // Class XPolygon;has a point-array and a flag-array, which contains information about a particular point
48 class SVX_DLLPUBLIC XPolygon
51 ImpXPolygon
* pImpXPolygon
;
53 // check ImpXPolygon-ReferenceCount and decouple if necessary
54 void CheckReference();
56 // auxiliary functions for Bezier conversion
57 void SubdivideBezier(sal_uInt16 nPos
, bool bCalcFirst
, double fT
);
58 void GenBezArc(const Point
& rCenter
, long nRx
, long nRy
,
59 long nXHdl
, long nYHdl
, sal_uInt16 nStart
, sal_uInt16 nEnd
,
60 sal_uInt16 nQuad
, sal_uInt16 nFirst
);
61 static bool CheckAngles(sal_uInt16
& nStart
, sal_uInt16 nEnd
, sal_uInt16
& nA1
, sal_uInt16
& nA2
);
64 XPolygon( sal_uInt16 nSize
=16, sal_uInt16 nResize
=16 );
65 XPolygon( const XPolygon
& rXPoly
);
66 XPolygon( const Polygon
& rPoly
);
67 XPolygon( const Rectangle
& rRect
, long nRx
= 0, long nRy
= 0 );
68 XPolygon( const Point
& rCenter
, long nRx
, long nRy
,
69 sal_uInt16 nStartAngle
= 0, sal_uInt16 nEndAngle
= 3600,
74 sal_uInt16
GetSize() const;
76 void SetPointCount( sal_uInt16 nPoints
);
77 sal_uInt16
GetPointCount() const;
79 void Insert( sal_uInt16 nPos
, const Point
& rPt
, XPolyFlags eFlags
);
80 void Insert( sal_uInt16 nPos
, const XPolygon
& rXPoly
);
81 void Remove( sal_uInt16 nPos
, sal_uInt16 nCount
);
82 void Move( long nHorzMove
, long nVertMove
);
83 Rectangle
GetBoundRect() const;
85 const Point
& operator[]( sal_uInt16 nPos
) const;
86 Point
& operator[]( sal_uInt16 nPos
);
87 XPolygon
& operator=( const XPolygon
& rXPoly
);
88 bool operator==( const XPolygon
& rXPoly
) const;
89 bool operator!=( const XPolygon
& rXPoly
) const;
91 XPolyFlags
GetFlags( sal_uInt16 nPos
) const;
92 void SetFlags( sal_uInt16 nPos
, XPolyFlags eFlags
);
93 bool IsControl(sal_uInt16 nPos
) const;
94 bool IsSmooth(sal_uInt16 nPos
) const;
96 // distance between two points
97 double CalcDistance(sal_uInt16 nP1
, sal_uInt16 nP2
);
100 void CalcSmoothJoin(sal_uInt16 nCenter
, sal_uInt16 nDrag
, sal_uInt16 nPnt
);
101 void CalcTangent(sal_uInt16 nCenter
, sal_uInt16 nPrev
, sal_uInt16 nNext
);
102 void PointsToBezier(sal_uInt16 nFirst
);
105 void Translate(const Point
& rTrans
);
106 void Scale(double fSx
, double fSy
);
107 void Distort(const Rectangle
& rRefRect
, const XPolygon
& rDistortedRect
);
109 // #116512# convert to basegfx::B2DPolygon and return
110 basegfx::B2DPolygon
getB2DPolygon() const;
112 // #116512# constructor to convert from basegfx::B2DPolygon
113 // #i76339# made explicit
114 explicit XPolygon(const basegfx::B2DPolygon
& rPolygon
);
117 // Class XPolyPolygon; like PolyPolygon, composed of XPolygons instead of Polygons
119 class ImpXPolyPolygon
;
121 class SVX_DLLPUBLIC XPolyPolygon
124 ImpXPolyPolygon
* pImpXPolyPolygon
;
126 // check ImpXPolyPolygon-ReferenceCount and decouple if necessary
127 void CheckReference();
130 XPolyPolygon( sal_uInt16 nInitSize
= 16, sal_uInt16 nResize
= 16 );
131 XPolyPolygon( const XPolyPolygon
& rXPolyPoly
);
135 void Insert( const XPolygon
& rXPoly
,
136 sal_uInt16 nPos
= XPOLYPOLY_APPEND
);
137 void Insert( const XPolyPolygon
& rXPoly
,
138 sal_uInt16 nPos
=XPOLYPOLY_APPEND
);
139 XPolygon
Remove( sal_uInt16 nPos
);
140 const XPolygon
& GetObject( sal_uInt16 nPos
) const;
143 sal_uInt16
Count() const;
145 Rectangle
GetBoundRect() const;
147 const XPolygon
& operator[]( sal_uInt16 nPos
) const
148 { return GetObject( nPos
); }
149 XPolygon
& operator[]( sal_uInt16 nPos
);
151 XPolyPolygon
& operator=( const XPolyPolygon
& rXPolyPoly
);
152 bool operator==( const XPolyPolygon
& rXPolyPoly
) const;
153 bool operator!=( const XPolyPolygon
& rXPolyPoly
) const;
156 void Distort(const Rectangle
& rRefRect
, const XPolygon
& rDistortedRect
);
158 // #116512# convert to basegfx::B2DPolyPolygon and return
159 basegfx::B2DPolyPolygon
getB2DPolyPolygon() const;
161 // #116512# constructor to convert from basegfx::B2DPolyPolygon
162 // #i76339# made explicit
163 explicit XPolyPolygon(const basegfx::B2DPolyPolygon
& rPolyPolygon
);
166 #endif // INCLUDED_SVX_XPOLY_HXX
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */