1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
32 using namespace ::com::sun::star
;
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;
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 };
58 for( const uno::Any
& rArg
: rArgs
)
60 beans::PropertyValue 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" )
94 else if ( rServiceName
== u
"OrthogonalLinesHatch" )
98 else if ( rServiceName
== u
"ThreeCrossingLinesHatch" )
102 else if ( rServiceName
== u
"FourCrossingLinesHatch" )
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
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
128 return new ParametricPolyPolygon(
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
143 return new ParametricPolyPolygon(
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
>&)
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
,
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
,
216 ParametricPolyPolygon::ParametricPolyPolygon( uno::Reference
< rendering::XGraphicDevice
> xDevice
,
218 const uno::Sequence
< uno::Sequence
< double > >& rColors
,
219 const uno::Sequence
< double >& rStops
) :
220 mxDevice(std::move( xDevice
)),
221 maValues( ::basegfx::B2DPolygon(),
229 const ParametricPolyPolygon::Values
& ParametricPolyPolygon::getValues() const
236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */