1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sal/config.h>
22 #include <drawinglayer/primitive2d/Primitive2DContainer.hxx>
23 #include <drawinglayer/primitive2d/Tools.hxx>
24 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
25 #include <drawinglayer/geometry/viewinformation2d.hxx>
29 namespace drawinglayer::primitive2d
31 Primitive2DContainer::Primitive2DContainer(
32 const css::uno::Sequence
<css::uno::Reference
<css::graphic::XPrimitive2D
>>& rSource
)
34 for (const auto& rPrimitive
: rSource
)
35 append(static_cast<const UnoPrimitive2D
*>(rPrimitive
.get())->getBasePrimitive2D());
37 Primitive2DContainer::Primitive2DContainer(
38 const std::deque
<css::uno::Reference
<css::graphic::XPrimitive2D
>>& rSource
)
40 for (const auto& rPrimitive
: rSource
)
41 append(static_cast<const UnoPrimitive2D
*>(rPrimitive
.get())->getBasePrimitive2D());
44 css::uno::Sequence
<css::uno::Reference
<css::graphic::XPrimitive2D
>>
45 Primitive2DContainer::toSequence() const
47 css::uno::Sequence
<css::uno::Reference
<css::graphic::XPrimitive2D
>> aVal(size());
48 auto p
= aVal
.getArray();
49 for (const auto& rPrimitive
: *this)
51 *p
= new UnoPrimitive2D(rPrimitive
);
57 Primitive2DContainer
Primitive2DContainer::maybeInvert(bool bInvert
)
60 std::reverse(begin(), end());
61 return std::move(*this);
64 // get B2DRange from a given Primitive2DSequence
66 Primitive2DContainer::getB2DRange(const geometry::ViewInformation2D
& aViewInformation
) const
68 basegfx::B2DRange aRetval
;
72 const sal_Int32
nCount(size());
74 for (sal_Int32
a(0); a
< nCount
; a
++)
76 aRetval
.expand(getB2DRangeFromPrimitive2DReference((*this)[a
], aViewInformation
));
83 bool Primitive2DContainer::operator==(const Primitive2DContainer
& rB
) const
85 const bool bAHasElements(!empty());
87 if (bAHasElements
!= !rB
.empty())
97 const size_t nCount(size());
99 if (nCount
!= rB
.size())
104 for (size_t a(0); a
< nCount
; a
++)
106 if (!arePrimitive2DReferencesEqual((*this)[a
], rB
[a
]))
115 Primitive2DContainer::~Primitive2DContainer() {}
117 void Primitive2DContainer::append(const Primitive2DReference
& rSource
) { push_back(rSource
); }
119 void Primitive2DContainer::append(const Primitive2DContainer
& rSource
)
121 insert(end(), rSource
.begin(), rSource
.end());
124 void Primitive2DContainer::append(Primitive2DContainer
&& rSource
)
126 this->insert(this->end(), std::make_move_iterator(rSource
.begin()),
127 std::make_move_iterator(rSource
.end()));
130 UnoPrimitive2D::~UnoPrimitive2D() {}
132 css::uno::Sequence
<::css::uno::Reference
<::css::graphic::XPrimitive2D
>>
133 SAL_CALL
UnoPrimitive2D::getDecomposition(
134 const css::uno::Sequence
<css::beans::PropertyValue
>& rViewParameters
)
136 std::unique_lock
aGuard(m_aMutex
);
137 return mxPrimitive
->getDecomposition(rViewParameters
).toSequence();
140 css::geometry::RealRectangle2D SAL_CALL
141 UnoPrimitive2D::getRange(const css::uno::Sequence
<css::beans::PropertyValue
>& rViewParameters
)
143 std::unique_lock
aGuard(m_aMutex
);
144 return mxPrimitive
->getRange(rViewParameters
);
147 sal_Int64 SAL_CALL
UnoPrimitive2D::estimateUsage()
149 std::unique_lock
aGuard(m_aMutex
);
150 return mxPrimitive
->estimateUsage();
153 } // end of namespace drawinglayer::primitive2d
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */