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_DRAWINGLAYER_PRIMITIVE2D_FILLGRADIENTPRIMITIVE2D_HXX
25 #define INCLUDED_DRAWINGLAYER_PRIMITIVE2D_FILLGRADIENTPRIMITIVE2D_HXX
26 
27 #include <drawinglayer/drawinglayerdllapi.h>
28 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
29 #include <drawinglayer/attribute/fillgradientattribute.hxx>
30 #include <drawinglayer/texture/texture.hxx>
31 
32 //////////////////////////////////////////////////////////////////////////////
33 // predefines
34 
35 namespace basegfx { class B2DPolygon; }
36 
37 //////////////////////////////////////////////////////////////////////////////
38 // FillGradientPrimitive2D class
39 
40 namespace drawinglayer
41 {
42 	namespace primitive2d
43 	{
44         /** FillGradientPrimitive2D class
45 
46             This class defines a gradient filling for a rectangular area. The
47             Range is defined by the Transformation, the gradient by the FillGradientAttribute.
48 
49             The decomposition will deliver the decomposed gradient, e.g. for an ellipse
50             gradient the various ellipses in various color steps will be created.
51 
52             I have added functionality to create both versions of filled decompositions:
53             Those who overlap and non-overlapping ones. The overlapping version is the
54             default one since it works with and without AntiAliasing. The non-overlapping
55             version is used in the MetafilePrimitive2D decomposition when the old XOR
56             paint was recorded.
57          */
58         class DRAWINGLAYER_DLLPUBLIC FillGradientPrimitive2D : public BufferedDecompositionPrimitive2D
59         {
60         private:
61             /// the geometrically visible area
62             basegfx::B2DRange                       maOutputRange;
63 
64             /// the area the gradient definition is based on
65             /// in the simplest case identical to OutputRange
66             basegfx::B2DRange                       maDefinitionRange;
67 
68             /// the gradient definition
69             attribute::FillGradientAttribute        maFillGradient;
70 
71             /// local helpers
72             void generateMatricesAndColors(
73                 std::vector< drawinglayer::texture::B2DHomMatrixAndBColor >& rEntries,
74                 basegfx::BColor& rOuterColor) const;
75             Primitive2DSequence createOverlappingFill(
76                 const std::vector< drawinglayer::texture::B2DHomMatrixAndBColor >& rEntries,
77                 const basegfx::BColor& rOuterColor,
78                 const basegfx::B2DPolygon& rUnitPolygon) const;
79             Primitive2DSequence createNonOverlappingFill(
80                 const std::vector< drawinglayer::texture::B2DHomMatrixAndBColor >& rEntries,
81                 const basegfx::BColor& rOuterColor,
82                 const basegfx::B2DPolygon& rUnitPolygon) const;
83 
84         protected:
85             /// local helper
86             Primitive2DSequence createFill(bool bOverlapping) const;
87 
88             /// local decomposition.
89             virtual Primitive2DSequence create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const;
90 
91         public:
92             /// constructors. The one without definition range will use output range as definition range
93             FillGradientPrimitive2D(
94                 const basegfx::B2DRange& rOutputRange,
95                 const attribute::FillGradientAttribute& rFillGradient);
96             FillGradientPrimitive2D(
97                 const basegfx::B2DRange& rOutputRange,
98                 const basegfx::B2DRange& rDefinitionRange,
99                 const attribute::FillGradientAttribute& rFillGradient);
100 
101             /// data read access
getOutputRange() const102             const basegfx::B2DRange& getOutputRange() const { return maOutputRange; }
getDefinitionRange() const103             const basegfx::B2DRange& getDefinitionRange() const { return maDefinitionRange; }
getFillGradient() const104             const attribute::FillGradientAttribute& getFillGradient() const { return maFillGradient; }
105 
106             /// compare operator
107             virtual bool operator==(const BasePrimitive2D& rPrimitive) const;
108 
109             /// get range
110             virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D& rViewInformation) const;
111 
112             /// provide unique ID
113             DeclPrimitrive2DIDBlock()
114         };
115     } // end of namespace primitive2d
116 } // end of namespace drawinglayer
117 
118 //////////////////////////////////////////////////////////////////////////////
119 
120 #endif //INCLUDED_DRAWINGLAYER_PRIMITIVE2D_FILLGRADIENTPRIMITIVE2D_HXX
121 
122 //////////////////////////////////////////////////////////////////////////////
123 // eof
124