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/discretebitmapprimitive2d.hxx>
28 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
29 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
30 
31 //////////////////////////////////////////////////////////////////////////////
32 
33 namespace drawinglayer
34 {
35 	namespace primitive2d
36 	{
37 		Primitive2DSequence DiscreteBitmapPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
38 		{
39 			// use getViewTransformation() and getObjectTransformation() from
40 			// ObjectAndViewTransformationDependentPrimitive2D to create a BitmapPrimitive2D
41 			// with the correct mapping
42 			Primitive2DSequence xRetval;
43 
44 			if(!getBitmapEx().IsEmpty())
45 			{
46 				// get discrete size
47 				const Size& rSizePixel = getBitmapEx().GetSizePixel();
48 				const basegfx::B2DVector aDiscreteSize(rSizePixel.Width(), rSizePixel.Height());
49 
50 				// get inverse ViewTransformation
51 				basegfx::B2DHomMatrix aInverseViewTransformation(getViewTransformation());
52 				aInverseViewTransformation.invert();
53 
54 				// get size and position in world coordinates
55 				const basegfx::B2DVector aWorldSize(aInverseViewTransformation * aDiscreteSize);
56 				const basegfx::B2DPoint  aWorldTopLeft(getObjectTransformation() * getTopLeft());
57 
58 				// build object matrix in world coordinates so that the top-left
59 				// position remains, but eventual transformations (e.g. rotations)
60 				// in the ObjectToView stack remain and get correctly applied
61 				basegfx::B2DHomMatrix aObjectTransform;
62 
63 				aObjectTransform.set(0, 0, aWorldSize.getX());
64 				aObjectTransform.set(1, 1, aWorldSize.getY());
65 				aObjectTransform.set(0, 2, aWorldTopLeft.getX());
66 				aObjectTransform.set(1, 2, aWorldTopLeft.getY());
67 
68 				// get inverse ObjectTransformation
69 				basegfx::B2DHomMatrix aInverseObjectTransformation(getObjectTransformation());
70 				aInverseObjectTransformation.invert();
71 
72 				// transform to object coordinate system
73 				aObjectTransform = aInverseObjectTransformation * aObjectTransform;
74 
75 				// create BitmapPrimitive2D with now object-local coordinate data
76 				const Primitive2DReference xRef(new BitmapPrimitive2D(getBitmapEx(), aObjectTransform));
77 				xRetval = Primitive2DSequence(&xRef, 1);
78 			}
79 
80 			return xRetval;
81 		}
82 
83 		DiscreteBitmapPrimitive2D::DiscreteBitmapPrimitive2D(
84 			const BitmapEx& rBitmapEx,
85 			const basegfx::B2DPoint& rTopLeft)
86 		:	ObjectAndViewTransformationDependentPrimitive2D(),
87 			maBitmapEx(rBitmapEx),
88 			maTopLeft(rTopLeft)
89 		{
90 		}
91 
92 		bool DiscreteBitmapPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
93 		{
94 			if(ObjectAndViewTransformationDependentPrimitive2D::operator==(rPrimitive))
95 			{
96 				const DiscreteBitmapPrimitive2D& rCompare = (DiscreteBitmapPrimitive2D&)rPrimitive;
97 
98 				return (getBitmapEx() == rCompare.getBitmapEx()
99 					&& getTopLeft() == rCompare.getTopLeft());
100 			}
101 
102 			return false;
103 		}
104 
105 		// provide unique ID
106 		ImplPrimitrive2DIDBlock(DiscreteBitmapPrimitive2D, PRIMITIVE2D_ID_DISCRETEBITMAPPRIMITIVE2D)
107 
108 	} // end of namespace primitive2d
109 } // end of namespace drawinglayer
110 
111 //////////////////////////////////////////////////////////////////////////////
112 // eof
113