1*035a2f44SArmin Le Grand /**************************************************************
2*035a2f44SArmin Le Grand  *
3*035a2f44SArmin Le Grand  * Licensed to the Apache Software Foundation (ASF) under one
4*035a2f44SArmin Le Grand  * or more contributor license agreements.  See the NOTICE file
5*035a2f44SArmin Le Grand  * distributed with this work for additional information
6*035a2f44SArmin Le Grand  * regarding copyright ownership.  The ASF licenses this file
7*035a2f44SArmin Le Grand  * to you under the Apache License, Version 2.0 (the
8*035a2f44SArmin Le Grand  * "License"); you may not use this file except in compliance
9*035a2f44SArmin Le Grand  * with the License.  You may obtain a copy of the License at
10*035a2f44SArmin Le Grand  *
11*035a2f44SArmin Le Grand  *   http://www.apache.org/licenses/LICENSE-2.0
12*035a2f44SArmin Le Grand  *
13*035a2f44SArmin Le Grand  * Unless required by applicable law or agreed to in writing,
14*035a2f44SArmin Le Grand  * software distributed under the License is distributed on an
15*035a2f44SArmin Le Grand  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*035a2f44SArmin Le Grand  * KIND, either express or implied.  See the License for the
17*035a2f44SArmin Le Grand  * specific language governing permissions and limitations
18*035a2f44SArmin Le Grand  * under the License.
19*035a2f44SArmin Le Grand  *
20*035a2f44SArmin Le Grand  *************************************************************/
21*035a2f44SArmin Le Grand 
22*035a2f44SArmin Le Grand 
23*035a2f44SArmin Le Grand 
24*035a2f44SArmin Le Grand // MARKER(update_precomp.py): autogen include statement, do not remove
25*035a2f44SArmin Le Grand #include "precompiled_drawinglayer.hxx"
26*035a2f44SArmin Le Grand 
27*035a2f44SArmin Le Grand #include <drawinglayer/primitive2d/fillgraphicprimitive2d.hxx>
28*035a2f44SArmin Le Grand #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
29*035a2f44SArmin Le Grand #include <basegfx/polygon/b2dpolygon.hxx>
30*035a2f44SArmin Le Grand #include <basegfx/polygon/b2dpolygontools.hxx>
31*035a2f44SArmin Le Grand #include <drawinglayer/texture/texture.hxx>
32*035a2f44SArmin Le Grand #include <basegfx/matrix/b2dhommatrixtools.hxx>
33*035a2f44SArmin Le Grand #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
34*035a2f44SArmin Le Grand #include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
35*035a2f44SArmin Le Grand #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
36*035a2f44SArmin Le Grand #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
37*035a2f44SArmin Le Grand #include <drawinglayer/primitive2d/graphicprimitivehelper2d.hxx>
38*035a2f44SArmin Le Grand 
39*035a2f44SArmin Le Grand //////////////////////////////////////////////////////////////////////////////
40*035a2f44SArmin Le Grand 
41*035a2f44SArmin Le Grand using namespace com::sun::star;
42*035a2f44SArmin Le Grand 
43*035a2f44SArmin Le Grand //////////////////////////////////////////////////////////////////////////////
44*035a2f44SArmin Le Grand 
45*035a2f44SArmin Le Grand namespace drawinglayer
46*035a2f44SArmin Le Grand {
47*035a2f44SArmin Le Grand 	namespace primitive2d
48*035a2f44SArmin Le Grand 	{
create2DDecomposition(const geometry::ViewInformation2D &) const49*035a2f44SArmin Le Grand 		Primitive2DSequence FillGraphicPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
50*035a2f44SArmin Le Grand 		{
51*035a2f44SArmin Le Grand 			Primitive2DSequence aRetval;
52*035a2f44SArmin Le Grand 			const attribute::FillGraphicAttribute& rAttribute = getFillGraphic();
53*035a2f44SArmin Le Grand 
54*035a2f44SArmin Le Grand             if(!rAttribute.isDefault())
55*035a2f44SArmin Le Grand             {
56*035a2f44SArmin Le Grand                 const Graphic& rGraphic = rAttribute.getGraphic();
57*035a2f44SArmin Le Grand 
58*035a2f44SArmin Le Grand                 if(GRAPHIC_BITMAP == rGraphic.GetType() || GRAPHIC_GDIMETAFILE == rGraphic.GetType())
59*035a2f44SArmin Le Grand                 {
60*035a2f44SArmin Le Grand                     const Size aSize(rGraphic.GetPrefSize());
61*035a2f44SArmin Le Grand 
62*035a2f44SArmin Le Grand                     if(aSize.Width() && aSize.Height())
63*035a2f44SArmin Le Grand                     {
64*035a2f44SArmin Le Grand                         // we have a graphic (bitmap or metafile) with some size
65*035a2f44SArmin Le Grand                         if(rAttribute.getTiling())
66*035a2f44SArmin Le Grand                         {
67*035a2f44SArmin Le Grand                             // get object range and create tiling matrices
68*035a2f44SArmin Le Grand                             ::std::vector< basegfx::B2DHomMatrix > aMatrices;
69*035a2f44SArmin Le Grand                             texture::GeoTexSvxTiled aTiling(
70*035a2f44SArmin Le Grand                                 rAttribute.getGraphicRange(),
71*035a2f44SArmin Le Grand                                 rAttribute.getOffsetX(),
72*035a2f44SArmin Le Grand                                 rAttribute.getOffsetY());
73*035a2f44SArmin Le Grand 
74*035a2f44SArmin Le Grand                             // get matrices and realloc retval
75*035a2f44SArmin Le Grand                             aTiling.appendTransformations(aMatrices);
76*035a2f44SArmin Le Grand                             aRetval.realloc(aMatrices.size());
77*035a2f44SArmin Le Grand 
78*035a2f44SArmin Le Grand                             // prepare content primitive
79*035a2f44SArmin Le Grand                             const Primitive2DSequence xSeq = create2DDecompositionOfGraphic(
80*035a2f44SArmin Le Grand                                 rGraphic,
81*035a2f44SArmin Le Grand                                 basegfx::B2DHomMatrix());
82*035a2f44SArmin Le Grand 
83*035a2f44SArmin Le Grand                             for(sal_uInt32 a(0); a < aMatrices.size(); a++)
84*035a2f44SArmin Le Grand                             {
85*035a2f44SArmin Le Grand                                 aRetval[a] = new TransformPrimitive2D(
86*035a2f44SArmin Le Grand                                     getTransformation() * aMatrices[a],
87*035a2f44SArmin Le Grand                                     xSeq);
88*035a2f44SArmin Le Grand                             }
89*035a2f44SArmin Le Grand                         }
90*035a2f44SArmin Le Grand                         else
91*035a2f44SArmin Le Grand                         {
92*035a2f44SArmin Le Grand                             // add graphic without tiling
93*035a2f44SArmin Le Grand                             const basegfx::B2DHomMatrix aObjectTransform(
94*035a2f44SArmin Le Grand                                 getTransformation() * basegfx::tools::createScaleTranslateB2DHomMatrix(
95*035a2f44SArmin Le Grand                                     rAttribute.getGraphicRange().getRange(),
96*035a2f44SArmin Le Grand                                     rAttribute.getGraphicRange().getMinimum()));
97*035a2f44SArmin Le Grand 
98*035a2f44SArmin Le Grand                             aRetval = create2DDecompositionOfGraphic(
99*035a2f44SArmin Le Grand                                 rGraphic,
100*035a2f44SArmin Le Grand                                 aObjectTransform);
101*035a2f44SArmin Le Grand                         }
102*035a2f44SArmin Le Grand                     }
103*035a2f44SArmin Le Grand                 }
104*035a2f44SArmin Le Grand             }
105*035a2f44SArmin Le Grand 
106*035a2f44SArmin Le Grand 			return aRetval;
107*035a2f44SArmin Le Grand 		}
108*035a2f44SArmin Le Grand 
FillGraphicPrimitive2D(const basegfx::B2DHomMatrix & rTransformation,const attribute::FillGraphicAttribute & rFillGraphic)109*035a2f44SArmin Le Grand 		FillGraphicPrimitive2D::FillGraphicPrimitive2D(
110*035a2f44SArmin Le Grand 			const basegfx::B2DHomMatrix& rTransformation,
111*035a2f44SArmin Le Grand 			const attribute::FillGraphicAttribute& rFillGraphic)
112*035a2f44SArmin Le Grand 		:	BufferedDecompositionPrimitive2D(),
113*035a2f44SArmin Le Grand 			maTransformation(rTransformation),
114*035a2f44SArmin Le Grand 			maFillGraphic(rFillGraphic)
115*035a2f44SArmin Le Grand 		{
116*035a2f44SArmin Le Grand 		}
117*035a2f44SArmin Le Grand 
operator ==(const BasePrimitive2D & rPrimitive) const118*035a2f44SArmin Le Grand 		bool FillGraphicPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
119*035a2f44SArmin Le Grand 		{
120*035a2f44SArmin Le Grand 			if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
121*035a2f44SArmin Le Grand 			{
122*035a2f44SArmin Le Grand 				const FillGraphicPrimitive2D& rCompare = static_cast< const FillGraphicPrimitive2D& >(rPrimitive);
123*035a2f44SArmin Le Grand 
124*035a2f44SArmin Le Grand 				return (getTransformation() == rCompare.getTransformation()
125*035a2f44SArmin Le Grand 					&& getFillGraphic() == rCompare.getFillGraphic());
126*035a2f44SArmin Le Grand 			}
127*035a2f44SArmin Le Grand 
128*035a2f44SArmin Le Grand 			return false;
129*035a2f44SArmin Le Grand 		}
130*035a2f44SArmin Le Grand 
getB2DRange(const geometry::ViewInformation2D &) const131*035a2f44SArmin Le Grand 		basegfx::B2DRange FillGraphicPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
132*035a2f44SArmin Le Grand 		{
133*035a2f44SArmin Le Grand 			// return range of it
134*035a2f44SArmin Le Grand 			basegfx::B2DPolygon aPolygon(basegfx::tools::createUnitPolygon());
135*035a2f44SArmin Le Grand 			aPolygon.transform(getTransformation());
136*035a2f44SArmin Le Grand 
137*035a2f44SArmin Le Grand             return basegfx::tools::getRange(aPolygon);
138*035a2f44SArmin Le Grand 		}
139*035a2f44SArmin Le Grand 
140*035a2f44SArmin Le Grand 		// provide unique ID
141*035a2f44SArmin Le Grand 		ImplPrimitrive2DIDBlock(FillGraphicPrimitive2D, PRIMITIVE2D_ID_FILLGRAPHICPRIMITIVE2D)
142*035a2f44SArmin Le Grand 
143*035a2f44SArmin Le Grand 	} // end of namespace primitive2d
144*035a2f44SArmin Le Grand } // end of namespace drawinglayer
145*035a2f44SArmin Le Grand 
146*035a2f44SArmin Le Grand //////////////////////////////////////////////////////////////////////////////
147*035a2f44SArmin Le Grand // eof
148