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 
24 #ifndef _BGFX_TOOLS_CANVASTOOLS_HXX
25 #define _BGFX_TOOLS_CANVASTOOLS_HXX
26 
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <com/sun/star/uno/Sequence.hxx>
29 
30 
31 namespace com { namespace sun { namespace star { namespace geometry
32 {
33     struct AffineMatrix2D;
34     struct AffineMatrix3D;
35     struct Matrix2D;
36     struct RealPoint2D;
37     struct RealSize2D;
38     struct RealRectangle2D;
39     struct RealRectangle3D;
40     struct IntegerPoint2D;
41     struct IntegerSize2D;
42     struct IntegerRectangle2D;
43     struct RealBezierSegment2D;
44 } } } }
45 
46 namespace com { namespace sun { namespace star { namespace rendering
47 {
48     class  XGraphicDevice;
49     class  XPolyPolygon2D;
50 } } } }
51 
52 namespace com { namespace sun { namespace star { namespace awt
53 {
54     struct Point;
55     struct Size;
56     struct Rectangle;
57 } } } }
58 
59 namespace basegfx
60 {
61     class B2DHomMatrix;
62     class B3DHomMatrix;
63     class B2DVector;
64     class B2DPoint;
65     class B2DRange;
66     class B3DRange;
67     class B2IVector;
68     class B2IPoint;
69     class B2IRange;
70     class B2DPolygon;
71     class B2DPolyPolygon;
72 
73     namespace unotools
74     {
75         // Polygon conversions
76         // ===================================================================
77 
78         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >
79     		xPolyPolygonFromB2DPolygon( const ::com::sun::star::uno::Reference<
80                                         	::com::sun::star::rendering::XGraphicDevice >& 	xGraphicDevice,
81                                         const ::basegfx::B2DPolygon&						rPoly	 );
82 
83         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >
84     		xPolyPolygonFromB2DPolyPolygon( const ::com::sun::star::uno::Reference<
85                                          		::com::sun::star::rendering::XGraphicDevice >& 	xGraphicDevice,
86                                             const ::basegfx::B2DPolyPolygon&					rPolyPoly	 );
87 
88 
89         ::com::sun::star::uno::Sequence<
90   			::com::sun::star::uno::Sequence<
91   				::com::sun::star::geometry::RealBezierSegment2D > >
92 	                bezierSequenceSequenceFromB2DPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly );
93 
94         ::com::sun::star::uno::Sequence<
95   			::com::sun::star::uno::Sequence<
96   				::com::sun::star::geometry::RealPoint2D > >
97 	                pointSequenceSequenceFromB2DPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly );
98 
99         ::basegfx::B2DPolygon polygonFromPoint2DSequence(
100             const ::com::sun::star::uno::Sequence<
101             	::com::sun::star::geometry::RealPoint2D >& rPoints );
102 
103         ::basegfx::B2DPolyPolygon polyPolygonFromPoint2DSequenceSequence(
104             const ::com::sun::star::uno::Sequence<
105             	::com::sun::star::uno::Sequence< ::com::sun::star::geometry::RealPoint2D > >& rPoints );
106 
107         ::basegfx::B2DPolygon polygonFromBezier2DSequence(
108             const ::com::sun::star::uno::Sequence<
109             	::com::sun::star::geometry::RealBezierSegment2D >& rPoints );
110 
111         ::basegfx::B2DPolyPolygon polyPolygonFromBezier2DSequenceSequence(
112             const ::com::sun::star::uno::Sequence<
113             	::com::sun::star::uno::Sequence< ::com::sun::star::geometry::RealBezierSegment2D > >& rPoints );
114 
115         ::basegfx::B2DPolyPolygon b2DPolyPolygonFromXPolyPolygon2D(
116             const ::com::sun::star::uno::Reference<
117                      ::com::sun::star::rendering::XPolyPolygon2D >& rPoly );
118 
119         // Matrix conversions
120         // ===================================================================
121 
122         ::com::sun::star::geometry::AffineMatrix2D&
123         	affineMatrixFromHomMatrix( ::com::sun::star::geometry::AffineMatrix2D&	matrix,
124                                        const ::basegfx::B2DHomMatrix&				transform);
125 
126         ::com::sun::star::geometry::AffineMatrix3D& affineMatrixFromHomMatrix3D(
127 			::com::sun::star::geometry::AffineMatrix3D&	matrix,
128 			const ::basegfx::B3DHomMatrix& transform);
129 
130         ::basegfx::B2DHomMatrix&
131         	homMatrixFromAffineMatrix( ::basegfx::B2DHomMatrix&								transform,
132                                        const ::com::sun::star::geometry::AffineMatrix2D&	matrix );
133 
134 		::basegfx::B2DHomMatrix homMatrixFromAffineMatrix( const ::com::sun::star::geometry::AffineMatrix2D& matrix );
135 		::basegfx::B3DHomMatrix homMatrixFromAffineMatrix3D( const ::com::sun::star::geometry::AffineMatrix3D& matrix );
136 
137         ::com::sun::star::geometry::Matrix2D&
138         	matrixFromHomMatrix( ::com::sun::star::geometry::Matrix2D& matrix,
139                                  const ::basegfx::B2DHomMatrix&		   transform);
140 
141         ::basegfx::B2DHomMatrix&
142         	homMatrixFromMatrix( ::basegfx::B2DHomMatrix&					 transform,
143                                  const ::com::sun::star::geometry::Matrix2D& matrix );
144 
145         // Geometry conversions
146         // ===================================================================
147 
148         ::com::sun::star::geometry::RealSize2D  		size2DFromB2DSize( const ::basegfx::B2DVector& );
149         ::com::sun::star::geometry::RealPoint2D 		point2DFromB2DPoint( const ::basegfx::B2DPoint& );
150         ::com::sun::star::geometry::RealRectangle2D 	rectangle2DFromB2DRectangle( const ::basegfx::B2DRange& );
151         ::com::sun::star::geometry::RealRectangle3D 	rectangle3DFromB3DRectangle( const ::basegfx::B3DRange& );
152 
153         ::basegfx::B2DVector  	b2DSizeFromRealSize2D( const ::com::sun::star::geometry::RealSize2D& );
154         ::basegfx::B2DPoint		b2DPointFromRealPoint2D( const ::com::sun::star::geometry::RealPoint2D& );
155         ::basegfx::B2DRange		b2DRectangleFromRealRectangle2D( const ::com::sun::star::geometry::RealRectangle2D& );
156         ::basegfx::B3DRange		b3DRectangleFromRealRectangle3D( const ::com::sun::star::geometry::RealRectangle3D& );
157 
158         ::com::sun::star::geometry::IntegerSize2D  		integerSize2DFromB2ISize( const ::basegfx::B2IVector& );
159         ::com::sun::star::geometry::IntegerPoint2D  	integerPoint2DFromB2IPoint( const ::basegfx::B2IPoint& );
160         ::com::sun::star::geometry::IntegerRectangle2D	integerRectangle2DFromB2IRectangle( const ::basegfx::B2IRange& );
161 
162 		::basegfx::B2IVector  	b2ISizeFromIntegerSize2D( const ::com::sun::star::geometry::IntegerSize2D& );
163         ::basegfx::B2IPoint		b2IPointFromIntegerPoint2D( const ::com::sun::star::geometry::IntegerPoint2D& );
164         ::basegfx::B2IRange		b2IRectangleFromIntegerRectangle2D( const ::com::sun::star::geometry::IntegerRectangle2D& );
165 
166         ::com::sun::star::awt::Size  		awtSizeFromB2ISize( const ::basegfx::B2IVector& );
167         ::com::sun::star::awt::Point  		awtPointFromB2IPoint( const ::basegfx::B2IPoint& );
168         ::com::sun::star::awt::Rectangle	awtRectangleFromB2IRectangle( const ::basegfx::B2IRange& );
169 
170         ::basegfx::B2IVector  	b2ISizeFromAwtSize( const ::com::sun::star::awt::Size& );
171         ::basegfx::B2IPoint		b2IPointFromAwtPoint( const ::com::sun::star::awt::Point& );
172         ::basegfx::B2IRange		b2IRectangleFromAwtRectangle( const ::com::sun::star::awt::Rectangle& );
173 
174         // Geometry comparisons
175         // ===================================================================
176 
177 		bool RealSize2DAreEqual( const ::com::sun::star::geometry::RealSize2D& rA, const ::com::sun::star::geometry::RealSize2D& rB );
178 		bool RealPoint2DAreEqual( const ::com::sun::star::geometry::RealPoint2D& rA, const ::com::sun::star::geometry::RealPoint2D& rB );
179 		bool RealRectangle2DAreEqual( const ::com::sun::star::geometry::RealRectangle2D& rA, const ::com::sun::star::geometry::RealRectangle2D& rB );
180 		bool RealRectangle3DAreEqual( const ::com::sun::star::geometry::RealRectangle3D& rA, const ::com::sun::star::geometry::RealRectangle3D& rB );
181 		bool AffineMatrix2DAreEqual( const ::com::sun::star::geometry::AffineMatrix2D& rA, const ::com::sun::star::geometry::AffineMatrix2D& rB );
182 
183 		bool IntegerSize2DAreEqual( const ::com::sun::star::geometry::IntegerSize2D& rA, const ::com::sun::star::geometry::IntegerSize2D& rB );
184 		bool IntegerPoint2DAreEqual( const ::com::sun::star::geometry::IntegerPoint2D& rA, const ::com::sun::star::geometry::IntegerPoint2D& rB );
185 		bool IntegerRectangle2DAreEqual( const ::com::sun::star::geometry::IntegerRectangle2D& rA, const ::com::sun::star::geometry::IntegerRectangle2D& rB );
186 
187 		bool awtSizeAreEqual( const ::com::sun::star::awt::Size& rA, const ::com::sun::star::awt::Size& rB );
188 		bool awtPointAreEqual( const ::com::sun::star::awt::Point& rA, const ::com::sun::star::awt::Point& rB );
189 		bool awtRectangleAreEqual( const ::com::sun::star::awt::Rectangle& rA, const ::com::sun::star::awt::Rectangle& rB );
190 
191 		/** Return smalltest integer range, which completely contains
192             given floating point range.
193 
194 			@param rRange
195             Input range. Values must be within the representable
196             bounds of sal_Int32
197 
198             @return the closest integer range, which completely
199             contains rRange.
200          */
201         ::basegfx::B2IRange 	b2ISurroundingRangeFromB2DRange( const ::basegfx::B2DRange& rRange );
202 
203         /** Return smalltest B2DRange with integer values, which
204             completely contains given floating point range.
205 
206 			@param rRange
207             Input range.
208 
209             @return the closest B2DRange with integer coordinates,
210             which completely contains rRange.
211          */
212         ::basegfx::B2DRange 	b2DSurroundingIntegerRangeFromB2DRange( const ::basegfx::B2DRange& rRange );
213 
214     }
215 }
216 
217 #endif /* _BGFX_TOOLS_CANVASTOOLS_HXX */
218