merge the formfield patch from ooo-build
[ooovba.git] / canvas / source / tools / parametricpolypolygon.cxx
blob134fe2dd3b6061c779c9e9aaff4b2a280bf89c5b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: parametricpolypolygon.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_canvas.hxx"
34 #include <canvas/debug.hxx>
35 #include <canvas/canvastools.hxx>
37 #include <rtl/math.hxx>
39 #include <basegfx/matrix/b2dhommatrix.hxx>
40 #include <basegfx/polygon/b2dpolygontools.hxx>
41 #include <basegfx/point/b2dpoint.hxx>
42 #include <basegfx/range/b2drectangle.hxx>
43 #include <basegfx/tools/canvastools.hxx>
44 #include <basegfx/numeric/ftools.hxx>
45 #include <basegfx/tools/tools.hxx>
47 #include <limits>
49 #include <canvas/parametricpolypolygon.hxx>
52 using namespace ::com::sun::star;
54 namespace canvas
56 ParametricPolyPolygon* ParametricPolyPolygon::createLinearHorizontalGradient(
57 const uno::Reference< rendering::XGraphicDevice >& rDevice,
58 const uno::Sequence< uno::Sequence< double > >& colors,
59 const uno::Sequence< double >& stops )
61 // TODO(P2): hold gradient brush statically, and only setup
62 // the colors
63 return new ParametricPolyPolygon( rDevice, GRADIENT_LINEAR, colors, stops );
66 ParametricPolyPolygon* ParametricPolyPolygon::createAxialHorizontalGradient(
67 const uno::Reference< rendering::XGraphicDevice >& rDevice,
68 const uno::Sequence< uno::Sequence< double > >& colors,
69 const uno::Sequence< double >& stops )
71 // TODO(P2): hold gradient brush statically, and only setup
72 // the colors
73 return new ParametricPolyPolygon( rDevice, GRADIENT_AXIAL, colors, stops );
76 namespace
78 double calcAspectRatio( const geometry::RealRectangle2D& rBoundRect )
80 const double nWidth( rBoundRect.X2 - rBoundRect.X1 );
81 const double nHeight( rBoundRect.Y2 - rBoundRect.Y1 );
83 return ::basegfx::fTools::equalZero( nHeight ) ? 1.0 : fabs( nWidth / nHeight );
87 ParametricPolyPolygon* ParametricPolyPolygon::createEllipticalGradient(
88 const uno::Reference< rendering::XGraphicDevice >& rDevice,
89 const uno::Sequence< uno::Sequence< double > >& colors,
90 const uno::Sequence< double >& stops,
91 const geometry::RealRectangle2D& boundRect )
93 // TODO(P2): hold gradient polygon statically, and only setup
94 // the colors
95 return new ParametricPolyPolygon(
96 rDevice,
97 ::basegfx::tools::createPolygonFromCircle(
98 ::basegfx::B2DPoint( 0.5, 0.5), 0.5 ),
99 GRADIENT_ELLIPTICAL,
100 colors, stops,
101 calcAspectRatio( boundRect ) );
104 ParametricPolyPolygon* ParametricPolyPolygon::createRectangularGradient( const uno::Reference< rendering::XGraphicDevice >& rDevice,
105 const uno::Sequence< uno::Sequence< double > >& colors,
106 const uno::Sequence< double >& stops,
107 const geometry::RealRectangle2D& boundRect )
109 // TODO(P2): hold gradient polygon statically, and only setup
110 // the colors
111 return new ParametricPolyPolygon(
112 rDevice,
113 ::basegfx::tools::createPolygonFromRect(
114 ::basegfx::B2DRectangle( 0.0, 0.0, 1.0, 1.0 ) ),
115 GRADIENT_RECTANGULAR,
116 colors, stops,
117 calcAspectRatio( boundRect ) );
120 void SAL_CALL ParametricPolyPolygon::disposing()
122 ::osl::MutexGuard aGuard( m_aMutex );
124 mxDevice.clear();
127 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL ParametricPolyPolygon::getOutline( double /*t*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException)
129 ::osl::MutexGuard aGuard( m_aMutex );
131 // TODO(F1): outline NYI
132 return uno::Reference< rendering::XPolyPolygon2D >();
135 uno::Sequence< double > SAL_CALL ParametricPolyPolygon::getColor( double /*t*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException)
137 ::osl::MutexGuard aGuard( m_aMutex );
139 // TODO(F1): color NYI
140 return uno::Sequence< double >();
143 uno::Sequence< double > SAL_CALL ParametricPolyPolygon::getPointColor( const geometry::RealPoint2D& /*point*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException)
145 ::osl::MutexGuard aGuard( m_aMutex );
147 // TODO(F1): point color NYI
148 return uno::Sequence< double >();
151 uno::Reference< rendering::XColorSpace > SAL_CALL ParametricPolyPolygon::getColorSpace() throw (uno::RuntimeException)
153 ::osl::MutexGuard aGuard( m_aMutex );
155 return mxDevice.is() ? mxDevice->getDeviceColorSpace() : uno::Reference< rendering::XColorSpace >();
158 #define IMPLEMENTATION_NAME "Canvas::ParametricPolyPolygon"
159 #define SERVICE_NAME "com.sun.star.rendering.ParametricPolyPolygon"
161 ::rtl::OUString SAL_CALL ParametricPolyPolygon::getImplementationName( ) throw (uno::RuntimeException)
163 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) );
166 sal_Bool SAL_CALL ParametricPolyPolygon::supportsService( const ::rtl::OUString& ServiceName ) throw (uno::RuntimeException)
168 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) );
171 uno::Sequence< ::rtl::OUString > SAL_CALL ParametricPolyPolygon::getSupportedServiceNames( ) throw (uno::RuntimeException)
173 uno::Sequence< ::rtl::OUString > aRet(1);
174 aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
176 return aRet;
179 ParametricPolyPolygon::~ParametricPolyPolygon()
183 ParametricPolyPolygon::ParametricPolyPolygon( const uno::Reference< rendering::XGraphicDevice >& rDevice,
184 const ::basegfx::B2DPolygon& rGradientPoly,
185 GradientType eType,
186 const uno::Sequence< uno::Sequence< double > >& rColors,
187 const uno::Sequence< double >& rStops ) :
188 ParametricPolyPolygon_Base( m_aMutex ),
189 mxDevice( rDevice ),
190 maValues( rGradientPoly,
191 rColors,
192 rStops,
193 1.0,
194 eType )
198 ParametricPolyPolygon::ParametricPolyPolygon( const uno::Reference< rendering::XGraphicDevice >& rDevice,
199 const ::basegfx::B2DPolygon& rGradientPoly,
200 GradientType eType,
201 const uno::Sequence< uno::Sequence< double > >& rColors,
202 const uno::Sequence< double >& rStops,
203 double nAspectRatio ) :
204 ParametricPolyPolygon_Base( m_aMutex ),
205 mxDevice( rDevice ),
206 maValues( rGradientPoly,
207 rColors,
208 rStops,
209 nAspectRatio,
210 eType )
214 ParametricPolyPolygon::ParametricPolyPolygon( const uno::Reference< rendering::XGraphicDevice >& rDevice,
215 GradientType eType,
216 const uno::Sequence< uno::Sequence< double > >& rColors,
217 const uno::Sequence< double >& rStops ) :
218 ParametricPolyPolygon_Base( m_aMutex ),
219 mxDevice( rDevice ),
220 maValues( ::basegfx::B2DPolygon(),
221 rColors,
222 rStops,
223 1.0,
224 eType )
228 ParametricPolyPolygon::Values ParametricPolyPolygon::getValues() const
230 ::osl::MutexGuard aGuard( m_aMutex );
232 return maValues;