/src/libreoffice/drawinglayer/source/primitive2d/discretebitmapprimitive2d.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #include <drawinglayer/primitive2d/discretebitmapprimitive2d.hxx> |
21 | | #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx> |
22 | | #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> |
23 | | |
24 | | |
25 | | namespace drawinglayer::primitive2d |
26 | | { |
27 | | Primitive2DReference DiscreteBitmapPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const |
28 | 0 | { |
29 | | // use getViewTransformation() and getObjectTransformation() from |
30 | | // ObjectAndViewTransformationDependentPrimitive2D to create a BitmapPrimitive2D |
31 | | // with the correct mapping |
32 | |
|
33 | 0 | if(getBitmap().IsEmpty()) |
34 | 0 | return nullptr; |
35 | | |
36 | | // get discrete size |
37 | 0 | const Size aSizePixel = getBitmap().GetSizePixel(); |
38 | 0 | const basegfx::B2DVector aDiscreteSize(aSizePixel.Width(), aSizePixel.Height()); |
39 | | |
40 | | // get inverse ViewTransformation |
41 | 0 | basegfx::B2DHomMatrix aInverseViewTransformation(getViewTransformation()); |
42 | 0 | aInverseViewTransformation.invert(); |
43 | | |
44 | | // get size and position in world coordinates |
45 | 0 | const basegfx::B2DVector aWorldSize(aInverseViewTransformation * aDiscreteSize); |
46 | 0 | const basegfx::B2DPoint aWorldTopLeft(getObjectTransformation() * getTopLeft()); |
47 | | |
48 | | // build object matrix in world coordinates so that the top-left |
49 | | // position remains, but possible transformations (e.g. rotations) |
50 | | // in the ObjectToView stack remain and get correctly applied |
51 | 0 | basegfx::B2DHomMatrix aObjectTransform; |
52 | |
|
53 | 0 | aObjectTransform.set(0, 0, aWorldSize.getX()); |
54 | 0 | aObjectTransform.set(1, 1, aWorldSize.getY()); |
55 | 0 | aObjectTransform.set(0, 2, aWorldTopLeft.getX()); |
56 | 0 | aObjectTransform.set(1, 2, aWorldTopLeft.getY()); |
57 | | |
58 | | // get inverse ObjectTransformation |
59 | 0 | basegfx::B2DHomMatrix aInverseObjectTransformation(getObjectTransformation()); |
60 | 0 | aInverseObjectTransformation.invert(); |
61 | | |
62 | | // transform to object coordinate system |
63 | 0 | aObjectTransform = aInverseObjectTransformation * aObjectTransform; |
64 | | |
65 | | // create BitmapPrimitive2D with now object-local coordinate data |
66 | 0 | return |
67 | 0 | new BitmapPrimitive2D( |
68 | 0 | getBitmap(), |
69 | 0 | aObjectTransform); |
70 | 0 | } |
71 | | |
72 | | DiscreteBitmapPrimitive2D::DiscreteBitmapPrimitive2D( |
73 | | const Bitmap& rBitmap, |
74 | | const basegfx::B2DPoint& rTopLeft) |
75 | 0 | : maBitmap(rBitmap), |
76 | 0 | maTopLeft(rTopLeft) |
77 | 0 | { |
78 | 0 | } |
79 | | |
80 | | bool DiscreteBitmapPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const |
81 | 0 | { |
82 | 0 | if(ObjectAndViewTransformationDependentPrimitive2D::operator==(rPrimitive)) |
83 | 0 | { |
84 | 0 | const DiscreteBitmapPrimitive2D& rCompare = static_cast<const DiscreteBitmapPrimitive2D&>(rPrimitive); |
85 | |
|
86 | 0 | return (getBitmap() == rCompare.getBitmap() |
87 | 0 | && getTopLeft() == rCompare.getTopLeft()); |
88 | 0 | } |
89 | | |
90 | 0 | return false; |
91 | 0 | } |
92 | | |
93 | | // provide unique ID |
94 | | sal_uInt32 DiscreteBitmapPrimitive2D::getPrimitive2DID() const |
95 | 0 | { |
96 | 0 | return PRIMITIVE2D_ID_DISCRETEBITMAPPRIMITIVE2D; |
97 | 0 | } |
98 | | |
99 | | } // end of namespace |
100 | | |
101 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |