1*ddde725dSArmin Le Grand /**************************************************************
2*ddde725dSArmin Le Grand  *
3*ddde725dSArmin Le Grand  * Licensed to the Apache Software Foundation (ASF) under one
4*ddde725dSArmin Le Grand  * or more contributor license agreements.  See the NOTICE file
5*ddde725dSArmin Le Grand  * distributed with this work for additional information
6*ddde725dSArmin Le Grand  * regarding copyright ownership.  The ASF licenses this file
7*ddde725dSArmin Le Grand  * to you under the Apache License, Version 2.0 (the
8*ddde725dSArmin Le Grand  * "License"); you may not use this file except in compliance
9*ddde725dSArmin Le Grand  * with the License.  You may obtain a copy of the License at
10*ddde725dSArmin Le Grand  *
11*ddde725dSArmin Le Grand  *   http://www.apache.org/licenses/LICENSE-2.0
12*ddde725dSArmin Le Grand  *
13*ddde725dSArmin Le Grand  * Unless required by applicable law or agreed to in writing,
14*ddde725dSArmin Le Grand  * software distributed under the License is distributed on an
15*ddde725dSArmin Le Grand  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ddde725dSArmin Le Grand  * KIND, either express or implied.  See the License for the
17*ddde725dSArmin Le Grand  * specific language governing permissions and limitations
18*ddde725dSArmin Le Grand  * under the License.
19*ddde725dSArmin Le Grand  *
20*ddde725dSArmin Le Grand  *************************************************************/
21*ddde725dSArmin Le Grand 
22*ddde725dSArmin Le Grand 
23*ddde725dSArmin Le Grand 
24*ddde725dSArmin Le Grand // MARKER(update_precomp.py): autogen include statement, do not remove
25*ddde725dSArmin Le Grand #include "precompiled_drawinglayer.hxx"
26*ddde725dSArmin Le Grand 
27*ddde725dSArmin Le Grand #include <drawinglayer/primitive2d/patternfillprimitive2d.hxx>
28*ddde725dSArmin Le Grand #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
29*ddde725dSArmin Le Grand #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
30*ddde725dSArmin Le Grand #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
31*ddde725dSArmin Le Grand #include <basegfx/polygon/b2dpolygontools.hxx>
32*ddde725dSArmin Le Grand #include <basegfx/matrix/b2dhommatrixtools.hxx>
33*ddde725dSArmin Le Grand #include <drawinglayer/texture/texture.hxx>
34*ddde725dSArmin Le Grand #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
35*ddde725dSArmin Le Grand 
36*ddde725dSArmin Le Grand //////////////////////////////////////////////////////////////////////////////
37*ddde725dSArmin Le Grand 
38*ddde725dSArmin Le Grand using namespace com::sun::star;
39*ddde725dSArmin Le Grand 
40*ddde725dSArmin Le Grand //////////////////////////////////////////////////////////////////////////////
41*ddde725dSArmin Le Grand 
42*ddde725dSArmin Le Grand namespace drawinglayer
43*ddde725dSArmin Le Grand {
44*ddde725dSArmin Le Grand     namespace primitive2d
45*ddde725dSArmin Le Grand     {
46*ddde725dSArmin Le Grand         Primitive2DSequence PatternFillPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
47*ddde725dSArmin Le Grand         {
48*ddde725dSArmin Le Grand             Primitive2DSequence aRetval;
49*ddde725dSArmin Le Grand 
50*ddde725dSArmin Le Grand             if(getChildren().hasElements())
51*ddde725dSArmin Le Grand             {
52*ddde725dSArmin Le Grand                 if(!getReferenceRange().isEmpty() && getReferenceRange().getWidth() > 0.0 && getReferenceRange().getHeight() > 0.0)
53*ddde725dSArmin Le Grand                 {
54*ddde725dSArmin Le Grand                     const basegfx::B2DRange aMaskRange(getMask().getB2DRange());
55*ddde725dSArmin Le Grand 
56*ddde725dSArmin Le Grand                     if(!aMaskRange.isEmpty() && aMaskRange.getWidth() > 0.0 && aMaskRange.getHeight() > 0.0)
57*ddde725dSArmin Le Grand                     {
58*ddde725dSArmin Le Grand                         // create tiling matrices
59*ddde725dSArmin Le Grand                         ::std::vector< basegfx::B2DHomMatrix > aMatrices;
60*ddde725dSArmin Le Grand                         texture::GeoTexSvxTiled aTiling(getReferenceRange().getMinimum(), getReferenceRange().getRange());
61*ddde725dSArmin Le Grand                         aTiling.appendTransformations(aMatrices);
62*ddde725dSArmin Le Grand 
63*ddde725dSArmin Le Grand                         // check if content needs to be clipped
64*ddde725dSArmin Le Grand                         const basegfx::B2DRange aUnitRange(0.0, 0.0, 1.0, 1.0);
65*ddde725dSArmin Le Grand                         const basegfx::B2DRange aContentRange(getB2DRangeFromPrimitive2DSequence(getChildren(), rViewInformation));
66*ddde725dSArmin Le Grand                         Primitive2DSequence aContent(getChildren());
67*ddde725dSArmin Le Grand 
68*ddde725dSArmin Le Grand                         if(!aUnitRange.isInside(aContentRange))
69*ddde725dSArmin Le Grand                         {
70*ddde725dSArmin Le Grand                             const Primitive2DReference xRef(
71*ddde725dSArmin Le Grand                                 new MaskPrimitive2D(
72*ddde725dSArmin Le Grand                                     basegfx::B2DPolyPolygon(basegfx::tools::createPolygonFromRect(aUnitRange)),
73*ddde725dSArmin Le Grand                                     aContent));
74*ddde725dSArmin Le Grand 
75*ddde725dSArmin Le Grand                             aContent = Primitive2DSequence(&xRef, 1);
76*ddde725dSArmin Le Grand                         }
77*ddde725dSArmin Le Grand 
78*ddde725dSArmin Le Grand                         // resize result
79*ddde725dSArmin Le Grand                         aRetval.realloc(aMatrices.size());
80*ddde725dSArmin Le Grand 
81*ddde725dSArmin Le Grand                         // create one primitive for each matrix
82*ddde725dSArmin Le Grand                         for(sal_uInt32 a(0); a < aMatrices.size(); a++)
83*ddde725dSArmin Le Grand                         {
84*ddde725dSArmin Le Grand                             aRetval[a] = new TransformPrimitive2D(
85*ddde725dSArmin Le Grand                                 aMatrices[a],
86*ddde725dSArmin Le Grand                                 aContent);
87*ddde725dSArmin Le Grand                         }
88*ddde725dSArmin Le Grand 
89*ddde725dSArmin Le Grand                         // transform result which is in unit coordinates to mask's object coordiantes
90*ddde725dSArmin Le Grand                         {
91*ddde725dSArmin Le Grand                             const basegfx::B2DHomMatrix aMaskTransform(
92*ddde725dSArmin Le Grand                                 basegfx::tools::createScaleTranslateB2DHomMatrix(
93*ddde725dSArmin Le Grand                                     aMaskRange.getRange(),
94*ddde725dSArmin Le Grand                                     aMaskRange.getMinimum()));
95*ddde725dSArmin Le Grand 
96*ddde725dSArmin Le Grand                             const Primitive2DReference xRef(
97*ddde725dSArmin Le Grand                                 new TransformPrimitive2D(
98*ddde725dSArmin Le Grand                                     aMaskTransform,
99*ddde725dSArmin Le Grand                                     aRetval));
100*ddde725dSArmin Le Grand 
101*ddde725dSArmin Le Grand                             aRetval = Primitive2DSequence(&xRef, 1);
102*ddde725dSArmin Le Grand                         }
103*ddde725dSArmin Le Grand 
104*ddde725dSArmin Le Grand                         // embed result in mask
105*ddde725dSArmin Le Grand                         {
106*ddde725dSArmin Le Grand                             const Primitive2DReference xRef(
107*ddde725dSArmin Le Grand                                 new MaskPrimitive2D(
108*ddde725dSArmin Le Grand                                     getMask(),
109*ddde725dSArmin Le Grand                                     aRetval));
110*ddde725dSArmin Le Grand 
111*ddde725dSArmin Le Grand                             aRetval = Primitive2DSequence(&xRef, 1);
112*ddde725dSArmin Le Grand                         }
113*ddde725dSArmin Le Grand 
114*ddde725dSArmin Le Grand                     }
115*ddde725dSArmin Le Grand                 }
116*ddde725dSArmin Le Grand             }
117*ddde725dSArmin Le Grand 
118*ddde725dSArmin Le Grand             return aRetval;
119*ddde725dSArmin Le Grand         }
120*ddde725dSArmin Le Grand 
121*ddde725dSArmin Le Grand         PatternFillPrimitive2D::PatternFillPrimitive2D(
122*ddde725dSArmin Le Grand             const basegfx::B2DPolyPolygon& rMask,
123*ddde725dSArmin Le Grand             const Primitive2DSequence& rChildren,
124*ddde725dSArmin Le Grand             const basegfx::B2DRange& rReferenceRange)
125*ddde725dSArmin Le Grand         :   BufferedDecompositionPrimitive2D(),
126*ddde725dSArmin Le Grand             maMask(rMask),
127*ddde725dSArmin Le Grand             maChildren(rChildren),
128*ddde725dSArmin Le Grand             maReferenceRange(rReferenceRange)
129*ddde725dSArmin Le Grand         {
130*ddde725dSArmin Le Grand         }
131*ddde725dSArmin Le Grand 
132*ddde725dSArmin Le Grand         bool PatternFillPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
133*ddde725dSArmin Le Grand         {
134*ddde725dSArmin Le Grand             if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
135*ddde725dSArmin Le Grand             {
136*ddde725dSArmin Le Grand                 const PatternFillPrimitive2D& rCompare = static_cast< const PatternFillPrimitive2D& >(rPrimitive);
137*ddde725dSArmin Le Grand 
138*ddde725dSArmin Le Grand                 return (getMask() == rCompare.getMask()
139*ddde725dSArmin Le Grand                     && getChildren() == rCompare.getChildren()
140*ddde725dSArmin Le Grand                     && getReferenceRange() == rCompare.getReferenceRange());
141*ddde725dSArmin Le Grand             }
142*ddde725dSArmin Le Grand 
143*ddde725dSArmin Le Grand             return false;
144*ddde725dSArmin Le Grand         }
145*ddde725dSArmin Le Grand 
146*ddde725dSArmin Le Grand         basegfx::B2DRange PatternFillPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
147*ddde725dSArmin Le Grand         {
148*ddde725dSArmin Le Grand             return getMask().getB2DRange();
149*ddde725dSArmin Le Grand         }
150*ddde725dSArmin Le Grand 
151*ddde725dSArmin Le Grand         // provide unique ID
152*ddde725dSArmin Le Grand         ImplPrimitrive2DIDBlock(PatternFillPrimitive2D, PRIMITIVE2D_ID_PATTERNFILLPRIMITIVE2D)
153*ddde725dSArmin Le Grand 
154*ddde725dSArmin Le Grand     } // end of namespace primitive2d
155*ddde725dSArmin Le Grand } // end of namespace drawinglayer
156*ddde725dSArmin Le Grand 
157*ddde725dSArmin Le Grand //////////////////////////////////////////////////////////////////////////////
158*ddde725dSArmin Le Grand // eof
159