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 <tools/solar.h>
23 #include <basegfx/polygon/b2dpolypolygon.hxx>
24 #include <svx/svxdllapi.h>
33 /************************************************************************/
35 #define XPOLYPOLY_APPEND 0xFFFF
36 #define XPOLY_APPEND 0xFFFF
38 #define XPOLY_MAXPOINTS 0xFFF0 /* Auch fuer die 32-Bitter etwas Luft lassen */
40 /************************************************************************/
41 // Punktstile im XPolygon:
42 // NORMAL : Anfangs- oder Endpunkt einer Kurve oder Linie
43 // SMOOTH : Glatter Uebergang zwischen Kurven
44 // SYMMTR : glatter und symmetrischer Uebergang zwischen Kurven
45 // CONTROL: Kontrollpunkt einer Bezierkurve
47 enum XPolyFlags
{ XPOLY_NORMAL
, XPOLY_SMOOTH
, XPOLY_CONTROL
, XPOLY_SYMMTR
};
50 /*************************************************************************
52 |* Klasse XPolygon; hat neben dem Point-Array noch ein Array mit Flags,
53 |* die Informationen ueber den jeweiligen Punkt enthalten
55 \************************************************************************/
59 class SVX_DLLPUBLIC XPolygon
62 ImpXPolygon
* pImpXPolygon
;
64 // ImpXPolygon-ReferenceCount pruefen und ggf. abkoppeln
65 void CheckReference();
67 // Hilfsfunktionen fuer Bezierkonvertierung
68 void SubdivideBezier(sal_uInt16 nPos
, sal_Bool bCalcFirst
, double fT
);
69 void GenBezArc(const Point
& rCenter
, long nRx
, long nRy
,
70 long nXHdl
, long nYHdl
, sal_uInt16 nStart
, sal_uInt16 nEnd
,
71 sal_uInt16 nQuad
, sal_uInt16 nFirst
);
72 sal_Bool
CheckAngles(sal_uInt16
& nStart
, sal_uInt16 nEnd
, sal_uInt16
& nA1
, sal_uInt16
& nA2
);
75 XPolygon( sal_uInt16 nSize
=16, sal_uInt16 nResize
=16 );
76 XPolygon( const XPolygon
& rXPoly
);
77 XPolygon( const Polygon
& rPoly
);
78 XPolygon( const Rectangle
& rRect
, long nRx
= 0, long nRy
= 0 );
79 XPolygon( const Point
& rCenter
, long nRx
, long nRy
,
80 sal_uInt16 nStartAngle
= 0, sal_uInt16 nEndAngle
= 3600,
81 sal_Bool bClose
= sal_True
);
85 sal_uInt16
GetSize() const;
87 void SetPointCount( sal_uInt16 nPoints
);
88 sal_uInt16
GetPointCount() const;
90 void Insert( sal_uInt16 nPos
, const Point
& rPt
, XPolyFlags eFlags
);
91 void Insert( sal_uInt16 nPos
, const XPolygon
& rXPoly
);
92 void Remove( sal_uInt16 nPos
, sal_uInt16 nCount
);
93 void Move( long nHorzMove
, long nVertMove
);
94 Rectangle
GetBoundRect() const;
96 const Point
& operator[]( sal_uInt16 nPos
) const;
97 Point
& operator[]( sal_uInt16 nPos
);
98 XPolygon
& operator=( const XPolygon
& rXPoly
);
99 sal_Bool
operator==( const XPolygon
& rXPoly
) const;
100 sal_Bool
operator!=( const XPolygon
& rXPoly
) const;
102 XPolyFlags
GetFlags( sal_uInt16 nPos
) const;
103 void SetFlags( sal_uInt16 nPos
, XPolyFlags eFlags
);
104 sal_Bool
IsControl(sal_uInt16 nPos
) const;
105 sal_Bool
IsSmooth(sal_uInt16 nPos
) const;
107 // Abstand zwischen zwei Punkten
108 double CalcDistance(sal_uInt16 nP1
, sal_uInt16 nP2
);
110 // Bezierkonvertierungen
111 void CalcSmoothJoin(sal_uInt16 nCenter
, sal_uInt16 nDrag
, sal_uInt16 nPnt
);
112 void CalcTangent(sal_uInt16 nCenter
, sal_uInt16 nPrev
, sal_uInt16 nNext
);
113 void PointsToBezier(sal_uInt16 nFirst
);
116 void Translate(const Point
& rTrans
);
117 void Scale(double fSx
, double fSy
);
118 void Distort(const Rectangle
& rRefRect
, const XPolygon
& rDistortedRect
);
120 // #116512# convert to basegfx::B2DPolygon and return
121 basegfx::B2DPolygon
getB2DPolygon() const;
123 // #116512# constructor to convert from basegfx::B2DPolygon
124 // #i76339# made explicit
125 explicit XPolygon(const basegfx::B2DPolygon
& rPolygon
);
128 /*************************************************************************
130 |* Klasse XPolyPolygon; wie PolyPolygon, nur statt aus Polygonen aus
131 |* XPolygonen bestehend
133 \************************************************************************/
135 class ImpXPolyPolygon
;
137 class SVX_DLLPUBLIC XPolyPolygon
140 ImpXPolyPolygon
* pImpXPolyPolygon
;
142 // ImpXPolyPolygon-ReferenceCount pruefen und ggf. abkoppeln
143 void CheckReference();
146 XPolyPolygon( sal_uInt16 nInitSize
= 16, sal_uInt16 nResize
= 16 );
147 XPolyPolygon( const XPolyPolygon
& rXPolyPoly
);
151 void Insert( const XPolygon
& rXPoly
,
152 sal_uInt16 nPos
= XPOLYPOLY_APPEND
);
153 void Insert( const XPolyPolygon
& rXPoly
,
154 sal_uInt16 nPos
=XPOLYPOLY_APPEND
);
155 XPolygon
Remove( sal_uInt16 nPos
);
156 const XPolygon
& GetObject( sal_uInt16 nPos
) const;
159 sal_uInt16
Count() const;
161 Rectangle
GetBoundRect() const;
163 const XPolygon
& operator[]( sal_uInt16 nPos
) const
164 { return GetObject( nPos
); }
165 XPolygon
& operator[]( sal_uInt16 nPos
);
167 XPolyPolygon
& operator=( const XPolyPolygon
& rXPolyPoly
);
168 sal_Bool
operator==( const XPolyPolygon
& rXPolyPoly
) const;
169 sal_Bool
operator!=( const XPolyPolygon
& rXPolyPoly
) const;
172 void Distort(const Rectangle
& rRefRect
, const XPolygon
& rDistortedRect
);
174 // #116512# convert to basegfx::B2DPolyPolygon and return
175 basegfx::B2DPolyPolygon
getB2DPolyPolygon() const;
177 // #116512# constructor to convert from basegfx::B2DPolyPolygon
178 // #i76339# made explicit
179 explicit XPolyPolygon(const basegfx::B2DPolyPolygon
& rPolyPolygon
);
182 #endif // INCLUDED_SVX_XPOLY_HXX
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */