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