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/fillgraphicprimitive2d.hxx>
28 #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
29 #include <basegfx/polygon/b2dpolygon.hxx>
30 #include <basegfx/polygon/b2dpolygontools.hxx>
31 #include <drawinglayer/texture/texture.hxx>
32 #include <basegfx/matrix/b2dhommatrixtools.hxx>
33 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
34 #include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
35 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
36 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
37 #include <drawinglayer/primitive2d/graphicprimitivehelper2d.hxx>
38 
39 //////////////////////////////////////////////////////////////////////////////
40 
41 using namespace com::sun::star;
42 
43 //////////////////////////////////////////////////////////////////////////////
44 
45 namespace drawinglayer
46 {
47 	namespace primitive2d
48 	{
create2DDecomposition(const geometry::ViewInformation2D &) const49 		Primitive2DSequence FillGraphicPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
50 		{
51 			Primitive2DSequence aRetval;
52 			const attribute::FillGraphicAttribute& rAttribute = getFillGraphic();
53 
54             if(!rAttribute.isDefault())
55             {
56                 const Graphic& rGraphic = rAttribute.getGraphic();
57 
58                 if(GRAPHIC_BITMAP == rGraphic.GetType() || GRAPHIC_GDIMETAFILE == rGraphic.GetType())
59                 {
60                     const Size aSize(rGraphic.GetPrefSize());
61 
62                     if(aSize.Width() && aSize.Height())
63                     {
64                         // we have a graphic (bitmap or metafile) with some size
65                         if(rAttribute.getTiling())
66                         {
67                             // get object range and create tiling matrices
68                             ::std::vector< basegfx::B2DHomMatrix > aMatrices;
69                             texture::GeoTexSvxTiled aTiling(
70                                 rAttribute.getGraphicRange(),
71                                 rAttribute.getOffsetX(),
72                                 rAttribute.getOffsetY());
73 
74                             // get matrices and realloc retval
75                             aTiling.appendTransformations(aMatrices);
76                             aRetval.realloc(aMatrices.size());
77 
78                             // prepare content primitive
79                             const Primitive2DSequence xSeq = create2DDecompositionOfGraphic(
80                                 rGraphic,
81                                 basegfx::B2DHomMatrix());
82 
83                             for(sal_uInt32 a(0); a < aMatrices.size(); a++)
84                             {
85                                 aRetval[a] = new TransformPrimitive2D(
86                                     getTransformation() * aMatrices[a],
87                                     xSeq);
88                             }
89                         }
90                         else
91                         {
92                             // add graphic without tiling
93                             const basegfx::B2DHomMatrix aObjectTransform(
94                                 getTransformation() * basegfx::tools::createScaleTranslateB2DHomMatrix(
95                                     rAttribute.getGraphicRange().getRange(),
96                                     rAttribute.getGraphicRange().getMinimum()));
97 
98                             aRetval = create2DDecompositionOfGraphic(
99                                 rGraphic,
100                                 aObjectTransform);
101                         }
102                     }
103                 }
104             }
105 
106 			return aRetval;
107 		}
108 
FillGraphicPrimitive2D(const basegfx::B2DHomMatrix & rTransformation,const attribute::FillGraphicAttribute & rFillGraphic)109 		FillGraphicPrimitive2D::FillGraphicPrimitive2D(
110 			const basegfx::B2DHomMatrix& rTransformation,
111 			const attribute::FillGraphicAttribute& rFillGraphic)
112 		:	BufferedDecompositionPrimitive2D(),
113 			maTransformation(rTransformation),
114 			maFillGraphic(rFillGraphic)
115 		{
116 		}
117 
operator ==(const BasePrimitive2D & rPrimitive) const118 		bool FillGraphicPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
119 		{
120 			if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
121 			{
122 				const FillGraphicPrimitive2D& rCompare = static_cast< const FillGraphicPrimitive2D& >(rPrimitive);
123 
124 				return (getTransformation() == rCompare.getTransformation()
125 					&& getFillGraphic() == rCompare.getFillGraphic());
126 			}
127 
128 			return false;
129 		}
130 
getB2DRange(const geometry::ViewInformation2D &) const131 		basegfx::B2DRange FillGraphicPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
132 		{
133 			// return range of it
134 			basegfx::B2DPolygon aPolygon(basegfx::tools::createUnitPolygon());
135 			aPolygon.transform(getTransformation());
136 
137             return basegfx::tools::getRange(aPolygon);
138 		}
139 
140 		// provide unique ID
141 		ImplPrimitrive2DIDBlock(FillGraphicPrimitive2D, PRIMITIVE2D_ID_FILLGRAPHICPRIMITIVE2D)
142 
143 	} // end of namespace primitive2d
144 } // end of namespace drawinglayer
145 
146 //////////////////////////////////////////////////////////////////////////////
147 // eof
148