tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / drawinglayer / source / primitive2d / discretebitmapprimitive2d.cxx
blob66dcfcb403e176d1254d3c7bad40ba43a56dfb50
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
23 #include <toolkit/helper/vclunohelper.hxx>
26 namespace drawinglayer::primitive2d
28 Primitive2DReference DiscreteBitmapPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
30 // use getViewTransformation() and getObjectTransformation() from
31 // ObjectAndViewTransformationDependentPrimitive2D to create a BitmapPrimitive2D
32 // with the correct mapping
34 if(getBitmapEx().IsEmpty())
35 return nullptr;
37 // get discrete size
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 return
68 new BitmapPrimitive2D(
69 getBitmapEx(),
70 aObjectTransform);
73 DiscreteBitmapPrimitive2D::DiscreteBitmapPrimitive2D(
74 const BitmapEx& rBitmapEx,
75 const basegfx::B2DPoint& rTopLeft)
76 : maBitmapEx(rBitmapEx),
77 maTopLeft(rTopLeft)
81 bool DiscreteBitmapPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
83 if(ObjectAndViewTransformationDependentPrimitive2D::operator==(rPrimitive))
85 const DiscreteBitmapPrimitive2D& rCompare = static_cast<const DiscreteBitmapPrimitive2D&>(rPrimitive);
87 return (getBitmapEx() == rCompare.getBitmapEx()
88 && getTopLeft() == rCompare.getTopLeft());
91 return false;
94 // provide unique ID
95 sal_uInt32 DiscreteBitmapPrimitive2D::getPrimitive2DID() const
97 return PRIMITIVE2D_ID_DISCRETEBITMAPPRIMITIVE2D;
100 } // end of namespace
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */