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