Move setting of LD_LIBRARY_PATH closer to invocation of cppunittester
[LibreOffice.git] / canvas / source / tools / parametricpolypolygon.cxx
blobcb948e095277ecaa1d9392ecd45d084d90ddba64
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 <sal/config.h>
22 #include <basegfx/point/b2dpoint.hxx>
23 #include <basegfx/polygon/b2dpolygontools.hxx>
24 #include <basegfx/range/b2drectangle.hxx>
25 #include <cppuhelper/supportsservice.hxx>
27 #include <com/sun/star/rendering/XGraphicDevice.hpp>
29 #include <parametricpolypolygon.hxx>
30 #include <utility>
32 using namespace ::com::sun::star;
34 namespace canvas
36 uno::Sequence<OUString> ParametricPolyPolygon::getAvailableServiceNames()
38 return {u"LinearGradient"_ustr,
39 u"EllipticalGradient"_ustr,
40 u"RectangularGradient"_ustr};
43 rtl::Reference<ParametricPolyPolygon> ParametricPolyPolygon::create(
44 const uno::Reference< rendering::XGraphicDevice >& rDevice,
45 std::u16string_view rServiceName,
46 const uno::Sequence< uno::Any >& rArgs )
48 double fAspectRatio=1.0;
50 // defaults
51 uno::Sequence< uno::Sequence< double > > colorSequence{
52 rDevice->getDeviceColorSpace()->convertFromRGB({ rendering::RGBColor(0,0,0) }),
53 rDevice->getDeviceColorSpace()->convertFromRGB({ rendering::RGBColor(1,1,1) })
55 uno::Sequence< double > colorStops{ 0, 1 };
57 // extract args
58 for( const uno::Any& rArg : rArgs )
60 beans::PropertyValue aProp;
61 if( rArg >>= aProp )
63 if ( aProp.Name == "Colors" )
65 aProp.Value >>= colorSequence;
67 else if ( aProp.Name == "Stops" )
69 aProp.Value >>= colorStops;
71 else if ( aProp.Name == "AspectRatio" )
73 aProp.Value >>= fAspectRatio;
78 if ( rServiceName == u"LinearGradient" )
80 return createLinearHorizontalGradient(rDevice, colorSequence, colorStops);
82 else if ( rServiceName == u"EllipticalGradient" )
84 return createEllipticalGradient(rDevice, colorSequence, colorStops, fAspectRatio);
86 else if ( rServiceName == u"RectangularGradient" )
88 return createRectangularGradient(rDevice, colorSequence, colorStops, fAspectRatio);
90 else if ( rServiceName == u"VerticalLineHatch" )
92 // TODO: NYI
94 else if ( rServiceName == u"OrthogonalLinesHatch" )
96 // TODO: NYI
98 else if ( rServiceName == u"ThreeCrossingLinesHatch" )
100 // TODO: NYI
102 else if ( rServiceName == u"FourCrossingLinesHatch" )
104 // TODO: NYI
107 return nullptr;
110 rtl::Reference<ParametricPolyPolygon> ParametricPolyPolygon::createLinearHorizontalGradient(
111 const uno::Reference< rendering::XGraphicDevice >& rDevice,
112 const uno::Sequence< uno::Sequence< double > >& colors,
113 const uno::Sequence< double >& stops )
115 // TODO(P2): hold gradient brush statically, and only setup
116 // the colors
117 return new ParametricPolyPolygon( rDevice, GradientType::Linear, colors, stops );
120 rtl::Reference<ParametricPolyPolygon> ParametricPolyPolygon::createEllipticalGradient(
121 const uno::Reference< rendering::XGraphicDevice >& rDevice,
122 const uno::Sequence< uno::Sequence< double > >& colors,
123 const uno::Sequence< double >& stops,
124 double fAspectRatio )
126 // TODO(P2): hold gradient polygon statically, and only setup
127 // the colors
128 return new ParametricPolyPolygon(
129 rDevice,
130 ::basegfx::utils::createPolygonFromCircle(
131 ::basegfx::B2DPoint(0,0), 1 ),
132 GradientType::Elliptical,
133 colors, stops, fAspectRatio );
136 rtl::Reference<ParametricPolyPolygon> ParametricPolyPolygon::createRectangularGradient( const uno::Reference< rendering::XGraphicDevice >& rDevice,
137 const uno::Sequence< uno::Sequence< double > >& colors,
138 const uno::Sequence< double >& stops,
139 double fAspectRatio )
141 // TODO(P2): hold gradient polygon statically, and only setup
142 // the colors
143 return new ParametricPolyPolygon(
144 rDevice,
145 ::basegfx::utils::createPolygonFromRect(
146 ::basegfx::B2DRectangle( -1, -1, 1, 1 ) ),
147 GradientType::Rectangular,
148 colors, stops, fAspectRatio );
151 void ParametricPolyPolygon::disposing(std::unique_lock<std::mutex>&)
153 mxDevice.clear();
156 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL ParametricPolyPolygon::getOutline( double /*t*/ )
158 // TODO(F1): outline NYI
159 return uno::Reference< rendering::XPolyPolygon2D >();
162 uno::Sequence< double > SAL_CALL ParametricPolyPolygon::getColor( double /*t*/ )
164 // TODO(F1): color NYI
165 return uno::Sequence< double >();
168 uno::Sequence< double > SAL_CALL ParametricPolyPolygon::getPointColor( const geometry::RealPoint2D& /*point*/ )
170 // TODO(F1): point color NYI
171 return uno::Sequence< double >();
174 uno::Reference< rendering::XColorSpace > SAL_CALL ParametricPolyPolygon::getColorSpace()
176 std::unique_lock aGuard( m_aMutex );
178 return mxDevice.is() ? mxDevice->getDeviceColorSpace() : uno::Reference< rendering::XColorSpace >();
182 OUString SAL_CALL ParametricPolyPolygon::getImplementationName( )
184 return u"Canvas::ParametricPolyPolygon"_ustr;
187 sal_Bool SAL_CALL ParametricPolyPolygon::supportsService( const OUString& ServiceName )
189 return cppu::supportsService(this, ServiceName);
192 uno::Sequence< OUString > SAL_CALL ParametricPolyPolygon::getSupportedServiceNames( )
194 return { u"com.sun.star.rendering.ParametricPolyPolygon"_ustr };
197 ParametricPolyPolygon::~ParametricPolyPolygon()
201 ParametricPolyPolygon::ParametricPolyPolygon( uno::Reference< rendering::XGraphicDevice > xDevice,
202 const ::basegfx::B2DPolygon& rGradientPoly,
203 GradientType eType,
204 const uno::Sequence< uno::Sequence< double > >& rColors,
205 const uno::Sequence< double >& rStops,
206 double nAspectRatio ) :
207 mxDevice(std::move( xDevice )),
208 maValues( rGradientPoly,
209 rColors,
210 rStops,
211 nAspectRatio,
212 eType )
216 ParametricPolyPolygon::ParametricPolyPolygon( uno::Reference< rendering::XGraphicDevice > xDevice,
217 GradientType eType,
218 const uno::Sequence< uno::Sequence< double > >& rColors,
219 const uno::Sequence< double >& rStops ) :
220 mxDevice(std::move( xDevice )),
221 maValues( ::basegfx::B2DPolygon(),
222 rColors,
223 rStops,
224 1.0,
225 eType )
229 const ParametricPolyPolygon::Values & ParametricPolyPolygon::getValues() const
231 return maValues;
236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */