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 36 namespace basegfx 37 { 38 class B2DPolygon; 39 class B2DHomMatrix; 40 } 41 42 43 /* Definition of ParametricPolyPolygon class */ 44 45 namespace canvas 46 { 47 typedef ::cppu::WeakComponentImplHelper2< ::com::sun::star::rendering::XParametricPolyPolygon2D, 48 ::com::sun::star::lang::XServiceInfo > ParametricPolyPolygon_Base; 49 50 class ParametricPolyPolygon : public ::comphelper::OBaseMutex, 51 public ParametricPolyPolygon_Base, 52 private ::boost::noncopyable 53 { 54 public: 55 enum GradientType 56 { 57 GRADIENT_LINEAR, 58 GRADIENT_ELLIPTICAL, 59 GRADIENT_RECTANGULAR 60 }; 61 62 /** Structure of defining values for the ParametricPolyPolygon 63 64 This is used to copy the state of the 65 ParametricPolyPolygon atomically. 66 */ 67 struct Values 68 { Valuescanvas::ParametricPolyPolygon::Values69 Values( const ::basegfx::B2DPolygon& rGradientPoly, 70 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > >& rColors, 71 const ::com::sun::star::uno::Sequence< double >& rStops, 72 double nAspectRatio, 73 GradientType eType ) : 74 maGradientPoly( rGradientPoly ), 75 mnAspectRatio( nAspectRatio ), 76 maColors( rColors ), 77 maStops( rStops ), 78 meType( eType ) 79 { 80 } 81 82 /// Polygonal gradient shape (ignored for linear and axial gradient) 83 const ::basegfx::B2DPolygon maGradientPoly; 84 85 /// Aspect ratio of gradient, affects scaling of innermost gradient polygon 86 const double mnAspectRatio; 87 88 /// Gradient colors 89 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > > maColors; 90 91 /// Gradient color stops 92 const ::com::sun::star::uno::Sequence< double > maStops; 93 94 /// Type of gradient to render (as e.g. linear grads are not represented by maGradientPoly) 95 const GradientType meType; 96 }; 97 98 static ::com::sun::star::uno::Sequence< ::rtl::OUString > getAvailableServiceNames(); 99 static ParametricPolyPolygon* create( 100 const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice >& rDevice, 101 const ::rtl::OUString& rServiceName, 102 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rArgs ); 103 104 /// Dispose all internal references 105 virtual void SAL_CALL disposing(); 106 107 // XParametricPolyPolygon2D 108 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); 109 virtual ::com::sun::star::uno::Sequence< double > SAL_CALL getColor( double t ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); 110 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); 111 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XColorSpace > SAL_CALL getColorSpace() throw (::com::sun::star::uno::RuntimeException); 112 113 // XServiceInfo 114 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); 115 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); 116 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); 117 118 /// Query all defining values of this object atomically 119 Values getValues() const; 120 121 protected: 122 ~ParametricPolyPolygon(); // we're a ref-counted UNO class. _We_ destroy ourselves. 123 124 private: 125 static ParametricPolyPolygon* createLinearHorizontalGradient( const ::com::sun::star::uno::Reference< 126 ::com::sun::star::rendering::XGraphicDevice >& rDevice, 127 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > >& colors, 128 const ::com::sun::star::uno::Sequence< double >& stops ); 129 static ParametricPolyPolygon* createEllipticalGradient( const ::com::sun::star::uno::Reference< 130 ::com::sun::star::rendering::XGraphicDevice >& rDevice, 131 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > >& colors, 132 const ::com::sun::star::uno::Sequence< double >& stops, 133 double fAspect ); 134 static ParametricPolyPolygon* createRectangularGradient( const ::com::sun::star::uno::Reference< 135 ::com::sun::star::rendering::XGraphicDevice >& rDevice, 136 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > >& colors, 137 const ::com::sun::star::uno::Sequence< double >& stops, 138 double fAspect ); 139 140 /// Private, because objects can only be created from the static factories 141 ParametricPolyPolygon( const ::com::sun::star::uno::Reference< 142 ::com::sun::star::rendering::XGraphicDevice >& rDevice, 143 const ::basegfx::B2DPolygon& rGradientPoly, 144 GradientType eType, 145 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > >& colors, 146 const ::com::sun::star::uno::Sequence< double >& stops ); 147 ParametricPolyPolygon( const ::com::sun::star::uno::Reference< 148 ::com::sun::star::rendering::XGraphicDevice >& rDevice, 149 const ::basegfx::B2DPolygon& rGradientPoly, 150 GradientType eType, 151 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > >& colors, 152 const ::com::sun::star::uno::Sequence< double >& stops, 153 double nAspectRatio ); 154 ParametricPolyPolygon( const ::com::sun::star::uno::Reference< 155 ::com::sun::star::rendering::XGraphicDevice >& rDevice, 156 GradientType eType, 157 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > >& colors, 158 const ::com::sun::star::uno::Sequence< double >& stops ); 159 160 ::com::sun::star::uno::Reference< 161 ::com::sun::star::rendering::XGraphicDevice > mxDevice; 162 163 /// All defining values of this object 164 const Values maValues; 165 }; 166 } 167 168 #endif /* INCLUDED_CANVAS_PARAMETRICPOLYPOLYGON_HXX */ 169