cool#10610 Ensure the parent-child relations of comments.
[LibreOffice.git] / drawinglayer / source / primitive2d / BitmapAlphaPrimitive2D.cxx
blob8aaca2e5fd159cd4644e2bc3e03b695376718a0f
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/BitmapAlphaPrimitive2D.hxx>
21 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
22 #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
23 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
24 #include <com/sun/star/awt/XBitmap.hpp>
25 #include <utility>
27 using namespace com::sun::star;
29 namespace drawinglayer::primitive2d
31 Primitive2DReference BitmapAlphaPrimitive2D::create2DDecomposition(
32 const geometry::ViewInformation2D& /*rViewInformation*/) const
34 if (basegfx::fTools::equal(getTransparency(), 1.0))
36 // completely transparent, done
37 return nullptr;
40 if (getBitmap().IsEmpty())
42 // no geometry, done
43 return nullptr;
46 if (basegfx::fTools::equalZero(getTransparency()))
48 // no transparency, use simple BitmapPrimitive2D
49 return Primitive2DReference{ new BitmapPrimitive2D(getBitmap(), getTransform()) };
52 // default: embed to UnifiedTransparencePrimitive2D
53 Primitive2DContainer aContent{ new BitmapPrimitive2D(getBitmap(), getTransform()) };
54 return Primitive2DReference{ new UnifiedTransparencePrimitive2D(std::move(aContent),
55 getTransparency()) };
58 BitmapAlphaPrimitive2D::BitmapAlphaPrimitive2D(BitmapEx xXBitmap, basegfx::B2DHomMatrix aTransform,
59 double fTransparency)
60 : maBitmap(std::move(xXBitmap))
61 , maTransform(std::move(aTransform))
62 , mfTransparency(std::max(0.0, std::min(1.0, fTransparency)))
66 bool BitmapAlphaPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
68 if (BasePrimitive2D::operator==(rPrimitive))
70 const BitmapAlphaPrimitive2D& rCompare
71 = static_cast<const BitmapAlphaPrimitive2D&>(rPrimitive);
73 return (getBitmap() == rCompare.getBitmap() && getTransform() == rCompare.getTransform()
74 && basegfx::fTools::equal(getTransparency(), rCompare.getTransparency()));
77 return false;
80 basegfx::B2DRange
81 BitmapAlphaPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
83 basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0);
84 aRetval.transform(maTransform);
85 return aRetval;
88 sal_Int64 BitmapAlphaPrimitive2D::estimateUsage()
90 if (getBitmap().IsEmpty())
92 return 0;
94 return getBitmap().GetSizeBytes();
97 // provide unique ID
98 sal_uInt32 BitmapAlphaPrimitive2D::getPrimitive2DID() const
100 return PRIMITIVE2D_ID_BITMAPALPHAPRIMITIVE2D;
103 } // end of namespace
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */