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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_drawinglayer.hxx"
26 
27 #include <drawinglayer/primitive2d/patternfillprimitive2d.hxx>
28 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
29 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
30 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
31 #include <basegfx/polygon/b2dpolygontools.hxx>
32 #include <basegfx/matrix/b2dhommatrixtools.hxx>
33 #include <drawinglayer/texture/texture.hxx>
34 #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
35 
36 //////////////////////////////////////////////////////////////////////////////
37 
38 using namespace com::sun::star;
39 
40 //////////////////////////////////////////////////////////////////////////////
41 
42 namespace drawinglayer
43 {
44     namespace primitive2d
45     {
46         Primitive2DSequence PatternFillPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
47         {
48             Primitive2DSequence aRetval;
49 
50             if(getChildren().hasElements())
51             {
52                 if(!getReferenceRange().isEmpty() && getReferenceRange().getWidth() > 0.0 && getReferenceRange().getHeight() > 0.0)
53                 {
54                     const basegfx::B2DRange aMaskRange(getMask().getB2DRange());
55 
56                     if(!aMaskRange.isEmpty() && aMaskRange.getWidth() > 0.0 && aMaskRange.getHeight() > 0.0)
57                     {
58                         // create tiling matrices
59                         ::std::vector< basegfx::B2DHomMatrix > aMatrices;
60                         texture::GeoTexSvxTiled aTiling(getReferenceRange());
61 
62                         aTiling.appendTransformations(aMatrices);
63 
64                         // check if content needs to be clipped
65                         const basegfx::B2DRange aUnitRange(0.0, 0.0, 1.0, 1.0);
66                         const basegfx::B2DRange aContentRange(getB2DRangeFromPrimitive2DSequence(getChildren(), rViewInformation));
67                         Primitive2DSequence aContent(getChildren());
68 
69                         if(!aUnitRange.isInside(aContentRange))
70                         {
71                             const Primitive2DReference xRef(
72                                 new MaskPrimitive2D(
73                                     basegfx::B2DPolyPolygon(basegfx::tools::createPolygonFromRect(aUnitRange)),
74                                     aContent));
75 
76                             aContent = Primitive2DSequence(&xRef, 1);
77                         }
78 
79                         // resize result
80                         aRetval.realloc(aMatrices.size());
81 
82                         // create one primitive for each matrix
83                         for(sal_uInt32 a(0); a < aMatrices.size(); a++)
84                         {
85                             aRetval[a] = new TransformPrimitive2D(
86                                 aMatrices[a],
87                                 aContent);
88                         }
89 
90                         // transform result which is in unit coordinates to mask's object coordiantes
91                         {
92                             const basegfx::B2DHomMatrix aMaskTransform(
93                                 basegfx::tools::createScaleTranslateB2DHomMatrix(
94                                     aMaskRange.getRange(),
95                                     aMaskRange.getMinimum()));
96 
97                             const Primitive2DReference xRef(
98                                 new TransformPrimitive2D(
99                                     aMaskTransform,
100                                     aRetval));
101 
102                             aRetval = Primitive2DSequence(&xRef, 1);
103                         }
104 
105                         // embed result in mask
106                         {
107                             const Primitive2DReference xRef(
108                                 new MaskPrimitive2D(
109                                     getMask(),
110                                     aRetval));
111 
112                             aRetval = Primitive2DSequence(&xRef, 1);
113                         }
114 
115                     }
116                 }
117             }
118 
119             return aRetval;
120         }
121 
122         PatternFillPrimitive2D::PatternFillPrimitive2D(
123             const basegfx::B2DPolyPolygon& rMask,
124             const Primitive2DSequence& rChildren,
125             const basegfx::B2DRange& rReferenceRange)
126         :   BufferedDecompositionPrimitive2D(),
127             maMask(rMask),
128             maChildren(rChildren),
129             maReferenceRange(rReferenceRange)
130         {
131         }
132 
133         bool PatternFillPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
134         {
135             if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
136             {
137                 const PatternFillPrimitive2D& rCompare = static_cast< const PatternFillPrimitive2D& >(rPrimitive);
138 
139                 return (getMask() == rCompare.getMask()
140                     && getChildren() == rCompare.getChildren()
141                     && getReferenceRange() == rCompare.getReferenceRange());
142             }
143 
144             return false;
145         }
146 
147         basegfx::B2DRange PatternFillPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
148         {
149             return getMask().getB2DRange();
150         }
151 
152         // provide unique ID
153         ImplPrimitrive2DIDBlock(PatternFillPrimitive2D, PRIMITIVE2D_ID_PATTERNFILLPRIMITIVE2D)
154 
155     } // end of namespace primitive2d
156 } // end of namespace drawinglayer
157 
158 //////////////////////////////////////////////////////////////////////////////
159 // eof
160