/************************************************************************* * * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: canvastools.cxx,v $ * * $Revision: 1.7 $ * * last change: $Author: obo $ $Date: 2006-09-17 08:05:36 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. * * * GNU Lesser General Public License Version 2.1 * ============================================= * Copyright 2005 by Sun Microsystems, Inc. * 901 San Antonio Road, Palo Alto, CA 94303, USA * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * ************************************************************************/ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_basegfx.hxx" #ifndef _COM_SUN_STAR_GEOMETRY_REALSIZE2D_HPP__ #include #endif #ifndef _COM_SUN_STAR_GEOMETRY_REALPOINT2D_HPP__ #include #endif #ifndef _COM_SUN_STAR_GEOMETRY_REALRECTANGLE2D_HPP__ #include #endif #ifndef _COM_SUN_STAR_GEOMETRY_REALBEZIERSEGMENT2D_HPP__ #include #endif #ifndef _COM_SUN_STAR_GEOMETRY_AFFINEMATRIX2D_HPP_ #include #endif #ifndef _COM_SUN_STAR_GEOMETRY_INTEGERSIZE2D_HPP__ #include #endif #ifndef _COM_SUN_STAR_GEOMETRY_INTEGERPOINT2D_HPP__ #include #endif #ifndef _COM_SUN_STAR_GEOMETRY_INTEGERRECTANGLE2D_HPP__ #include #endif #ifndef _COM_SUN_STAR_RENDERING_XPOLYPOLYGON2D_HPP__ #include #endif #ifndef _COM_SUN_STAR_RENDERING_XGRAPHICDEVICE_HPP__ #include #endif #ifndef _COM_SUN_STAR_AWT_SIZE_HPP__ #include #endif #ifndef _COM_SUN_STAR_AWT_POINT_HPP__ #include #endif #ifndef _COM_SUN_STAR_AWT_RECTANGLE_HPP__ #include #endif #include #include #include #include #include #include #include #include #include #include #include using namespace ::com::sun::star; namespace basegfx { namespace unotools { namespace { uno::Sequence< geometry::RealBezierSegment2D > bezierSequenceFromB2DPolygon( const ::basegfx::B2DPolygon& rPoly ) { const sal_uInt32 nNumPoints( rPoly.count() ); uno::Sequence< geometry::RealBezierSegment2D > outputSequence( nNumPoints ); geometry::RealBezierSegment2D* pOutput = outputSequence.getArray(); // fill sequence from polygon sal_uInt32 i; for( i=0; i pointSequenceFromB2DPolygon( const ::basegfx::B2DPolygon& rPoly ) { const sal_uInt32 nNumPoints( rPoly.count() ); uno::Sequence< geometry::RealPoint2D > outputSequence( nNumPoints ); geometry::RealPoint2D* pOutput = outputSequence.getArray(); // fill sequence from polygon sal_uInt32 i; for( i=0; i > bezierSequenceSequenceFromB2DPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly ) { const sal_uInt32 nNumPolies( rPolyPoly.count() ); sal_uInt32 i; uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > > outputSequence( nNumPolies ); uno::Sequence< geometry::RealBezierSegment2D >* pOutput = outputSequence.getArray(); for( i=0; i > pointSequenceSequenceFromB2DPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly ) { const sal_uInt32 nNumPolies( rPolyPoly.count() ); sal_uInt32 i; uno::Sequence< uno::Sequence< geometry::RealPoint2D > > outputSequence( nNumPolies ); uno::Sequence< geometry::RealPoint2D >* pOutput = outputSequence.getArray(); for( i=0; i xPolyPolygonFromB2DPolygon( const uno::Reference< rendering::XGraphicDevice >& xGraphicDevice, const ::basegfx::B2DPolygon& rPoly ) { uno::Reference< rendering::XPolyPolygon2D > xRes; if( !xGraphicDevice.is() ) return xRes; if( rPoly.areControlPointsUsed() ) { uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > > outputSequence( 1 ); outputSequence[0] = bezierSequenceFromB2DPolygon( rPoly ); xRes.set( xGraphicDevice->createCompatibleBezierPolyPolygon( outputSequence ), uno::UNO_QUERY ); } else { uno::Sequence< uno::Sequence< geometry::RealPoint2D > > outputSequence( 1 ); outputSequence[0] = pointSequenceFromB2DPolygon( rPoly ); xRes.set( xGraphicDevice->createCompatibleLinePolyPolygon( outputSequence ), uno::UNO_QUERY ); } if( xRes.is() && rPoly.isClosed() ) xRes->setClosed( 0, sal_True ); return xRes; } //--------------------------------------------------------------------------------------- uno::Reference< rendering::XPolyPolygon2D > xPolyPolygonFromB2DPolyPolygon( const uno::Reference< rendering::XGraphicDevice >& xGraphicDevice, const ::basegfx::B2DPolyPolygon& rPolyPoly ) { uno::Reference< rendering::XPolyPolygon2D > xRes; if( !xGraphicDevice.is() ) return xRes; const sal_uInt32 nNumPolies( rPolyPoly.count() ); sal_uInt32 i; if( rPolyPoly.areControlPointsUsed() ) { xRes.set( xGraphicDevice->createCompatibleBezierPolyPolygon( bezierSequenceSequenceFromB2DPolyPolygon( rPolyPoly ) ), uno::UNO_QUERY ); } else { xRes.set( xGraphicDevice->createCompatibleLinePolyPolygon( pointSequenceSequenceFromB2DPolyPolygon( rPolyPoly ) ), uno::UNO_QUERY ); } for( i=0; isetClosed( i, sal_True ); } return xRes; } //--------------------------------------------------------------------------------------- ::basegfx::B2DPolygon polygonFromPoint2DSequence( const uno::Sequence< geometry::RealPoint2D >& points ) { const sal_Int32 nCurrSize( points.getLength() ); ::basegfx::B2DPolygon aPoly; for( sal_Int32 nCurrPoint=0; nCurrPoint >& points ) { ::basegfx::B2DPolyPolygon aRes; for( sal_Int32 nCurrPoly=0; nCurrPoly& curves ) { const sal_Int32 nSize( curves.getLength() ); ::basegfx::B2DPolygon aPoly; for( sal_Int32 nCurrPoint=0; nCurrPoint >& curves ) { ::basegfx::B2DPolyPolygon aRes; for( sal_Int32 nCurrPoly=0; nCurrPoly::max() && rRect.getWidth() > ::std::numeric_limits< sal_Int32 >::min(), "awtRectangleFromB2IRectangle(): width overflow" ); OSL_ENSURE( rRect.getHeight() < ::std::numeric_limits< sal_Int32 >::max() && rRect.getHeight() > ::std::numeric_limits< sal_Int32 >::min(), "awtRectangleFromB2IRectangle(): height overflow" ); return awt::Rectangle( rRect.getMinX(), rRect.getMinY(), static_cast< sal_Int32 >(rRect.getWidth()), static_cast< sal_Int32 >(rRect.getHeight()) ); } ::basegfx::B2IVector b2ISizeFromAwtSize( const awt::Size& rSize ) { return ::basegfx::B2IVector( rSize.Width, rSize.Height ); } ::basegfx::B2IPoint b2IPointFromAwtPoint( const awt::Point& rPoint ) { return ::basegfx::B2IPoint( rPoint.X, rPoint.Y ); } ::basegfx::B2IRange b2IRectangleFromAwtRectangle( const awt::Rectangle& rRect ) { return ::basegfx::B2IRange( rRect.X, rRect.Y, rRect.X + rRect.Width, rRect.Y + rRect.Height ); } ::basegfx::B2IRange b2ISurroundingRangeFromB2DRange( const ::basegfx::B2DRange& rRange ) { return ::basegfx::B2IRange( static_cast( floor(rRange.getMinX()) ), static_cast( floor(rRange.getMinY()) ), static_cast( ceil(rRange.getMaxX()) ), static_cast( ceil(rRange.getMaxY()) ) ); } ::basegfx::B2DRange b2DSurroundingIntegerRangeFromB2DRange( const ::basegfx::B2DRange& rRange ) { return ::basegfx::B2DRange( floor(rRange.getMinX()), floor(rRange.getMinY()), ceil(rRange.getMaxX()), ceil(rRange.getMaxY()) ); } } // namespace bgfxtools } // namespace canvas