1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_basegfx.hxx"
30 
31 #include <com/sun/star/geometry/RealSize2D.hpp>
32 #include <com/sun/star/geometry/RealPoint2D.hpp>
33 #include <com/sun/star/geometry/RealRectangle2D.hpp>
34 #include <com/sun/star/geometry/RealRectangle3D.hpp>
35 #include <com/sun/star/geometry/RealBezierSegment2D.hpp>
36 #include <com/sun/star/geometry/AffineMatrix2D.hpp>
37 #include <com/sun/star/geometry/AffineMatrix3D.hpp>
38 #include <com/sun/star/geometry/Matrix2D.hpp>
39 #include <com/sun/star/geometry/IntegerSize2D.hpp>
40 #include <com/sun/star/geometry/IntegerPoint2D.hpp>
41 #include <com/sun/star/geometry/IntegerRectangle2D.hpp>
42 #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
43 #include <com/sun/star/rendering/XGraphicDevice.hpp>
44 #include <com/sun/star/awt/Size.hpp>
45 #include <com/sun/star/awt/Point.hpp>
46 #include <com/sun/star/awt/Rectangle.hpp>
47 #include <basegfx/tools/unopolypolygon.hxx>
48 #include <basegfx/matrix/b2dhommatrix.hxx>
49 #include <basegfx/matrix/b3dhommatrix.hxx>
50 #include <basegfx/vector/b2dsize.hxx>
51 #include <basegfx/point/b2dpoint.hxx>
52 #include <basegfx/range/b2drectangle.hxx>
53 #include <basegfx/range/b3drange.hxx>
54 #include <basegfx/vector/b2isize.hxx>
55 #include <basegfx/point/b2ipoint.hxx>
56 #include <basegfx/range/b2irectangle.hxx>
57 #include <basegfx/polygon/b2dpolygon.hxx>
58 #include <basegfx/polygon/b2dpolypolygon.hxx>
59 #include <basegfx/tools/canvastools.hxx>
60 #include <limits>
61 
62 using namespace ::com::sun::star;
63 
64 namespace basegfx
65 {
66 
67     namespace unotools
68     {
69         namespace
70         {
71             uno::Sequence< geometry::RealBezierSegment2D > bezierSequenceFromB2DPolygon(const ::basegfx::B2DPolygon& rPoly)
72             {
73                 const sal_uInt32 nPointCount(rPoly.count());
74                 uno::Sequence< geometry::RealBezierSegment2D > outputSequence(nPointCount);
75                 geometry::RealBezierSegment2D* pOutput = outputSequence.getArray();
76 
77 				// fill sequences and imply clodes polygon on this implementation layer
78 				for(sal_uInt32 a(0); a < nPointCount; a++)
79 				{
80                     const basegfx::B2DPoint aStart(rPoly.getB2DPoint(a));
81                     const basegfx::B2DPoint aControlA(rPoly.getNextControlPoint(a));
82                     const basegfx::B2DPoint aControlB(rPoly.getPrevControlPoint((a + 1) % nPointCount));
83 
84 					pOutput[a] = geometry::RealBezierSegment2D(
85 						aStart.getX(), aStart.getY(),
86 						aControlA.getX(), aControlA.getY(),
87 						aControlB.getX(), aControlB.getY());
88 				}
89 
90                 return outputSequence;
91             }
92 
93             uno::Sequence< geometry::RealPoint2D > pointSequenceFromB2DPolygon( const ::basegfx::B2DPolygon& rPoly )
94             {
95                 const sal_uInt32 nNumPoints( rPoly.count() );
96 
97                 uno::Sequence< geometry::RealPoint2D > outputSequence( nNumPoints );
98                 geometry::RealPoint2D* pOutput = outputSequence.getArray();
99 
100                 // fill sequence from polygon
101                 sal_uInt32 i;
102                 for( i=0; i<nNumPoints; ++i )
103                 {
104                     const ::basegfx::B2DPoint 	aPoint( rPoly.getB2DPoint(i) );
105 
106                     pOutput[i] = geometry::RealPoint2D( aPoint.getX(),
107                                                         aPoint.getY() );
108                 }
109 
110                 return outputSequence;
111             }
112         }
113 
114         //---------------------------------------------------------------------------------------
115 
116         uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > > bezierSequenceSequenceFromB2DPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly )
117         {
118             const sal_uInt32 nNumPolies( rPolyPoly.count() );
119             sal_uInt32 i;
120 
121             uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > > outputSequence( nNumPolies );
122             uno::Sequence< geometry::RealBezierSegment2D >* pOutput = outputSequence.getArray();
123 
124             for( i=0; i<nNumPolies; ++i )
125             {
126                 pOutput[i] = bezierSequenceFromB2DPolygon( rPolyPoly.getB2DPolygon(i) );
127             }
128 
129             return outputSequence;
130         }
131 
132         //---------------------------------------------------------------------------------------
133 
134         uno::Sequence< uno::Sequence< geometry::RealPoint2D > > pointSequenceSequenceFromB2DPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly	 )
135         {
136             const sal_uInt32 nNumPolies( rPolyPoly.count() );
137             sal_uInt32 i;
138 
139             uno::Sequence< uno::Sequence< geometry::RealPoint2D > > outputSequence( nNumPolies );
140             uno::Sequence< geometry::RealPoint2D >* pOutput = outputSequence.getArray();
141 
142             for( i=0; i<nNumPolies; ++i )
143             {
144                 pOutput[i] = pointSequenceFromB2DPolygon( rPolyPoly.getB2DPolygon(i) );
145             }
146 
147             return outputSequence;
148         }
149 
150         //---------------------------------------------------------------------------------------
151 
152         uno::Reference< rendering::XPolyPolygon2D > xPolyPolygonFromB2DPolygon( const uno::Reference< rendering::XGraphicDevice >& 	xGraphicDevice,
153                                                                                 const ::basegfx::B2DPolygon&						rPoly	 )
154         {
155             uno::Reference< rendering::XPolyPolygon2D > xRes;
156 
157             if( !xGraphicDevice.is() )
158                 return xRes;
159 
160             if( rPoly.areControlPointsUsed() )
161             {
162                 uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > > outputSequence( 1 );
163                 outputSequence[0] = bezierSequenceFromB2DPolygon( rPoly );
164 
165                 xRes.set( xGraphicDevice->createCompatibleBezierPolyPolygon( outputSequence ),
166                           uno::UNO_QUERY );
167             }
168             else
169             {
170                 uno::Sequence< uno::Sequence< geometry::RealPoint2D > > outputSequence( 1 );
171                 outputSequence[0] = pointSequenceFromB2DPolygon( rPoly );
172 
173                 xRes.set( xGraphicDevice->createCompatibleLinePolyPolygon( outputSequence ),
174                           uno::UNO_QUERY );
175             }
176 
177             if( xRes.is() && rPoly.isClosed() )
178                 xRes->setClosed( 0, sal_True );
179 
180             return xRes;
181         }
182 
183         //---------------------------------------------------------------------------------------
184 
185         uno::Reference< rendering::XPolyPolygon2D > xPolyPolygonFromB2DPolyPolygon( const uno::Reference< rendering::XGraphicDevice >& 	xGraphicDevice,
186                                                                                     const ::basegfx::B2DPolyPolygon&					rPolyPoly	 )
187         {
188             uno::Reference< rendering::XPolyPolygon2D > xRes;
189 
190             if( !xGraphicDevice.is() )
191                 return xRes;
192 
193             const sal_uInt32 nNumPolies( rPolyPoly.count() );
194             sal_uInt32 i;
195 
196             if( rPolyPoly.areControlPointsUsed() )
197             {
198                 xRes.set( xGraphicDevice->createCompatibleBezierPolyPolygon(
199                               bezierSequenceSequenceFromB2DPolyPolygon( rPolyPoly ) ),
200                           uno::UNO_QUERY );
201             }
202             else
203             {
204                 xRes.set( xGraphicDevice->createCompatibleLinePolyPolygon(
205                               pointSequenceSequenceFromB2DPolyPolygon( rPolyPoly ) ),
206                           uno::UNO_QUERY );
207             }
208 
209             for( i=0; i<nNumPolies; ++i )
210             {
211 	            xRes->setClosed( i, rPolyPoly.getB2DPolygon(i).isClosed() );
212             }
213 
214             return xRes;
215         }
216 
217         //---------------------------------------------------------------------------------------
218 
219         ::basegfx::B2DPolygon polygonFromPoint2DSequence( const uno::Sequence< geometry::RealPoint2D >& points )
220         {
221             const sal_Int32 nCurrSize( points.getLength() );
222 
223             ::basegfx::B2DPolygon aPoly;
224 
225             for( sal_Int32 nCurrPoint=0; nCurrPoint<nCurrSize; ++nCurrPoint )
226                 aPoly.append( b2DPointFromRealPoint2D( points[nCurrPoint] ) );
227 
228             return aPoly;
229         }
230 
231         //---------------------------------------------------------------------------------------
232 
233         ::basegfx::B2DPolyPolygon polyPolygonFromPoint2DSequenceSequence( const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >& points )
234         {
235             ::basegfx::B2DPolyPolygon aRes;
236 
237             for( sal_Int32 nCurrPoly=0; nCurrPoly<points.getLength(); ++nCurrPoly )
238             {
239                 aRes.append( polygonFromPoint2DSequence( points[nCurrPoly] ) );
240             }
241 
242             return aRes;
243         }
244 
245         //---------------------------------------------------------------------------------------
246 
247         ::basegfx::B2DPolygon polygonFromBezier2DSequence( const uno::Sequence< geometry::RealBezierSegment2D >& curves )
248         {
249             const sal_Int32 nSize(curves.getLength());
250 			basegfx::B2DPolygon aRetval;
251 
252 			if(nSize)
253 			{
254 				// prepare start with providing a start point. Use the first point from
255 				// the sequence for this
256 				const geometry::RealBezierSegment2D& rFirstSegment(curves[0]); // #i79917# first segment, not last
257 				aRetval.append(basegfx::B2DPoint(rFirstSegment.Px, rFirstSegment.Py));
258 
259 				for(sal_Int32 a(0); a < nSize; a++)
260 				{
261 					const geometry::RealBezierSegment2D& rCurrSegment(curves[a]);
262 					const geometry::RealBezierSegment2D& rNextSegment(curves[(a + 1) % nSize]);
263 
264 					// append curved edge with the control points and the next point
265 					aRetval.appendBezierSegment(
266 						basegfx::B2DPoint(rCurrSegment.C1x, rCurrSegment.C1y),
267 						basegfx::B2DPoint(rCurrSegment.C2x, rCurrSegment.C2y), // #i79917# Argh! An x for an y!!
268 						basegfx::B2DPoint(rNextSegment.Px, rNextSegment.Py));
269 				}
270 
271 				// rescue the control point and remove the now double-added point
272 				aRetval.setPrevControlPoint(0, aRetval.getPrevControlPoint(aRetval.count() - 1));
273 				aRetval.remove(aRetval.count() - 1);
274 			}
275 
276 			return aRetval;
277         }
278 
279         //---------------------------------------------------------------------------------------
280 
281         ::basegfx::B2DPolyPolygon polyPolygonFromBezier2DSequenceSequence( const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >& curves )
282         {
283             ::basegfx::B2DPolyPolygon aRes;
284 
285             for( sal_Int32 nCurrPoly=0; nCurrPoly<curves.getLength(); ++nCurrPoly )
286             {
287                 aRes.append( polygonFromBezier2DSequence( curves[nCurrPoly] ) );
288             }
289 
290             return aRes;
291         }
292 
293         //---------------------------------------------------------------------------------------
294 
295         ::basegfx::B2DPolyPolygon b2DPolyPolygonFromXPolyPolygon2D( const uno::Reference< rendering::XPolyPolygon2D >& xPoly )
296         {
297             ::basegfx::unotools::UnoPolyPolygon* pPolyImpl =
298                 dynamic_cast< ::basegfx::unotools::UnoPolyPolygon* >( xPoly.get() );
299 
300             if( pPolyImpl )
301             {
302                 return pPolyImpl->getPolyPolygon();
303             }
304             else
305             {
306                 // not a known implementation object - try data source
307                 // interfaces
308                 const sal_Int32 nPolys( xPoly->getNumberOfPolygons() );
309 
310                 uno::Reference< rendering::XBezierPolyPolygon2D > xBezierPoly(
311                     xPoly,
312                     uno::UNO_QUERY );
313 
314                 if( xBezierPoly.is() )
315                 {
316                     return ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence(
317                         xBezierPoly->getBezierSegments( 0,
318                                                         nPolys,
319                                                         0,
320                                                         -1 ) );
321                 }
322                 else
323                 {
324                     uno::Reference< rendering::XLinePolyPolygon2D > xLinePoly(
325                         xPoly,
326                         uno::UNO_QUERY );
327 
328                     // no implementation class and no data provider
329                     // found - contract violation.
330                     if( !xLinePoly.is() )
331                     {
332                         throw lang::IllegalArgumentException(
333                             ::rtl::OUString::createFromAscii(
334                                     "basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(): Invalid input"
335                                     "poly-polygon, cannot retrieve vertex data"),
336                             uno::Reference< uno::XInterface >(),
337                             0 );
338                     }
339 
340                     return ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence(
341                         xLinePoly->getPoints( 0,
342                                               nPolys,
343                                               0,
344                                               -1 ));
345                 }
346             }
347         }
348 
349         //---------------------------------------------------------------------------------------
350 
351         ::basegfx::B2DHomMatrix& homMatrixFromAffineMatrix( ::basegfx::B2DHomMatrix&		output,
352                                                             const geometry::AffineMatrix2D&	input )
353         {
354             // ensure last row is [0,0,1] (and optimized away)
355             output.identity();
356 
357             output.set(0,0, input.m00);
358             output.set(0,1, input.m01);
359             output.set(0,2, input.m02);
360             output.set(1,0, input.m10);
361             output.set(1,1, input.m11);
362             output.set(1,2, input.m12);
363 
364             return output;
365         }
366 
367         ::basegfx::B2DHomMatrix homMatrixFromAffineMatrix( const geometry::AffineMatrix2D& input )
368         {
369             ::basegfx::B2DHomMatrix output;
370 
371             output.set(0,0, input.m00);
372             output.set(0,1, input.m01);
373             output.set(0,2, input.m02);
374             output.set(1,0, input.m10);
375             output.set(1,1, input.m11);
376             output.set(1,2, input.m12);
377 
378             return output;
379         }
380 
381 		::basegfx::B3DHomMatrix homMatrixFromAffineMatrix3D( const ::com::sun::star::geometry::AffineMatrix3D& input )
382 		{
383             ::basegfx::B3DHomMatrix output;
384 
385             output.set(0,0, input.m00);
386             output.set(0,1, input.m01);
387             output.set(0,2, input.m02);
388             output.set(0,3, input.m03);
389 
390             output.set(1,0, input.m10);
391             output.set(1,1, input.m11);
392             output.set(1,2, input.m12);
393             output.set(1,3, input.m13);
394 
395             output.set(2,0, input.m20);
396             output.set(2,1, input.m21);
397             output.set(2,2, input.m22);
398             output.set(2,3, input.m23);
399 
400             return output;
401 		}
402 
403         geometry::AffineMatrix2D& affineMatrixFromHomMatrix( geometry::AffineMatrix2D&		output,
404                                                              const ::basegfx::B2DHomMatrix&	input)
405         {
406             output.m00 = input.get(0,0);
407             output.m01 = input.get(0,1);
408             output.m02 = input.get(0,2);
409             output.m10 = input.get(1,0);
410             output.m11 = input.get(1,1);
411             output.m12 = input.get(1,2);
412 
413             return output;
414         }
415 
416         geometry::AffineMatrix3D& affineMatrixFromHomMatrix3D(
417 			geometry::AffineMatrix3D& output,
418 			const ::basegfx::B3DHomMatrix&	input)
419         {
420             output.m00 = input.get(0,0);
421             output.m01 = input.get(0,1);
422             output.m02 = input.get(0,2);
423             output.m03 = input.get(0,3);
424 
425 			output.m10 = input.get(1,0);
426             output.m11 = input.get(1,1);
427             output.m12 = input.get(1,2);
428             output.m13 = input.get(1,3);
429 
430 			output.m20 = input.get(2,0);
431             output.m21 = input.get(2,1);
432             output.m22 = input.get(2,2);
433             output.m23 = input.get(2,3);
434 
435             return output;
436         }
437 
438         //---------------------------------------------------------------------------------------
439 
440         ::basegfx::B2DHomMatrix& homMatrixFromMatrix( ::basegfx::B2DHomMatrix&	output,
441                                                       const geometry::Matrix2D& input )
442         {
443             // ensure last row is [0,0,1] (and optimized away)
444             output.identity();
445 
446             output.set(0,0, input.m00);
447             output.set(0,1, input.m01);
448             output.set(1,0, input.m10);
449             output.set(1,1, input.m11);
450 
451             return output;
452         }
453 
454         //---------------------------------------------------------------------------------------
455 
456         geometry::RealSize2D size2DFromB2DSize( const ::basegfx::B2DVector& rVec )
457         {
458             return geometry::RealSize2D( rVec.getX(),
459                                          rVec.getY() );
460         }
461 
462         geometry::RealPoint2D point2DFromB2DPoint( const ::basegfx::B2DPoint& rPoint )
463         {
464             return geometry::RealPoint2D( rPoint.getX(),
465                                           rPoint.getY() );
466         }
467 
468         geometry::RealRectangle2D rectangle2DFromB2DRectangle( const ::basegfx::B2DRange& rRect )
469         {
470             return geometry::RealRectangle2D( rRect.getMinX(),
471                                               rRect.getMinY(),
472                                               rRect.getMaxX(),
473                                               rRect.getMaxY() );
474         }
475 
476         geometry::RealRectangle3D rectangle3DFromB3DRectangle( const ::basegfx::B3DRange& rRect )
477         {
478             return geometry::RealRectangle3D( rRect.getMinX(),
479                                               rRect.getMinY(),
480                                               rRect.getMinZ(),
481                                               rRect.getMaxX(),
482                                               rRect.getMaxY(),
483 											  rRect.getMaxZ());
484         }
485 
486         ::basegfx::B2DVector b2DSizeFromRealSize2D( const geometry::RealSize2D& rSize )
487         {
488             return ::basegfx::B2DVector( rSize.Width,
489                                          rSize.Height );
490         }
491 
492         ::basegfx::B2DPoint b2DPointFromRealPoint2D( const geometry::RealPoint2D& rPoint )
493         {
494             return ::basegfx::B2DPoint( rPoint.X,
495                                         rPoint.Y );
496         }
497 
498         ::basegfx::B2DRange b2DRectangleFromRealRectangle2D( const geometry::RealRectangle2D& rRect )
499         {
500             return ::basegfx::B2DRange( rRect.X1,
501                                         rRect.Y1,
502                                         rRect.X2,
503                                         rRect.Y2 );
504         }
505 
506         ::basegfx::B3DRange b3DRectangleFromRealRectangle3D( const geometry::RealRectangle3D& rRect )
507         {
508             return ::basegfx::B3DRange( rRect.X1,
509                                         rRect.Y1,
510                                         rRect.Z1,
511                                         rRect.X2,
512                                         rRect.Y2,
513 										rRect.Z2);
514         }
515 
516         geometry::IntegerSize2D integerSize2DFromB2ISize( const ::basegfx::B2IVector& rSize )
517         {
518             return geometry::IntegerSize2D( rSize.getX(),
519                                             rSize.getY() );
520         }
521 
522         geometry::IntegerPoint2D integerPoint2DFromB2IPoint( const ::basegfx::B2IPoint& rPoint )
523         {
524             return geometry::IntegerPoint2D( rPoint.getX(),
525                                              rPoint.getY() );
526         }
527 
528         geometry::IntegerRectangle2D integerRectangle2DFromB2IRectangle( const ::basegfx::B2IRange& rRectangle )
529         {
530             return geometry::IntegerRectangle2D( rRectangle.getMinX(), rRectangle.getMinY(),
531                                                  rRectangle.getMaxX(), rRectangle.getMaxY() );
532         }
533 
534         ::basegfx::B2IVector b2ISizeFromIntegerSize2D( const geometry::IntegerSize2D& rSize )
535         {
536             return ::basegfx::B2IVector( rSize.Width,
537                                          rSize.Height );
538         }
539 
540         ::basegfx::B2IPoint b2IPointFromIntegerPoint2D( const geometry::IntegerPoint2D& rPoint )
541         {
542             return ::basegfx::B2IPoint( rPoint.X,
543                                         rPoint.Y );
544         }
545 
546         ::basegfx::B2IRange b2IRectangleFromIntegerRectangle2D( const geometry::IntegerRectangle2D& rRectangle )
547         {
548             return ::basegfx::B2IRange( rRectangle.X1, rRectangle.Y1,
549                                         rRectangle.X2, rRectangle.Y2 );
550         }
551 
552         awt::Size awtSizeFromB2ISize( const ::basegfx::B2IVector& rVec )
553         {
554             return awt::Size( rVec.getX(),
555                               rVec.getY() );
556         }
557 
558         awt::Point awtPointFromB2IPoint( const ::basegfx::B2IPoint& rPoint )
559         {
560             return awt::Point( rPoint.getX(),
561                                rPoint.getY() );
562         }
563 
564         awt::Rectangle awtRectangleFromB2IRectangle( const ::basegfx::B2IRange& rRect )
565         {
566             OSL_ENSURE( rRect.getWidth() < ::std::numeric_limits< sal_Int32 >::max() &&
567                         rRect.getWidth() > ::std::numeric_limits< sal_Int32 >::min(),
568                         "awtRectangleFromB2IRectangle(): width overflow" );
569             OSL_ENSURE( rRect.getHeight() < ::std::numeric_limits< sal_Int32 >::max() &&
570                         rRect.getHeight() > ::std::numeric_limits< sal_Int32 >::min(),
571                         "awtRectangleFromB2IRectangle(): height overflow" );
572 
573             return awt::Rectangle( rRect.getMinX(),
574                                    rRect.getMinY(),
575                                    static_cast< sal_Int32 >(rRect.getWidth()),
576                                    static_cast< sal_Int32 >(rRect.getHeight()) );
577         }
578 
579         ::basegfx::B2IVector b2ISizeFromAwtSize( const awt::Size& rSize )
580         {
581             return ::basegfx::B2IVector( rSize.Width,
582                                          rSize.Height );
583         }
584 
585         ::basegfx::B2IPoint b2IPointFromAwtPoint( const awt::Point& rPoint )
586         {
587             return ::basegfx::B2IPoint( rPoint.X,
588                                         rPoint.Y );
589         }
590 
591         ::basegfx::B2IRange b2IRectangleFromAwtRectangle( const awt::Rectangle& rRect )
592         {
593             return ::basegfx::B2IRange( rRect.X,
594                                         rRect.Y,
595                                         rRect.X + rRect.Width,
596                                         rRect.Y + rRect.Height );
597         }
598 
599         ::basegfx::B2IRange b2ISurroundingRangeFromB2DRange( const ::basegfx::B2DRange& rRange )
600         {
601             return ::basegfx::B2IRange( static_cast<sal_Int32>( floor(rRange.getMinX()) ),
602                                         static_cast<sal_Int32>( floor(rRange.getMinY()) ),
603                                         static_cast<sal_Int32>( ceil(rRange.getMaxX()) ),
604                                         static_cast<sal_Int32>( ceil(rRange.getMaxY()) ) );
605         }
606 
607         ::basegfx::B2DRange b2DSurroundingIntegerRangeFromB2DRange( const ::basegfx::B2DRange& rRange )
608         {
609             return ::basegfx::B2DRange( floor(rRange.getMinX()),
610                                         floor(rRange.getMinY()),
611                                         ceil(rRange.getMaxX()),
612                                         ceil(rRange.getMaxY()) );
613         }
614 
615         // Geometry comparisons
616         // ===================================================================
617 
618 		bool RealSize2DAreEqual( const ::com::sun::star::geometry::RealSize2D& rA, const ::com::sun::star::geometry::RealSize2D& rB )
619 		{
620 			return (rA.Width == rB.Width && rA.Height == rB.Height);
621 		}
622 
623 		bool RealPoint2DAreEqual( const ::com::sun::star::geometry::RealPoint2D& rA, const ::com::sun::star::geometry::RealPoint2D& rB )
624 		{
625 			return (rA.X == rB.X && rA.Y == rB.Y);
626 		}
627 
628 		bool RealRectangle2DAreEqual( const ::com::sun::star::geometry::RealRectangle2D& rA, const ::com::sun::star::geometry::RealRectangle2D& rB )
629 		{
630 			return (rA.X1 == rB.X1 && rA.Y1 == rB.Y1 && rA.X2 == rB.X2 && rA.Y2 == rB.Y2);
631 		}
632 
633 		bool RealRectangle3DAreEqual( const ::com::sun::star::geometry::RealRectangle3D& rA, const ::com::sun::star::geometry::RealRectangle3D& rB )
634 		{
635 			return (rA.X1 == rB.X1 && rA.Y1 == rB.Y1 && rA.Z1 == rB.Z1 && rA.X2 == rB.X2 && rA.Y2 == rB.Y2 && rA.Z2 == rB.Z2);
636 		}
637 
638 		bool AffineMatrix2DAreEqual( const ::com::sun::star::geometry::AffineMatrix2D& rA, const ::com::sun::star::geometry::AffineMatrix2D& rB )
639 		{
640 			return (rA.m00 == rB.m00 && rA.m01 == rB.m01 && rA.m02 == rB.m02 && rA.m10 == rB.m10 && rA.m11 == rB.m11 && rA.m12 == rB.m12);
641 		}
642 
643 		bool IntegerSize2DAreEqual( const ::com::sun::star::geometry::IntegerSize2D& rA, const ::com::sun::star::geometry::IntegerSize2D& rB )
644 		{
645 			return (rA.Width == rB.Width && rA.Height == rB.Height);
646 		}
647 
648 		bool IntegerPoint2DAreEqual( const ::com::sun::star::geometry::IntegerPoint2D& rA, const ::com::sun::star::geometry::IntegerPoint2D& rB )
649 		{
650 			return (rA.X == rB.X && rA.Y == rB.Y);
651 		}
652 
653 		bool IntegerRectangle2DAreEqual( const ::com::sun::star::geometry::IntegerRectangle2D& rA, const ::com::sun::star::geometry::IntegerRectangle2D& rB )
654 		{
655 			return (rA.X1 == rB.X1 && rA.Y1 == rB.Y1 && rA.X2 == rB.X2 && rA.Y2 == rB.Y2);
656 		}
657 
658 		bool awtSizeAreEqual( const ::com::sun::star::awt::Size& rA, const ::com::sun::star::awt::Size& rB )
659 		{
660 			return (rA.Width == rB.Width && rA.Height == rB.Height);
661 		}
662 
663 		bool awtPointAreEqual( const ::com::sun::star::awt::Point& rA, const ::com::sun::star::awt::Point& rB )
664 		{
665 			return (rA.X == rB.X && rA.Y == rB.Y);
666 		}
667 
668 		bool awtRectangleAreEqual( const ::com::sun::star::awt::Rectangle& rA, const ::com::sun::star::awt::Rectangle& rB )
669 		{
670 			return (rA.X == rB.X && rA.Y == rB.Y && rA.Width == rB.Width && rA.Height == rB.Height);
671 		}
672     } // namespace bgfxtools
673 
674 } // namespace canvas
675