Coverage Report

Created: 2026-10-14 09:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/drawinglayer/source/primitive2d/Primitive2DContainer.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 <sal/config.h>
21
22
#include <drawinglayer/primitive2d/Primitive2DContainer.hxx>
23
#include <drawinglayer/primitive2d/Tools.hxx>
24
#include <drawinglayer/primitive2d/baseprimitive2d.hxx>
25
#include <drawinglayer/geometry/viewinformation2d.hxx>
26
27
using namespace css;
28
29
namespace drawinglayer::primitive2d
30
{
31
Primitive2DContainer::Primitive2DContainer(
32
    const css::uno::Sequence<css::uno::Reference<css::graphic::XPrimitive2D>>& rSource)
33
3
{
34
3
    for (const auto& rPrimitive : rSource)
35
3
        append(static_cast<const UnoPrimitive2D*>(rPrimitive.get())->getBasePrimitive2D());
36
3
}
37
Primitive2DContainer::Primitive2DContainer(
38
    const std::deque<css::uno::Reference<css::graphic::XPrimitive2D>>& rSource)
39
1.13k
{
40
1.13k
    for (const auto& rPrimitive : rSource)
41
361
        append(static_cast<const UnoPrimitive2D*>(rPrimitive.get())->getBasePrimitive2D());
42
1.13k
}
43
44
css::uno::Sequence<css::uno::Reference<css::graphic::XPrimitive2D>>
45
Primitive2DContainer::toSequence() const
46
37.0k
{
47
37.0k
    css::uno::Sequence<css::uno::Reference<css::graphic::XPrimitive2D>> aVal(size());
48
37.0k
    auto p = aVal.getArray();
49
37.0k
    for (const auto& rPrimitive : *this)
50
6.82k
    {
51
6.82k
        *p = new UnoPrimitive2D(rPrimitive);
52
6.82k
        ++p;
53
6.82k
    }
54
37.0k
    return aVal;
55
37.0k
}
56
57
Primitive2DContainer Primitive2DContainer::maybeInvert(bool bInvert)
58
0
{
59
0
    if (bInvert)
60
0
        std::reverse(begin(), end());
61
0
    return std::move(*this);
62
0
}
63
64
// get B2DRange from a given Primitive2DSequence
65
basegfx::B2DRange
66
Primitive2DContainer::getB2DRange(const geometry::ViewInformation2D& aViewInformation) const
67
55.1k
{
68
55.1k
    basegfx::B2DRange aRetval;
69
70
55.1k
    if (!empty())
71
55.0k
    {
72
55.0k
        const sal_Int32 nCount(size());
73
74
832k
        for (sal_Int32 a(0); a < nCount; a++)
75
777k
        {
76
777k
            aRetval.expand(getB2DRangeFromPrimitive2DReference((*this)[a], aViewInformation));
77
777k
        }
78
55.0k
    }
79
80
55.1k
    return aRetval;
81
55.1k
}
82
83
bool Primitive2DContainer::operator==(const Primitive2DContainer& rB) const
84
11.8k
{
85
11.8k
    const bool bAHasElements(!empty());
86
87
11.8k
    if (bAHasElements != !rB.empty())
88
7.76k
    {
89
7.76k
        return false;
90
7.76k
    }
91
92
4.03k
    if (!bAHasElements)
93
2.15k
    {
94
2.15k
        return true;
95
2.15k
    }
96
97
1.88k
    const size_t nCount(size());
98
99
1.88k
    if (nCount != rB.size())
100
0
    {
101
0
        return false;
102
0
    }
103
104
3.76k
    for (size_t a(0); a < nCount; a++)
105
1.88k
    {
106
1.88k
        if (!arePrimitive2DReferencesEqual((*this)[a], rB[a]))
107
0
        {
108
0
            return false;
109
0
        }
110
1.88k
    }
111
112
1.88k
    return true;
113
1.88k
}
114
115
28.7M
Primitive2DContainer::~Primitive2DContainer() {}
116
117
621k
void Primitive2DContainer::append(const Primitive2DReference& rSource) { push_back(rSource); }
118
119
void Primitive2DContainer::append(const Primitive2DContainer& rSource)
120
13.3k
{
121
13.3k
    insert(end(), rSource.begin(), rSource.end());
122
13.3k
}
123
124
void Primitive2DContainer::append(Primitive2DContainer&& rSource)
125
589k
{
126
589k
    this->insert(this->end(), std::make_move_iterator(rSource.begin()),
127
589k
                 std::make_move_iterator(rSource.end()));
128
589k
}
129
130
6.82k
UnoPrimitive2D::~UnoPrimitive2D() {}
131
132
css::uno::Sequence<::css::uno::Reference<::css::graphic::XPrimitive2D>>
133
    SAL_CALL UnoPrimitive2D::getDecomposition(
134
        const css::uno::Sequence<css::beans::PropertyValue>& rViewParameters)
135
0
{
136
0
    std::unique_lock aGuard(m_aMutex);
137
0
    return mxPrimitive->getDecomposition(rViewParameters).toSequence();
138
0
}
139
140
css::geometry::RealRectangle2D SAL_CALL
141
UnoPrimitive2D::getRange(const css::uno::Sequence<css::beans::PropertyValue>& rViewParameters)
142
6.82k
{
143
6.82k
    std::unique_lock aGuard(m_aMutex);
144
6.82k
    return mxPrimitive->getRange(rViewParameters);
145
6.82k
}
146
147
sal_Int64 SAL_CALL UnoPrimitive2D::estimateUsage()
148
6.82k
{
149
6.82k
    std::unique_lock aGuard(m_aMutex);
150
6.82k
    return mxPrimitive->estimateUsage();
151
6.82k
}
152
153
} // end of namespace drawinglayer::primitive2d
154
155
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */