LibreOffice Module canvas (master) 1
parametricpolypolygon.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21
26
27#include <com/sun/star/rendering/XGraphicDevice.hpp>
28
29#include <parametricpolypolygon.hxx>
30#include <utility>
31
32using namespace ::com::sun::star;
33
34namespace canvas
35{
37 {
38 return {"LinearGradient",
39 "EllipticalGradient",
40 "RectangularGradient"};
41 }
42
44 const uno::Reference< rendering::XGraphicDevice >& rDevice,
45 std::u16string_view rServiceName,
46 const uno::Sequence< uno::Any >& rArgs )
47 {
48 double fAspectRatio=1.0;
49
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) })
54 };
55 uno::Sequence< double > colorStops{ 0, 1 };
56
57 // extract args
58 for( const uno::Any& rArg : rArgs )
59 {
60 beans::PropertyValue aProp;
61 if( rArg >>= aProp )
62 {
63 if ( aProp.Name == "Colors" )
64 {
65 aProp.Value >>= colorSequence;
66 }
67 else if ( aProp.Name == "Stops" )
68 {
69 aProp.Value >>= colorStops;
70 }
71 else if ( aProp.Name == "AspectRatio" )
72 {
73 aProp.Value >>= fAspectRatio;
74 }
75 }
76 }
77
78 if ( rServiceName == u"LinearGradient" )
79 {
80 return createLinearHorizontalGradient(rDevice, colorSequence, colorStops);
81 }
82 else if ( rServiceName == u"EllipticalGradient" )
83 {
84 return createEllipticalGradient(rDevice, colorSequence, colorStops, fAspectRatio);
85 }
86 else if ( rServiceName == u"RectangularGradient" )
87 {
88 return createRectangularGradient(rDevice, colorSequence, colorStops, fAspectRatio);
89 }
90 else if ( rServiceName == u"VerticalLineHatch" )
91 {
92 // TODO: NYI
93 }
94 else if ( rServiceName == u"OrthogonalLinesHatch" )
95 {
96 // TODO: NYI
97 }
98 else if ( rServiceName == u"ThreeCrossingLinesHatch" )
99 {
100 // TODO: NYI
101 }
102 else if ( rServiceName == u"FourCrossingLinesHatch" )
103 {
104 // TODO: NYI
105 }
106
107 return nullptr;
108 }
109
111 const uno::Reference< rendering::XGraphicDevice >& rDevice,
112 const uno::Sequence< uno::Sequence< double > >& colors,
113 const uno::Sequence< double >& stops )
114 {
115 // TODO(P2): hold gradient brush statically, and only setup
116 // the colors
117 return new ParametricPolyPolygon( rDevice, GradientType::Linear, colors, stops );
118 }
119
121 const uno::Reference< rendering::XGraphicDevice >& rDevice,
122 const uno::Sequence< uno::Sequence< double > >& colors,
123 const uno::Sequence< double >& stops,
124 double fAspectRatio )
125 {
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 ),
133 colors, stops, fAspectRatio );
134 }
135
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 )
140 {
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 ) ),
148 colors, stops, fAspectRatio );
149 }
150
151 void ParametricPolyPolygon::disposing(std::unique_lock<std::mutex>&)
152 {
153 mxDevice.clear();
154 }
155
156 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL ParametricPolyPolygon::getOutline( double /*t*/ )
157 {
158 // TODO(F1): outline NYI
159 return uno::Reference< rendering::XPolyPolygon2D >();
160 }
161
162 uno::Sequence< double > SAL_CALL ParametricPolyPolygon::getColor( double /*t*/ )
163 {
164 // TODO(F1): color NYI
165 return uno::Sequence< double >();
166 }
167
168 uno::Sequence< double > SAL_CALL ParametricPolyPolygon::getPointColor( const geometry::RealPoint2D& /*point*/ )
169 {
170 // TODO(F1): point color NYI
171 return uno::Sequence< double >();
172 }
173
174 uno::Reference< rendering::XColorSpace > SAL_CALL ParametricPolyPolygon::getColorSpace()
175 {
176 std::unique_lock aGuard( m_aMutex );
177
178 return mxDevice.is() ? mxDevice->getDeviceColorSpace() : uno::Reference< rendering::XColorSpace >();
179 }
180
181
183 {
184 return "Canvas::ParametricPolyPolygon";
185 }
186
187 sal_Bool SAL_CALL ParametricPolyPolygon::supportsService( const OUString& ServiceName )
188 {
190 }
191
192 uno::Sequence< OUString > SAL_CALL ParametricPolyPolygon::getSupportedServiceNames( )
193 {
194 return { "com.sun.star.rendering.ParametricPolyPolygon" };
195 }
196
198 {
199 }
200
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 )
213 {
214 }
215
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 )
226 {
227 }
228
230 {
231 std::unique_lock aGuard( m_aMutex );
232
233 return maValues;
234 }
235
236}
237
238/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ValueVectorType maValues
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Reference< css::rendering::XPolyPolygon2D > SAL_CALL getOutline(double t) override
Values getValues() const
Query all defining values of this object atomically.
static rtl::Reference< ParametricPolyPolygon > create(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, std::u16string_view rServiceName, const css::uno::Sequence< css::uno::Any > &rArgs)
virtual OUString SAL_CALL getImplementationName() override
css::uno::Reference< css::rendering::XGraphicDevice > mxDevice
virtual css::uno::Sequence< double > SAL_CALL getPointColor(const css::geometry::RealPoint2D &point) override
static rtl::Reference< ParametricPolyPolygon > createEllipticalGradient(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::uno::Sequence< css::uno::Sequence< double > > &colors, const css::uno::Sequence< double > &stops, double fAspect)
virtual css::uno::Sequence< double > SAL_CALL getColor(double t) override
virtual void disposing(std::unique_lock< std::mutex > &) override
Dispose all internal references.
static rtl::Reference< ParametricPolyPolygon > createLinearHorizontalGradient(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::uno::Sequence< css::uno::Sequence< double > > &colors, const css::uno::Sequence< double > &stops)
virtual css::uno::Reference< css::rendering::XColorSpace > SAL_CALL getColorSpace() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
static css::uno::Sequence< OUString > getAvailableServiceNames()
static rtl::Reference< ParametricPolyPolygon > createRectangularGradient(const css::uno::Reference< css::rendering::XGraphicDevice > &rDevice, const css::uno::Sequence< css::uno::Sequence< double > > &colors, const css::uno::Sequence< double > &stops, double fAspect)
const Values maValues
All defining values of this object.
ParametricPolyPolygon(const ParametricPolyPolygon &)=delete
float u
Definition: dx_9rm.cxx:192
DocumentType eType
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
GradientType
Structure of defining values for the ParametricPolyPolygon.
unsigned char sal_Bool