Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/drawinglayer/source/primitive2d/BitmapAlphaPrimitive2D.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/BitmapAlphaPrimitive2D.hxx>
21
#include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
22
#include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
23
#include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
24
#include <utility>
25
26
using namespace com::sun::star;
27
28
namespace drawinglayer::primitive2d
29
{
30
Primitive2DReference BitmapAlphaPrimitive2D::create2DDecomposition(
31
    const geometry::ViewInformation2D& /*rViewInformation*/) const
32
0
{
33
0
    if (basegfx::fTools::equal(getTransparency(), 1.0))
34
0
    {
35
        // completely transparent, done
36
0
        return nullptr;
37
0
    }
38
39
0
    if (getBitmap().IsEmpty())
40
0
    {
41
        // no geometry, done
42
0
        return nullptr;
43
0
    }
44
45
0
    if (basegfx::fTools::equalZero(getTransparency()))
46
0
    {
47
        // no transparency, use simple BitmapPrimitive2D
48
0
        return Primitive2DReference{ new BitmapPrimitive2D(getBitmap(), getTransform()) };
49
0
    }
50
51
    // default: embed to UnifiedTransparencePrimitive2D
52
0
    Primitive2DContainer aContent{ new BitmapPrimitive2D(getBitmap(), getTransform()) };
53
0
    return Primitive2DReference{ new UnifiedTransparencePrimitive2D(std::move(aContent),
54
0
                                                                    getTransparency()) };
55
0
}
56
57
BitmapAlphaPrimitive2D::BitmapAlphaPrimitive2D(Bitmap xXBitmap, basegfx::B2DHomMatrix aTransform,
58
                                               double fTransparency)
59
0
    : maBitmap(std::move(xXBitmap))
60
0
    , maTransform(std::move(aTransform))
61
0
    , mfTransparency(std::max(0.0, std::min(1.0, fTransparency)))
62
0
{
63
0
}
64
65
bool BitmapAlphaPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
66
0
{
67
0
    if (BasePrimitive2D::operator==(rPrimitive))
68
0
    {
69
0
        const BitmapAlphaPrimitive2D& rCompare
70
0
            = static_cast<const BitmapAlphaPrimitive2D&>(rPrimitive);
71
72
0
        return (getBitmap() == rCompare.getBitmap() && getTransform() == rCompare.getTransform()
73
0
                && basegfx::fTools::equal(getTransparency(), rCompare.getTransparency()));
74
0
    }
75
76
0
    return false;
77
0
}
78
79
basegfx::B2DRange
80
BitmapAlphaPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
81
0
{
82
0
    basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0);
83
0
    aRetval.transform(maTransform);
84
0
    return aRetval;
85
0
}
86
87
sal_Int64 BitmapAlphaPrimitive2D::estimateUsage()
88
0
{
89
0
    if (getBitmap().IsEmpty())
90
0
    {
91
0
        return 0;
92
0
    }
93
0
    return getBitmap().GetSizeBytes();
94
0
}
95
96
// provide unique ID
97
sal_uInt32 BitmapAlphaPrimitive2D::getPrimitive2DID() const
98
0
{
99
0
    return PRIMITIVE2D_ID_BITMAPALPHAPRIMITIVE2D;
100
0
}
101
102
} // end of namespace
103
104
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */