xref: /trunk/main/drawinglayer/source/primitive2d/discretebitmapprimitive2d.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_drawinglayer.hxx"
30 
31 #include <drawinglayer/primitive2d/discretebitmapprimitive2d.hxx>
32 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
33 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
34 
35 //////////////////////////////////////////////////////////////////////////////
36 
37 namespace drawinglayer
38 {
39     namespace primitive2d
40     {
41         Primitive2DSequence DiscreteBitmapPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
42         {
43             // use getViewTransformation() and getObjectTransformation() from
44             // ObjectAndViewTransformationDependentPrimitive2D to create a BitmapPrimitive2D
45             // with the correct mapping
46             Primitive2DSequence xRetval;
47 
48             if(!getBitmapEx().IsEmpty())
49             {
50                 // get discrete size
51                 const Size& rSizePixel = getBitmapEx().GetSizePixel();
52                 const basegfx::B2DVector aDiscreteSize(rSizePixel.Width(), rSizePixel.Height());
53 
54                 // get inverse ViewTransformation
55                 basegfx::B2DHomMatrix aInverseViewTransformation(getViewTransformation());
56                 aInverseViewTransformation.invert();
57 
58                 // get size and position in world coordinates
59                 const basegfx::B2DVector aWorldSize(aInverseViewTransformation * aDiscreteSize);
60                 const basegfx::B2DPoint  aWorldTopLeft(getObjectTransformation() * getTopLeft());
61 
62                 // build object matrix in world coordinates so that the top-left
63                 // position remains, but eventual transformations (e.g. rotations)
64                 // in the ObjectToView stack remain and get correctly applied
65                 basegfx::B2DHomMatrix aObjectTransform;
66 
67                 aObjectTransform.set(0, 0, aWorldSize.getX());
68                 aObjectTransform.set(1, 1, aWorldSize.getY());
69                 aObjectTransform.set(0, 2, aWorldTopLeft.getX());
70                 aObjectTransform.set(1, 2, aWorldTopLeft.getY());
71 
72                 // get inverse ObjectTransformation
73                 basegfx::B2DHomMatrix aInverseObjectTransformation(getObjectTransformation());
74                 aInverseObjectTransformation.invert();
75 
76                 // transform to object coordinate system
77                 aObjectTransform = aInverseObjectTransformation * aObjectTransform;
78 
79                 // create BitmapPrimitive2D with now object-local coordinate data
80                 const Primitive2DReference xRef(new BitmapPrimitive2D(getBitmapEx(), aObjectTransform));
81                 xRetval = Primitive2DSequence(&xRef, 1);
82             }
83 
84             return xRetval;
85         }
86 
87         DiscreteBitmapPrimitive2D::DiscreteBitmapPrimitive2D(
88             const BitmapEx& rBitmapEx,
89             const basegfx::B2DPoint& rTopLeft)
90         :   ObjectAndViewTransformationDependentPrimitive2D(),
91             maBitmapEx(rBitmapEx),
92             maTopLeft(rTopLeft)
93         {
94         }
95 
96         bool DiscreteBitmapPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
97         {
98             if(ObjectAndViewTransformationDependentPrimitive2D::operator==(rPrimitive))
99             {
100                 const DiscreteBitmapPrimitive2D& rCompare = (DiscreteBitmapPrimitive2D&)rPrimitive;
101 
102                 return (getBitmapEx() == rCompare.getBitmapEx()
103                     && getTopLeft() == rCompare.getTopLeft());
104             }
105 
106             return false;
107         }
108 
109         // provide unique ID
110         ImplPrimitrive2DIDBlock(DiscreteBitmapPrimitive2D, PRIMITIVE2D_ID_DISCRETEBITMAPPRIMITIVE2D)
111 
112     } // end of namespace primitive2d
113 } // end of namespace drawinglayer
114 
115 //////////////////////////////////////////////////////////////////////////////
116 // eof
117