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 
31 using namespace ::com::sun::star;
32 
33 namespace canvas
34 {
36  {
37  return {"LinearGradient",
38  "EllipticalGradient",
39  "RectangularGradient"};
40  }
41 
43  const uno::Reference< rendering::XGraphicDevice >& rDevice,
44  std::u16string_view rServiceName,
45  const uno::Sequence< uno::Any >& rArgs )
46  {
47  double fAspectRatio=1.0;
48 
49  // defaults
50  uno::Sequence< uno::Sequence< double > > colorSequence{
51  rDevice->getDeviceColorSpace()->convertFromRGB({ rendering::RGBColor(0,0,0) }),
52  rDevice->getDeviceColorSpace()->convertFromRGB({ rendering::RGBColor(1,1,1) })
53  };
54  uno::Sequence< double > colorStops{ 0, 1 };
55 
56  // extract args
57  for( const uno::Any& rArg : rArgs )
58  {
59  beans::PropertyValue aProp;
60  if( rArg >>= aProp )
61  {
62  if ( aProp.Name == "Colors" )
63  {
64  aProp.Value >>= colorSequence;
65  }
66  else if ( aProp.Name == "Stops" )
67  {
68  aProp.Value >>= colorStops;
69  }
70  else if ( aProp.Name == "AspectRatio" )
71  {
72  aProp.Value >>= fAspectRatio;
73  }
74  }
75  }
76 
77  if ( rServiceName == u"LinearGradient" )
78  {
79  return createLinearHorizontalGradient(rDevice, colorSequence, colorStops);
80  }
81  else if ( rServiceName == u"EllipticalGradient" )
82  {
83  return createEllipticalGradient(rDevice, colorSequence, colorStops, fAspectRatio);
84  }
85  else if ( rServiceName == u"RectangularGradient" )
86  {
87  return createRectangularGradient(rDevice, colorSequence, colorStops, fAspectRatio);
88  }
89  else if ( rServiceName == u"VerticalLineHatch" )
90  {
91  // TODO: NYI
92  }
93  else if ( rServiceName == u"OrthogonalLinesHatch" )
94  {
95  // TODO: NYI
96  }
97  else if ( rServiceName == u"ThreeCrossingLinesHatch" )
98  {
99  // TODO: NYI
100  }
101  else if ( rServiceName == u"FourCrossingLinesHatch" )
102  {
103  // TODO: NYI
104  }
105 
106  return nullptr;
107  }
108 
110  const uno::Reference< rendering::XGraphicDevice >& rDevice,
111  const uno::Sequence< uno::Sequence< double > >& colors,
112  const uno::Sequence< double >& stops )
113  {
114  // TODO(P2): hold gradient brush statically, and only setup
115  // the colors
116  return new ParametricPolyPolygon( rDevice, GradientType::Linear, colors, stops );
117  }
118 
120  const uno::Reference< rendering::XGraphicDevice >& rDevice,
121  const uno::Sequence< uno::Sequence< double > >& colors,
122  const uno::Sequence< double >& stops,
123  double fAspectRatio )
124  {
125  // TODO(P2): hold gradient polygon statically, and only setup
126  // the colors
127  return new ParametricPolyPolygon(
128  rDevice,
130  ::basegfx::B2DPoint(0,0), 1 ),
132  colors, stops, fAspectRatio );
133  }
134 
135  rtl::Reference<ParametricPolyPolygon> ParametricPolyPolygon::createRectangularGradient( const uno::Reference< rendering::XGraphicDevice >& rDevice,
136  const uno::Sequence< uno::Sequence< double > >& colors,
137  const uno::Sequence< double >& stops,
138  double fAspectRatio )
139  {
140  // TODO(P2): hold gradient polygon statically, and only setup
141  // the colors
142  return new ParametricPolyPolygon(
143  rDevice,
145  ::basegfx::B2DRectangle( -1, -1, 1, 1 ) ),
147  colors, stops, fAspectRatio );
148  }
149 
150  void ParametricPolyPolygon::disposing(std::unique_lock<std::mutex>&)
151  {
152  mxDevice.clear();
153  }
154 
155  uno::Reference< rendering::XPolyPolygon2D > SAL_CALL ParametricPolyPolygon::getOutline( double /*t*/ )
156  {
157  // TODO(F1): outline NYI
158  return uno::Reference< rendering::XPolyPolygon2D >();
159  }
160 
161  uno::Sequence< double > SAL_CALL ParametricPolyPolygon::getColor( double /*t*/ )
162  {
163  // TODO(F1): color NYI
164  return uno::Sequence< double >();
165  }
166 
167  uno::Sequence< double > SAL_CALL ParametricPolyPolygon::getPointColor( const geometry::RealPoint2D& /*point*/ )
168  {
169  // TODO(F1): point color NYI
170  return uno::Sequence< double >();
171  }
172 
173  uno::Reference< rendering::XColorSpace > SAL_CALL ParametricPolyPolygon::getColorSpace()
174  {
175  std::unique_lock aGuard( m_aMutex );
176 
177  return mxDevice.is() ? mxDevice->getDeviceColorSpace() : uno::Reference< rendering::XColorSpace >();
178  }
179 
180 
182  {
183  return "Canvas::ParametricPolyPolygon";
184  }
185 
186  sal_Bool SAL_CALL ParametricPolyPolygon::supportsService( const OUString& ServiceName )
187  {
188  return cppu::supportsService(this, ServiceName);
189  }
190 
191  uno::Sequence< OUString > SAL_CALL ParametricPolyPolygon::getSupportedServiceNames( )
192  {
193  return { "com.sun.star.rendering.ParametricPolyPolygon" };
194  }
195 
197  {
198  }
199 
200  ParametricPolyPolygon::ParametricPolyPolygon( const uno::Reference< rendering::XGraphicDevice >& rDevice,
201  const ::basegfx::B2DPolygon& rGradientPoly,
202  GradientType eType,
203  const uno::Sequence< uno::Sequence< double > >& rColors,
204  const uno::Sequence< double >& rStops,
205  double nAspectRatio ) :
206  mxDevice( rDevice ),
207  maValues( rGradientPoly,
208  rColors,
209  rStops,
210  nAspectRatio,
211  eType )
212  {
213  }
214 
215  ParametricPolyPolygon::ParametricPolyPolygon( const uno::Reference< rendering::XGraphicDevice >& rDevice,
216  GradientType eType,
217  const uno::Sequence< uno::Sequence< double > >& rColors,
218  const uno::Sequence< double >& rStops ) :
219  mxDevice( rDevice ),
220  maValues( ::basegfx::B2DPolygon(),
221  rColors,
222  rStops,
223  1.0,
224  eType )
225  {
226  }
227 
229  {
230  std::unique_lock aGuard( m_aMutex );
231 
232  return maValues;
233  }
234 
235 }
236 
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void disposing(std::unique_lock< std::mutex > &) override
Dispose all internal references.
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)
static css::uno::Sequence< OUString > getAvailableServiceNames()
ValueVectorType maValues
css::uno::Reference< css::rendering::XGraphicDevice > mxDevice
virtual css::uno::Reference< css::rendering::XColorSpace > SAL_CALL getColorSpace() override
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)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
ParametricPolyPolygon(const ParametricPolyPolygon &)=delete
B2DPolygon createPolygonFromCircle(const B2DPoint &rCenter, double fRadius)
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
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)
float u
Definition: dx_9rm.cxx:192
unsigned char sal_Bool
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
const Values maValues
All defining values of this object.
virtual css::uno::Reference< css::rendering::XPolyPolygon2D > SAL_CALL getOutline(double t) override
virtual css::uno::Sequence< double > SAL_CALL getColor(double t) override
virtual css::uno::Sequence< double > SAL_CALL getPointColor(const css::geometry::RealPoint2D &point) override
Structure of defining values for the ParametricPolyPolygon.
Values getValues() const
Query all defining values of this object atomically.
GradientType
virtual OUString SAL_CALL getImplementationName() override
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)