1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <drawinglayer/primitive2d/discretebitmapprimitive2d.hxx>
21 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
22 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
25 namespace drawinglayer
29 void DiscreteBitmapPrimitive2D::create2DDecomposition(Primitive2DContainer
& rContainer
, const geometry::ViewInformation2D
& /*rViewInformation*/) const
31 // use getViewTransformation() and getObjectTransformation() from
32 // ObjectAndViewTransformationDependentPrimitive2D to create a BitmapPrimitive2D
33 // with the correct mapping
35 if(!getBitmapEx().IsEmpty())
38 const Size
& rSizePixel
= getBitmapEx().GetSizePixel();
39 const basegfx::B2DVector
aDiscreteSize(rSizePixel
.Width(), rSizePixel
.Height());
41 // get inverse ViewTransformation
42 basegfx::B2DHomMatrix
aInverseViewTransformation(getViewTransformation());
43 aInverseViewTransformation
.invert();
45 // get size and position in world coordinates
46 const basegfx::B2DVector
aWorldSize(aInverseViewTransformation
* aDiscreteSize
);
47 const basegfx::B2DPoint
aWorldTopLeft(getObjectTransformation() * getTopLeft());
49 // build object matrix in world coordinates so that the top-left
50 // position remains, but possible transformations (e.g. rotations)
51 // in the ObjectToView stack remain and get correctly applied
52 basegfx::B2DHomMatrix aObjectTransform
;
54 aObjectTransform
.set(0, 0, aWorldSize
.getX());
55 aObjectTransform
.set(1, 1, aWorldSize
.getY());
56 aObjectTransform
.set(0, 2, aWorldTopLeft
.getX());
57 aObjectTransform
.set(1, 2, aWorldTopLeft
.getY());
59 // get inverse ObjectTransformation
60 basegfx::B2DHomMatrix
aInverseObjectTransformation(getObjectTransformation());
61 aInverseObjectTransformation
.invert();
63 // transform to object coordinate system
64 aObjectTransform
= aInverseObjectTransformation
* aObjectTransform
;
66 // create BitmapPrimitive2D with now object-local coordinate data
67 rContainer
.push_back(new BitmapPrimitive2D(getBitmapEx(), aObjectTransform
));
71 DiscreteBitmapPrimitive2D::DiscreteBitmapPrimitive2D(
72 const BitmapEx
& rBitmapEx
,
73 const basegfx::B2DPoint
& rTopLeft
)
74 : ObjectAndViewTransformationDependentPrimitive2D(),
75 maBitmapEx(rBitmapEx
),
80 bool DiscreteBitmapPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
82 if(ObjectAndViewTransformationDependentPrimitive2D::operator==(rPrimitive
))
84 const DiscreteBitmapPrimitive2D
& rCompare
= static_cast<const DiscreteBitmapPrimitive2D
&>(rPrimitive
);
86 return (getBitmapEx() == rCompare
.getBitmapEx()
87 && getTopLeft() == rCompare
.getTopLeft());
94 ImplPrimitive2DIDBlock(DiscreteBitmapPrimitive2D
, PRIMITIVE2D_ID_DISCRETEBITMAPPRIMITIVE2D
)
96 } // end of namespace primitive2d
97 } // end of namespace drawinglayer
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */