1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef INCLUDED_CANVAS_PARAMETRICPOLYPOLYGON_HXX
25 #define INCLUDED_CANVAS_PARAMETRICPOLYPOLYGON_HXX
26 
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/rendering/XGraphicDevice.hpp>
29 #include <com/sun/star/rendering/XParametricPolyPolygon2D.hpp>
30 #include <cppuhelper/compbase2.hxx>
31 #include <comphelper/broadcasthelper.hxx>
32 #include <basegfx/polygon/b2dpolygon.hxx>
33 
34 #include <boost/utility.hpp>
35 #include <canvas/canvastoolsdllapi.h>
36 
37 namespace basegfx
38 {
39     class B2DPolygon;
40     class B2DHomMatrix;
41 }
42 
43 
44 /* Definition of ParametricPolyPolygon class */
45 
46 namespace canvas
47 {
48     typedef ::cppu::WeakComponentImplHelper2< ::com::sun::star::rendering::XParametricPolyPolygon2D,
49             		   			  		      ::com::sun::star::lang::XServiceInfo > ParametricPolyPolygon_Base;
50 
51     class CANVASTOOLS_DLLPUBLIC ParametricPolyPolygon : public ::comphelper::OBaseMutex,
52                                   public ParametricPolyPolygon_Base,
53 							      private ::boost::noncopyable
54     {
55     public:
56         enum GradientType
57         {
58             GRADIENT_LINEAR,
59             GRADIENT_ELLIPTICAL,
60             GRADIENT_RECTANGULAR
61         };
62 
63         /** Structure of defining values for the ParametricPolyPolygon
64 
65             This is used to copy the state of the
66             ParametricPolyPolygon atomically.
67          */
68         struct Values
69         {
Valuescanvas::ParametricPolyPolygon::Values70             Values( const ::basegfx::B2DPolygon&                        rGradientPoly,
71                     const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > >&	rColors,
72                     const ::com::sun::star::uno::Sequence< double >&	rStops,
73                     double                                              nAspectRatio,
74                     GradientType                                        eType ) :
75                 maGradientPoly( rGradientPoly ),
76                 mnAspectRatio( nAspectRatio ),
77                 maColors( rColors ),
78                 maStops( rStops ),
79                 meType( eType )
80             {
81             }
82 
83             /// Polygonal gradient shape (ignored for linear and axial gradient)
84             const ::basegfx::B2DPolygon							maGradientPoly;
85 
86             /// Aspect ratio of gradient, affects scaling of innermost gradient polygon
87             const double										mnAspectRatio;
88 
89             /// Gradient colors
90             const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > >		maColors;
91 
92             /// Gradient color stops
93             const ::com::sun::star::uno::Sequence< double >		maStops;
94 
95             /// Type of gradient to render (as e.g. linear grads are not represented by maGradientPoly)
96             const GradientType									meType;
97         };
98 
99         static ::com::sun::star::uno::Sequence< ::rtl::OUString > getAvailableServiceNames();
100         static ParametricPolyPolygon* create(
101             const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice >& rDevice,
102             const ::rtl::OUString& rServiceName,
103             const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rArgs );
104 
105         /// Dispose all internal references
106         virtual void SAL_CALL disposing();
107 
108         // XParametricPolyPolygon2D
109         virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D > SAL_CALL getOutline( double t ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
110         virtual ::com::sun::star::uno::Sequence< double > SAL_CALL getColor( double t ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
111         virtual ::com::sun::star::uno::Sequence< double > SAL_CALL getPointColor( const ::com::sun::star::geometry::RealPoint2D& point ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
112 	    virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XColorSpace > SAL_CALL getColorSpace() throw (::com::sun::star::uno::RuntimeException);
113 
114         // XServiceInfo
115         virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException);
116         virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
117         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (::com::sun::star::uno::RuntimeException);
118 
119         /// Query all defining values of this object atomically
120         Values getValues() const;
121 
122     protected:
123         ~ParametricPolyPolygon(); // we're a ref-counted UNO class. _We_ destroy ourselves.
124 
125     private:
126         static ParametricPolyPolygon* createLinearHorizontalGradient( const ::com::sun::star::uno::Reference<
127                                                                          ::com::sun::star::rendering::XGraphicDevice >& rDevice,
128                                                                       const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > >& colors,
129                                                                       const ::com::sun::star::uno::Sequence< double >& stops );
130         static ParametricPolyPolygon* createEllipticalGradient( const ::com::sun::star::uno::Reference<
131                                                                    ::com::sun::star::rendering::XGraphicDevice >& rDevice,
132                                                                 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > >& colors,
133                                                                 const ::com::sun::star::uno::Sequence< double >& stops,
134                                                                 double fAspect );
135         static ParametricPolyPolygon* createRectangularGradient( const ::com::sun::star::uno::Reference<
136                                                                     ::com::sun::star::rendering::XGraphicDevice >& rDevice,
137                                                                  const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > >& colors,
138                                                                  const ::com::sun::star::uno::Sequence< double >& stops,
139                                                                  double fAspect );
140 
141         /// Private, because objects can only be created from the static factories
142         ParametricPolyPolygon( const ::com::sun::star::uno::Reference<
143                                	::com::sun::star::rendering::XGraphicDevice >& 	rDevice,
144                                const ::basegfx::B2DPolygon& 					rGradientPoly,
145                                GradientType	  									eType,
146                                const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > >& 	colors,
147                                const ::com::sun::star::uno::Sequence< double >& 	stops );
148         ParametricPolyPolygon( const ::com::sun::star::uno::Reference<
149                                	::com::sun::star::rendering::XGraphicDevice >& 	rDevice,
150                                const ::basegfx::B2DPolygon& 					rGradientPoly,
151                                GradientType	  									eType,
152                                const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > >& 	colors,
153                                const ::com::sun::star::uno::Sequence< double >& 	stops,
154                                double											nAspectRatio );
155         ParametricPolyPolygon( const ::com::sun::star::uno::Reference<
156                                	::com::sun::star::rendering::XGraphicDevice >& 	rDevice,
157                                GradientType	  									eType,
158                                const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > >& 	colors,
159                                const ::com::sun::star::uno::Sequence< double >& 	stops );
160 
161     	::com::sun::star::uno::Reference<
162 	        ::com::sun::star::rendering::XGraphicDevice > 	 mxDevice;
163 
164         /// All defining values of this object
165         const Values                                         maValues;
166     };
167 }
168 
169 #endif /* INCLUDED_CANVAS_PARAMETRICPOLYPOLYGON_HXX */
170