Branch libreoffice-5-0-4
[LibreOffice.git] / canvas / source / tools / parametricpolypolygon.cxx
blob688f90d4b3d4811fa264038fc9c2266e0cecde09
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <canvas/debug.hxx>
21 #include <canvas/canvastools.hxx>
23 #include <rtl/math.hxx>
25 #include <basegfx/matrix/b2dhommatrix.hxx>
26 #include <basegfx/polygon/b2dpolygontools.hxx>
27 #include <basegfx/point/b2dpoint.hxx>
28 #include <basegfx/range/b2drectangle.hxx>
29 #include <basegfx/tools/canvastools.hxx>
30 #include <basegfx/numeric/ftools.hxx>
31 #include <basegfx/tools/tools.hxx>
32 #include <cppuhelper/supportsservice.hxx>
34 #include <limits>
36 #include <canvas/parametricpolypolygon.hxx>
38 using namespace ::com::sun::star;
40 namespace canvas
42 uno::Sequence<OUString> ParametricPolyPolygon::getAvailableServiceNames()
44 uno::Sequence<OUString> aRet(3);
45 aRet[0] = "LinearGradient";
46 aRet[1] = "EllipticalGradient";
47 aRet[2] = "RectangularGradient";
49 return aRet;
52 ParametricPolyPolygon* ParametricPolyPolygon::create(
53 const uno::Reference< rendering::XGraphicDevice >& rDevice,
54 const OUString& rServiceName,
55 const uno::Sequence< uno::Any >& rArgs )
57 uno::Sequence< uno::Sequence< double > > colorSequence(2);
58 uno::Sequence< double > colorStops(2);
59 double fAspectRatio=1.0;
61 // defaults
62 uno::Sequence< rendering::RGBColor > rgbColors(1);
63 rgbColors[0] = rendering::RGBColor(0,0,0);
64 colorSequence[0] = rDevice->getDeviceColorSpace()->convertFromRGB(rgbColors);
65 rgbColors[0] = rendering::RGBColor(1,1,1);
66 colorSequence[1] = rDevice->getDeviceColorSpace()->convertFromRGB(rgbColors);
67 colorStops[0] = 0;
68 colorStops[1] = 1;
70 // extract args
71 for( sal_Int32 i=0; i<rArgs.getLength(); ++i )
73 beans::PropertyValue aProp;
74 if( (rArgs[i] >>= aProp) )
76 if ( aProp.Name == "Colors" )
78 aProp.Value >>= colorSequence;
80 else if ( aProp.Name == "Stops" )
82 aProp.Value >>= colorStops;
84 else if ( aProp.Name == "AspectRatio" )
86 aProp.Value >>= fAspectRatio;
91 if ( rServiceName == "LinearGradient" )
93 return createLinearHorizontalGradient(rDevice, colorSequence, colorStops);
95 else if ( rServiceName == "EllipticalGradient" )
97 return createEllipticalGradient(rDevice, colorSequence, colorStops, fAspectRatio);
99 else if ( rServiceName == "RectangularGradient" )
101 return createRectangularGradient(rDevice, colorSequence, colorStops, fAspectRatio);
103 else if ( rServiceName == "VerticalLineHatch" )
105 // TODO: NYI
107 else if ( rServiceName == "OrthogonalLinesHatch" )
109 // TODO: NYI
111 else if ( rServiceName == "ThreeCrossingLinesHatch" )
113 // TODO: NYI
115 else if ( rServiceName == "FourCrossingLinesHatch" )
117 // TODO: NYI
120 return NULL;
123 ParametricPolyPolygon* ParametricPolyPolygon::createLinearHorizontalGradient(
124 const uno::Reference< rendering::XGraphicDevice >& rDevice,
125 const uno::Sequence< uno::Sequence< double > >& colors,
126 const uno::Sequence< double >& stops )
128 // TODO(P2): hold gradient brush statically, and only setup
129 // the colors
130 return new ParametricPolyPolygon( rDevice, GRADIENT_LINEAR, colors, stops );
133 ParametricPolyPolygon* ParametricPolyPolygon::createEllipticalGradient(
134 const uno::Reference< rendering::XGraphicDevice >& rDevice,
135 const uno::Sequence< uno::Sequence< double > >& colors,
136 const uno::Sequence< double >& stops,
137 double fAspectRatio )
139 // TODO(P2): hold gradient polygon statically, and only setup
140 // the colors
141 return new ParametricPolyPolygon(
142 rDevice,
143 ::basegfx::tools::createPolygonFromCircle(
144 ::basegfx::B2DPoint(0,0), 1 ),
145 GRADIENT_ELLIPTICAL,
146 colors, stops, fAspectRatio );
149 ParametricPolyPolygon* ParametricPolyPolygon::createRectangularGradient( const uno::Reference< rendering::XGraphicDevice >& rDevice,
150 const uno::Sequence< uno::Sequence< double > >& colors,
151 const uno::Sequence< double >& stops,
152 double fAspectRatio )
154 // TODO(P2): hold gradient polygon statically, and only setup
155 // the colors
156 return new ParametricPolyPolygon(
157 rDevice,
158 ::basegfx::tools::createPolygonFromRect(
159 ::basegfx::B2DRectangle( -1, -1, 1, 1 ) ),
160 GRADIENT_RECTANGULAR,
161 colors, stops, fAspectRatio );
164 void SAL_CALL ParametricPolyPolygon::disposing()
166 ::osl::MutexGuard aGuard( m_aMutex );
168 mxDevice.clear();
171 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL ParametricPolyPolygon::getOutline( double /*t*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
173 ::osl::MutexGuard aGuard( m_aMutex );
175 // TODO(F1): outline NYI
176 return uno::Reference< rendering::XPolyPolygon2D >();
179 uno::Sequence< double > SAL_CALL ParametricPolyPolygon::getColor( double /*t*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
181 ::osl::MutexGuard aGuard( m_aMutex );
183 // TODO(F1): color NYI
184 return uno::Sequence< double >();
187 uno::Sequence< double > SAL_CALL ParametricPolyPolygon::getPointColor( const geometry::RealPoint2D& /*point*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
189 ::osl::MutexGuard aGuard( m_aMutex );
191 // TODO(F1): point color NYI
192 return uno::Sequence< double >();
195 uno::Reference< rendering::XColorSpace > SAL_CALL ParametricPolyPolygon::getColorSpace() throw (uno::RuntimeException, std::exception)
197 ::osl::MutexGuard aGuard( m_aMutex );
199 return mxDevice.is() ? mxDevice->getDeviceColorSpace() : uno::Reference< rendering::XColorSpace >();
203 OUString SAL_CALL ParametricPolyPolygon::getImplementationName( ) throw (uno::RuntimeException, std::exception)
205 return OUString( "Canvas::ParametricPolyPolygon" );
208 sal_Bool SAL_CALL ParametricPolyPolygon::supportsService( const OUString& ServiceName ) throw (uno::RuntimeException, std::exception)
210 return cppu::supportsService(this, ServiceName);
213 uno::Sequence< OUString > SAL_CALL ParametricPolyPolygon::getSupportedServiceNames( ) throw (uno::RuntimeException, std::exception)
215 uno::Sequence< OUString > aRet(1);
216 aRet[0] = "com.sun.star.rendering.ParametricPolyPolygon";
218 return aRet;
221 ParametricPolyPolygon::~ParametricPolyPolygon()
225 ParametricPolyPolygon::ParametricPolyPolygon( const uno::Reference< rendering::XGraphicDevice >& rDevice,
226 const ::basegfx::B2DPolygon& rGradientPoly,
227 GradientType eType,
228 const uno::Sequence< uno::Sequence< double > >& rColors,
229 const uno::Sequence< double >& rStops,
230 double nAspectRatio ) :
231 ParametricPolyPolygon_Base( m_aMutex ),
232 mxDevice( rDevice ),
233 maValues( rGradientPoly,
234 rColors,
235 rStops,
236 nAspectRatio,
237 eType )
241 ParametricPolyPolygon::ParametricPolyPolygon( const uno::Reference< rendering::XGraphicDevice >& rDevice,
242 GradientType eType,
243 const uno::Sequence< uno::Sequence< double > >& rColors,
244 const uno::Sequence< double >& rStops ) :
245 ParametricPolyPolygon_Base( m_aMutex ),
246 mxDevice( rDevice ),
247 maValues( ::basegfx::B2DPolygon(),
248 rColors,
249 rStops,
250 1.0,
251 eType )
255 ParametricPolyPolygon::Values ParametricPolyPolygon::getValues() const
257 ::osl::MutexGuard aGuard( m_aMutex );
259 return maValues;
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */