xref: /trunk/main/svx/inc/svx/xpoly.hxx (revision 914d351e5f5b84e4342a86d6ab8d4aca7308b9bd)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _XPOLY_HXX
24 #define _XPOLY_HXX
25 
26 // include ---------------------------------------------------------------
27 
28 #include <tools/solar.h>
29 #include <basegfx/polygon/b2dpolypolygon.hxx>
30 #include "svx/svxdllapi.h"
31 
32 class Point;
33 class Rectangle;
34 class SvStream;
35 class Polygon;
36 class PolyPolygon;
37 class OutputDevice;
38 
39 /************************************************************************/
40 
41 #define XPOLYPOLY_APPEND     0xFFFF
42 #define XPOLY_APPEND         0xFFFF
43 
44 #define XPOLY_MAXPOINTS      0xFFF0 /* Auch fuer die 32-Bitter etwas Luft lassen */
45 
46 /************************************************************************/
47 // Punktstile im XPolygon:
48 // NORMAL : Anfangs- oder Endpunkt einer Kurve oder Linie
49 // SMOOTH : Glatter Uebergang zwischen Kurven
50 // SYMMTR : glatter und symmetrischer Uebergang zwischen Kurven
51 // CONTROL: Kontrollpunkt einer Bezierkurve
52 
53 enum XPolyFlags { XPOLY_NORMAL, XPOLY_SMOOTH, XPOLY_CONTROL, XPOLY_SYMMTR };
54 
55 
56 /*************************************************************************
57 |*
58 |* Klasse XPolygon; hat neben dem Point-Array noch ein Array mit Flags,
59 |* die Informationen ueber den jeweiligen Punkt enthalten
60 |*
61 \************************************************************************/
62 
63 class ImpXPolygon;
64 
65 class SVX_DLLPUBLIC XPolygon
66 {
67 protected:
68     ImpXPolygon*    pImpXPolygon;
69 
70     // ImpXPolygon-ReferenceCount pruefen und ggf. abkoppeln
71     void    CheckReference();
72 
73     // Hilfsfunktionen fuer Bezierkonvertierung
74     void    SubdivideBezier(sal_uInt16 nPos, sal_Bool bCalcFirst, double fT);
75     void    GenBezArc(const Point& rCenter, long nRx, long nRy,
76                       long nXHdl, long nYHdl, sal_uInt16 nStart, sal_uInt16 nEnd,
77                       sal_uInt16 nQuad, sal_uInt16 nFirst);
78     sal_Bool    CheckAngles(sal_uInt16& nStart, sal_uInt16 nEnd, sal_uInt16& nA1, sal_uInt16& nA2);
79 
80 public:
81     XPolygon( sal_uInt16 nSize=16, sal_uInt16 nResize=16 );
82     XPolygon( const XPolygon& rXPoly );
83     XPolygon( const Polygon& rPoly );
84     XPolygon( const Rectangle& rRect, long nRx = 0, long nRy = 0 );
85     XPolygon( const Point& rCenter, long nRx, long nRy,
86               sal_uInt16 nStartAngle = 0, sal_uInt16 nEndAngle = 3600,
87               sal_Bool bClose = sal_True );
88 
89     ~XPolygon();
90 
91     void        SetSize( sal_uInt16 nSize );
92     sal_uInt16      GetSize() const;
93 
94     void        SetPointCount( sal_uInt16 nPoints );
95     sal_uInt16      GetPointCount() const;
96 
97     void        Insert( sal_uInt16 nPos, const Point& rPt, XPolyFlags eFlags );
98     void        Insert( sal_uInt16 nPos, const XPolygon& rXPoly );
99     void        Insert( sal_uInt16 nPos, const Polygon& rPoly );
100     void        Remove( sal_uInt16 nPos, sal_uInt16 nCount );
101     void        Move( long nHorzMove, long nVertMove );
102     Rectangle   GetBoundRect() const;
103 
104     const Point&    operator[]( sal_uInt16 nPos ) const;
105           Point&    operator[]( sal_uInt16 nPos );
106     XPolygon&       operator=( const XPolygon& rXPoly );
107     sal_Bool            operator==( const XPolygon& rXPoly ) const;
108     sal_Bool            operator!=( const XPolygon& rXPoly ) const;
109 
110     XPolyFlags  GetFlags( sal_uInt16 nPos ) const;
111     void        SetFlags( sal_uInt16 nPos, XPolyFlags eFlags );
112     sal_Bool        IsControl(sal_uInt16 nPos) const;
113     sal_Bool        IsSmooth(sal_uInt16 nPos) const;
114 
115     // Abstand zwischen zwei Punkten
116     double  CalcDistance(sal_uInt16 nP1, sal_uInt16 nP2);
117 
118     // Bezierkonvertierungen
119     void CalcSmoothJoin(sal_uInt16 nCenter, sal_uInt16 nDrag, sal_uInt16 nPnt);
120     void CalcTangent(sal_uInt16 nCenter, sal_uInt16 nPrev, sal_uInt16 nNext);
121     void PointsToBezier(sal_uInt16 nFirst);
122 
123     // Transformationen
124     void Translate(const Point& rTrans);
125     void Rotate(const Point& rCenter, double fSin, double fCos);
126     void Rotate(const Point& rCenter, sal_uInt16 nAngle);
127     void Scale(double fSx, double fSy);
128     void SlantX(long nYRef, double fSin, double fCos);
129     void SlantY(long nXRef, double fSin, double fCos);
130     void Distort(const Rectangle& rRefRect, const XPolygon& rDistortedRect);
131     void Rotate20 ();
132 
133     // #116512# convert to basegfx::B2DPolygon and return
134     basegfx::B2DPolygon getB2DPolygon() const;
135 
136     // #116512# constructor to convert from basegfx::B2DPolygon
137     // #i76339# made explicit
138     explicit XPolygon(const basegfx::B2DPolygon& rPolygon);
139 };
140 
141 /*************************************************************************
142 |*
143 |* Klasse XPolyPolygon; wie PolyPolygon, nur statt aus Polygonen aus
144 |* XPolygonen bestehend
145 |*
146 \************************************************************************/
147 
148 class ImpXPolyPolygon;
149 
150 class SVX_DLLPUBLIC XPolyPolygon
151 {
152 protected:
153     ImpXPolyPolygon* pImpXPolyPolygon;
154 
155     // ImpXPolyPolygon-ReferenceCount pruefen und ggf. abkoppeln
156     void    CheckReference();
157 
158 public:
159                     XPolyPolygon( sal_uInt16 nInitSize = 16, sal_uInt16 nResize = 16 );
160                     XPolyPolygon( const XPolygon& rXPoly );
161                     XPolyPolygon( const XPolyPolygon& rXPolyPoly );
162                     XPolyPolygon( const PolyPolygon& rPolyPoly);
163 
164                     ~XPolyPolygon();
165 
166     void            Insert( const XPolygon& rXPoly,
167                             sal_uInt16 nPos = XPOLYPOLY_APPEND );
168     void            Insert( const XPolyPolygon& rXPoly,
169                             sal_uInt16 nPos=XPOLYPOLY_APPEND );
170     XPolygon        Remove( sal_uInt16 nPos );
171     XPolygon        Replace( const XPolygon& rXPoly, sal_uInt16 nPos );
172     const XPolygon& GetObject( sal_uInt16 nPos ) const;
173 
174     void            Clear();
175     sal_uInt16          Count() const;
176 
177     void            Move( long nHorzMove, long nVertMove );
178     Rectangle       GetBoundRect() const;
179 
operator [](sal_uInt16 nPos) const180     const XPolygon& operator[]( sal_uInt16 nPos ) const
181                         { return GetObject( nPos ); }
182     XPolygon&       operator[]( sal_uInt16 nPos );
183 
184     XPolyPolygon&   operator=( const XPolyPolygon& rXPolyPoly );
185     sal_Bool            operator==( const XPolyPolygon& rXPolyPoly ) const;
186     sal_Bool            operator!=( const XPolyPolygon& rXPolyPoly ) const;
187 
188     // Transformationen
189     void Translate(const Point& rTrans);
190     void Rotate(const Point& rCenter, double fSin, double fCos);
191     void Rotate(const Point& rCenter, sal_uInt16 nAngle);
192     void Scale(double fSx, double fSy);
193     void SlantX(long nYRef, double fSin, double fCos);
194     void SlantY(long nXRef, double fSin, double fCos);
195     void Distort(const Rectangle& rRefRect, const XPolygon& rDistortedRect);
196     void Rotate20 ();
197 
198     // #116512# convert to basegfx::B2DPolyPolygon and return
199     basegfx::B2DPolyPolygon getB2DPolyPolygon() const;
200 
201     // #116512# constructor to convert from basegfx::B2DPolyPolygon
202     // #i76339# made explicit
203     explicit XPolyPolygon(const basegfx::B2DPolyPolygon& rPolyPolygon);
204 };
205 
206 #endif      // _XPOLY_HXX
207 
208 // eof
209