1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: parametricpolypolygon.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_canvas.hxx"
34 #include <canvas/debug.hxx>
35 #include <canvas/canvastools.hxx>
37 #include <rtl/math.hxx>
39 #include <basegfx/matrix/b2dhommatrix.hxx>
40 #include <basegfx/polygon/b2dpolygontools.hxx>
41 #include <basegfx/point/b2dpoint.hxx>
42 #include <basegfx/range/b2drectangle.hxx>
43 #include <basegfx/tools/canvastools.hxx>
44 #include <basegfx/numeric/ftools.hxx>
45 #include <basegfx/tools/tools.hxx>
49 #include <canvas/parametricpolypolygon.hxx>
52 using namespace ::com::sun::star
;
56 ParametricPolyPolygon
* ParametricPolyPolygon::createLinearHorizontalGradient(
57 const uno::Reference
< rendering::XGraphicDevice
>& rDevice
,
58 const uno::Sequence
< uno::Sequence
< double > >& colors
,
59 const uno::Sequence
< double >& stops
)
61 // TODO(P2): hold gradient brush statically, and only setup
63 return new ParametricPolyPolygon( rDevice
, GRADIENT_LINEAR
, colors
, stops
);
66 ParametricPolyPolygon
* ParametricPolyPolygon::createAxialHorizontalGradient(
67 const uno::Reference
< rendering::XGraphicDevice
>& rDevice
,
68 const uno::Sequence
< uno::Sequence
< double > >& colors
,
69 const uno::Sequence
< double >& stops
)
71 // TODO(P2): hold gradient brush statically, and only setup
73 return new ParametricPolyPolygon( rDevice
, GRADIENT_AXIAL
, colors
, stops
);
78 double calcAspectRatio( const geometry::RealRectangle2D
& rBoundRect
)
80 const double nWidth( rBoundRect
.X2
- rBoundRect
.X1
);
81 const double nHeight( rBoundRect
.Y2
- rBoundRect
.Y1
);
83 return ::basegfx::fTools::equalZero( nHeight
) ? 1.0 : fabs( nWidth
/ nHeight
);
87 ParametricPolyPolygon
* ParametricPolyPolygon::createEllipticalGradient(
88 const uno::Reference
< rendering::XGraphicDevice
>& rDevice
,
89 const uno::Sequence
< uno::Sequence
< double > >& colors
,
90 const uno::Sequence
< double >& stops
,
91 const geometry::RealRectangle2D
& boundRect
)
93 // TODO(P2): hold gradient polygon statically, and only setup
95 return new ParametricPolyPolygon(
97 ::basegfx::tools::createPolygonFromCircle(
98 ::basegfx::B2DPoint( 0.5, 0.5), 0.5 ),
101 calcAspectRatio( boundRect
) );
104 ParametricPolyPolygon
* ParametricPolyPolygon::createRectangularGradient( const uno::Reference
< rendering::XGraphicDevice
>& rDevice
,
105 const uno::Sequence
< uno::Sequence
< double > >& colors
,
106 const uno::Sequence
< double >& stops
,
107 const geometry::RealRectangle2D
& boundRect
)
109 // TODO(P2): hold gradient polygon statically, and only setup
111 return new ParametricPolyPolygon(
113 ::basegfx::tools::createPolygonFromRect(
114 ::basegfx::B2DRectangle( 0.0, 0.0, 1.0, 1.0 ) ),
115 GRADIENT_RECTANGULAR
,
117 calcAspectRatio( boundRect
) );
120 void SAL_CALL
ParametricPolyPolygon::disposing()
122 ::osl::MutexGuard
aGuard( m_aMutex
);
127 uno::Reference
< rendering::XPolyPolygon2D
> SAL_CALL
ParametricPolyPolygon::getOutline( double /*t*/ ) throw (lang::IllegalArgumentException
, uno::RuntimeException
)
129 ::osl::MutexGuard
aGuard( m_aMutex
);
131 // TODO(F1): outline NYI
132 return uno::Reference
< rendering::XPolyPolygon2D
>();
135 uno::Sequence
< double > SAL_CALL
ParametricPolyPolygon::getColor( double /*t*/ ) throw (lang::IllegalArgumentException
, uno::RuntimeException
)
137 ::osl::MutexGuard
aGuard( m_aMutex
);
139 // TODO(F1): color NYI
140 return uno::Sequence
< double >();
143 uno::Sequence
< double > SAL_CALL
ParametricPolyPolygon::getPointColor( const geometry::RealPoint2D
& /*point*/ ) throw (lang::IllegalArgumentException
, uno::RuntimeException
)
145 ::osl::MutexGuard
aGuard( m_aMutex
);
147 // TODO(F1): point color NYI
148 return uno::Sequence
< double >();
151 uno::Reference
< rendering::XColorSpace
> SAL_CALL
ParametricPolyPolygon::getColorSpace() throw (uno::RuntimeException
)
153 ::osl::MutexGuard
aGuard( m_aMutex
);
155 return mxDevice
.is() ? mxDevice
->getDeviceColorSpace() : uno::Reference
< rendering::XColorSpace
>();
158 #define IMPLEMENTATION_NAME "Canvas::ParametricPolyPolygon"
159 #define SERVICE_NAME "com.sun.star.rendering.ParametricPolyPolygon"
161 ::rtl::OUString SAL_CALL
ParametricPolyPolygon::getImplementationName( ) throw (uno::RuntimeException
)
163 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME
) );
166 sal_Bool SAL_CALL
ParametricPolyPolygon::supportsService( const ::rtl::OUString
& ServiceName
) throw (uno::RuntimeException
)
168 return ServiceName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME
) );
171 uno::Sequence
< ::rtl::OUString
> SAL_CALL
ParametricPolyPolygon::getSupportedServiceNames( ) throw (uno::RuntimeException
)
173 uno::Sequence
< ::rtl::OUString
> aRet(1);
174 aRet
[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME
) );
179 ParametricPolyPolygon::~ParametricPolyPolygon()
183 ParametricPolyPolygon::ParametricPolyPolygon( const uno::Reference
< rendering::XGraphicDevice
>& rDevice
,
184 const ::basegfx::B2DPolygon
& rGradientPoly
,
186 const uno::Sequence
< uno::Sequence
< double > >& rColors
,
187 const uno::Sequence
< double >& rStops
) :
188 ParametricPolyPolygon_Base( m_aMutex
),
190 maValues( rGradientPoly
,
198 ParametricPolyPolygon::ParametricPolyPolygon( const uno::Reference
< rendering::XGraphicDevice
>& rDevice
,
199 const ::basegfx::B2DPolygon
& rGradientPoly
,
201 const uno::Sequence
< uno::Sequence
< double > >& rColors
,
202 const uno::Sequence
< double >& rStops
,
203 double nAspectRatio
) :
204 ParametricPolyPolygon_Base( m_aMutex
),
206 maValues( rGradientPoly
,
214 ParametricPolyPolygon::ParametricPolyPolygon( const uno::Reference
< rendering::XGraphicDevice
>& rDevice
,
216 const uno::Sequence
< uno::Sequence
< double > >& rColors
,
217 const uno::Sequence
< double >& rStops
) :
218 ParametricPolyPolygon_Base( m_aMutex
),
220 maValues( ::basegfx::B2DPolygon(),
228 ParametricPolyPolygon::Values
ParametricPolyPolygon::getValues() const
230 ::osl::MutexGuard
aGuard( m_aMutex
);