Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <canvas/debug.hxx>
31 : : #include <canvas/canvastools.hxx>
32 : :
33 : : #include <rtl/math.hxx>
34 : :
35 : : #include <basegfx/matrix/b2dhommatrix.hxx>
36 : : #include <basegfx/polygon/b2dpolygontools.hxx>
37 : : #include <basegfx/point/b2dpoint.hxx>
38 : : #include <basegfx/range/b2drectangle.hxx>
39 : : #include <basegfx/tools/canvastools.hxx>
40 : : #include <basegfx/numeric/ftools.hxx>
41 : : #include <basegfx/tools/tools.hxx>
42 : :
43 : : #include <limits>
44 : :
45 : : #include <canvas/parametricpolypolygon.hxx>
46 : :
47 : :
48 : : using namespace ::com::sun::star;
49 : :
50 : : namespace canvas
51 : : {
52 : 0 : uno::Sequence<rtl::OUString> ParametricPolyPolygon::getAvailableServiceNames()
53 : : {
54 : 0 : uno::Sequence<rtl::OUString> aRet(3);
55 [ # # ][ # # ]: 0 : aRet[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LinearGradient" ));
56 [ # # ][ # # ]: 0 : aRet[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EllipticalGradient" ));
57 [ # # ][ # # ]: 0 : aRet[2] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RectangularGradient" ));
58 : :
59 : 0 : return aRet;
60 : : }
61 : :
62 : 0 : ParametricPolyPolygon* ParametricPolyPolygon::create(
63 : : const uno::Reference< rendering::XGraphicDevice >& rDevice,
64 : : const ::rtl::OUString& rServiceName,
65 : : const uno::Sequence< uno::Any >& rArgs )
66 : : {
67 [ # # ]: 0 : uno::Sequence< uno::Sequence< double > > colorSequence(2);
68 [ # # ]: 0 : uno::Sequence< double > colorStops(2);
69 : 0 : double fAspectRatio=1.0;
70 : :
71 : : // defaults
72 [ # # ]: 0 : uno::Sequence< rendering::RGBColor > rgbColors(1);
73 [ # # ]: 0 : rgbColors[0] = rendering::RGBColor(0,0,0);
74 [ # # ][ # # ]: 0 : colorSequence[0] = rDevice->getDeviceColorSpace()->convertFromRGB(rgbColors);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
75 [ # # ]: 0 : rgbColors[0] = rendering::RGBColor(1,1,1);
76 [ # # ][ # # ]: 0 : colorSequence[1] = rDevice->getDeviceColorSpace()->convertFromRGB(rgbColors);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
77 [ # # ]: 0 : colorStops[0] = 0;
78 [ # # ]: 0 : colorStops[1] = 1;
79 : :
80 : : // extract args
81 [ # # ]: 0 : for( sal_Int32 i=0; i<rArgs.getLength(); ++i )
82 : : {
83 : 0 : beans::PropertyValue aProp;
84 [ # # ][ # # ]: 0 : if( (rArgs[i] >>= aProp) )
85 : : {
86 [ # # ]: 0 : if ( aProp.Name == "Colors" )
87 : : {
88 [ # # ]: 0 : aProp.Value >>= colorSequence;
89 : : }
90 [ # # ]: 0 : else if ( aProp.Name == "Stops" )
91 : : {
92 [ # # ]: 0 : aProp.Value >>= colorStops;
93 : : }
94 [ # # ]: 0 : else if ( aProp.Name == "AspectRatio" )
95 : : {
96 : 0 : aProp.Value >>= fAspectRatio;
97 : : }
98 : : }
99 : 0 : }
100 : :
101 [ # # ]: 0 : if ( rServiceName == "LinearGradient" )
102 : : {
103 [ # # ]: 0 : return createLinearHorizontalGradient(rDevice, colorSequence, colorStops);
104 : : }
105 [ # # ]: 0 : else if ( rServiceName == "EllipticalGradient" )
106 : : {
107 [ # # ]: 0 : return createEllipticalGradient(rDevice, colorSequence, colorStops, fAspectRatio);
108 : : }
109 [ # # ]: 0 : else if ( rServiceName == "RectangularGradient" )
110 : : {
111 [ # # ]: 0 : return createRectangularGradient(rDevice, colorSequence, colorStops, fAspectRatio);
112 : : }
113 [ # # ]: 0 : else if ( rServiceName == "VerticalLineHatch" )
114 : : {
115 : : // TODO: NYI
116 : : }
117 [ # # ]: 0 : else if ( rServiceName == "OrthogonalLinesHatch" )
118 : : {
119 : : // TODO: NYI
120 : : }
121 [ # # ]: 0 : else if ( rServiceName == "ThreeCrossingLinesHatch" )
122 : : {
123 : : // TODO: NYI
124 : : }
125 : 0 : else if ( rServiceName == "FourCrossingLinesHatch" )
126 : : {
127 : : // TODO: NYI
128 : : }
129 : :
130 [ # # ][ # # ]: 0 : return NULL;
[ # # ]
131 : : }
132 : :
133 : 0 : ParametricPolyPolygon* ParametricPolyPolygon::createLinearHorizontalGradient(
134 : : const uno::Reference< rendering::XGraphicDevice >& rDevice,
135 : : const uno::Sequence< uno::Sequence< double > >& colors,
136 : : const uno::Sequence< double >& stops )
137 : : {
138 : : // TODO(P2): hold gradient brush statically, and only setup
139 : : // the colors
140 [ # # ]: 0 : return new ParametricPolyPolygon( rDevice, GRADIENT_LINEAR, colors, stops );
141 : : }
142 : :
143 : 0 : ParametricPolyPolygon* ParametricPolyPolygon::createEllipticalGradient(
144 : : const uno::Reference< rendering::XGraphicDevice >& rDevice,
145 : : const uno::Sequence< uno::Sequence< double > >& colors,
146 : : const uno::Sequence< double >& stops,
147 : : double fAspectRatio )
148 : : {
149 : : // TODO(P2): hold gradient polygon statically, and only setup
150 : : // the colors
151 : : return new ParametricPolyPolygon(
152 : : rDevice,
153 : : ::basegfx::tools::createPolygonFromCircle(
154 : : ::basegfx::B2DPoint(0,0), 1 ),
155 : : GRADIENT_ELLIPTICAL,
156 [ # # ][ # # ]: 0 : colors, stops, fAspectRatio );
[ # # ]
157 : : }
158 : :
159 : 0 : ParametricPolyPolygon* ParametricPolyPolygon::createRectangularGradient( const uno::Reference< rendering::XGraphicDevice >& rDevice,
160 : : const uno::Sequence< uno::Sequence< double > >& colors,
161 : : const uno::Sequence< double >& stops,
162 : : double fAspectRatio )
163 : : {
164 : : // TODO(P2): hold gradient polygon statically, and only setup
165 : : // the colors
166 : : return new ParametricPolyPolygon(
167 : : rDevice,
168 : : ::basegfx::tools::createPolygonFromRect(
169 : : ::basegfx::B2DRectangle( -1, -1, 1, 1 ) ),
170 : : GRADIENT_RECTANGULAR,
171 [ # # ][ # # ]: 0 : colors, stops, fAspectRatio );
[ # # ]
172 : : }
173 : :
174 : 0 : void SAL_CALL ParametricPolyPolygon::disposing()
175 : : {
176 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
177 : :
178 [ # # ]: 0 : mxDevice.clear();
179 : 0 : }
180 : :
181 : 0 : uno::Reference< rendering::XPolyPolygon2D > SAL_CALL ParametricPolyPolygon::getOutline( double /*t*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException)
182 : : {
183 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
184 : :
185 : : // TODO(F1): outline NYI
186 [ # # ]: 0 : return uno::Reference< rendering::XPolyPolygon2D >();
187 : : }
188 : :
189 : 0 : uno::Sequence< double > SAL_CALL ParametricPolyPolygon::getColor( double /*t*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException)
190 : : {
191 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
192 : :
193 : : // TODO(F1): color NYI
194 [ # # ][ # # ]: 0 : return uno::Sequence< double >();
195 : : }
196 : :
197 : 0 : uno::Sequence< double > SAL_CALL ParametricPolyPolygon::getPointColor( const geometry::RealPoint2D& /*point*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException)
198 : : {
199 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
200 : :
201 : : // TODO(F1): point color NYI
202 [ # # ][ # # ]: 0 : return uno::Sequence< double >();
203 : : }
204 : :
205 : 0 : uno::Reference< rendering::XColorSpace > SAL_CALL ParametricPolyPolygon::getColorSpace() throw (uno::RuntimeException)
206 : : {
207 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
208 : :
209 [ # # ][ # # ]: 0 : return mxDevice.is() ? mxDevice->getDeviceColorSpace() : uno::Reference< rendering::XColorSpace >();
[ # # ][ # # ]
210 : : }
211 : :
212 : : #define IMPLEMENTATION_NAME "Canvas::ParametricPolyPolygon"
213 : : #define SERVICE_NAME "com.sun.star.rendering.ParametricPolyPolygon"
214 : :
215 : 0 : ::rtl::OUString SAL_CALL ParametricPolyPolygon::getImplementationName( ) throw (uno::RuntimeException)
216 : : {
217 : 0 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) );
218 : : }
219 : :
220 : 0 : sal_Bool SAL_CALL ParametricPolyPolygon::supportsService( const ::rtl::OUString& ServiceName ) throw (uno::RuntimeException)
221 : : {
222 : 0 : return ServiceName == SERVICE_NAME;
223 : : }
224 : :
225 : 0 : uno::Sequence< ::rtl::OUString > SAL_CALL ParametricPolyPolygon::getSupportedServiceNames( ) throw (uno::RuntimeException)
226 : : {
227 : 0 : uno::Sequence< ::rtl::OUString > aRet(1);
228 [ # # ][ # # ]: 0 : aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
229 : :
230 : 0 : return aRet;
231 : : }
232 : :
233 [ # # ][ # # ]: 0 : ParametricPolyPolygon::~ParametricPolyPolygon()
234 : : {
235 [ # # ]: 0 : }
236 : :
237 : 0 : ParametricPolyPolygon::ParametricPolyPolygon( const uno::Reference< rendering::XGraphicDevice >& rDevice,
238 : : const ::basegfx::B2DPolygon& rGradientPoly,
239 : : GradientType eType,
240 : : const uno::Sequence< uno::Sequence< double > >& rColors,
241 : : const uno::Sequence< double >& rStops,
242 : : double nAspectRatio ) :
243 : : ParametricPolyPolygon_Base( m_aMutex ),
244 : : mxDevice( rDevice ),
245 : : maValues( rGradientPoly,
246 : : rColors,
247 : : rStops,
248 : : nAspectRatio,
249 [ # # ]: 0 : eType )
250 : : {
251 : 0 : }
252 : :
253 : 0 : ParametricPolyPolygon::ParametricPolyPolygon( const uno::Reference< rendering::XGraphicDevice >& rDevice,
254 : : GradientType eType,
255 : : const uno::Sequence< uno::Sequence< double > >& rColors,
256 : : const uno::Sequence< double >& rStops ) :
257 : : ParametricPolyPolygon_Base( m_aMutex ),
258 : : mxDevice( rDevice ),
259 : : maValues( ::basegfx::B2DPolygon(),
260 : : rColors,
261 : : rStops,
262 : : 1.0,
263 [ # # ][ # # ]: 0 : eType )
[ # # ]
264 : : {
265 : 0 : }
266 : :
267 : 0 : ParametricPolyPolygon::Values ParametricPolyPolygon::getValues() const
268 : : {
269 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
270 : :
271 [ # # ][ # # ]: 0 : return maValues;
272 : : }
273 : :
274 : : }
275 : :
276 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|