/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 | 5 | { |
34 | 5 | for (const auto& rPrimitive : rSource) |
35 | 5 | append(static_cast<const UnoPrimitive2D*>(rPrimitive.get())->getBasePrimitive2D()); |
36 | 5 | } |
37 | | Primitive2DContainer::Primitive2DContainer( |
38 | | const std::deque<css::uno::Reference<css::graphic::XPrimitive2D>>& rSource) |
39 | 998 | { |
40 | 998 | for (const auto& rPrimitive : rSource) |
41 | 176 | append(static_cast<const UnoPrimitive2D*>(rPrimitive.get())->getBasePrimitive2D()); |
42 | 998 | } |
43 | | |
44 | | css::uno::Sequence<css::uno::Reference<css::graphic::XPrimitive2D>> |
45 | | Primitive2DContainer::toSequence() const |
46 | 32.0k | { |
47 | 32.0k | css::uno::Sequence<css::uno::Reference<css::graphic::XPrimitive2D>> aVal(size()); |
48 | 32.0k | auto p = aVal.getArray(); |
49 | 32.0k | for (const auto& rPrimitive : *this) |
50 | 6.81k | { |
51 | 6.81k | *p = new UnoPrimitive2D(rPrimitive); |
52 | 6.81k | ++p; |
53 | 6.81k | } |
54 | 32.0k | return aVal; |
55 | 32.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 | 16.5k | { |
68 | 16.5k | basegfx::B2DRange aRetval; |
69 | | |
70 | 16.5k | if (!empty()) |
71 | 16.4k | { |
72 | 16.4k | const sal_Int32 nCount(size()); |
73 | | |
74 | 35.7k | for (sal_Int32 a(0); a < nCount; a++) |
75 | 19.2k | { |
76 | 19.2k | aRetval.expand(getB2DRangeFromPrimitive2DReference((*this)[a], aViewInformation)); |
77 | 19.2k | } |
78 | 16.4k | } |
79 | | |
80 | 16.5k | return aRetval; |
81 | 16.5k | } |
82 | | |
83 | | bool Primitive2DContainer::operator==(const Primitive2DContainer& rB) const |
84 | 8.27k | { |
85 | 8.27k | const bool bAHasElements(!empty()); |
86 | | |
87 | 8.27k | if (bAHasElements != !rB.empty()) |
88 | 3.95k | { |
89 | 3.95k | return false; |
90 | 3.95k | } |
91 | | |
92 | 4.32k | if (!bAHasElements) |
93 | 2.42k | { |
94 | 2.42k | return true; |
95 | 2.42k | } |
96 | | |
97 | 1.89k | const size_t nCount(size()); |
98 | | |
99 | 1.89k | if (nCount != rB.size()) |
100 | 0 | { |
101 | 0 | return false; |
102 | 0 | } |
103 | | |
104 | 3.79k | for (size_t a(0); a < nCount; a++) |
105 | 1.89k | { |
106 | 1.89k | if (!arePrimitive2DReferencesEqual((*this)[a], rB[a])) |
107 | 0 | { |
108 | 0 | return false; |
109 | 0 | } |
110 | 1.89k | } |
111 | | |
112 | 1.89k | return true; |
113 | 1.89k | } |
114 | | |
115 | 9.29M | Primitive2DContainer::~Primitive2DContainer() {} |
116 | | |
117 | 380k | void Primitive2DContainer::append(const Primitive2DReference& rSource) { push_back(rSource); } |
118 | | |
119 | | void Primitive2DContainer::append(const Primitive2DContainer& rSource) |
120 | 8.08k | { |
121 | 8.08k | insert(end(), rSource.begin(), rSource.end()); |
122 | 8.08k | } |
123 | | |
124 | | void Primitive2DContainer::append(Primitive2DContainer&& rSource) |
125 | 357k | { |
126 | 357k | this->insert(this->end(), std::make_move_iterator(rSource.begin()), |
127 | 357k | std::make_move_iterator(rSource.end())); |
128 | 357k | } |
129 | | |
130 | 6.81k | 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.81k | { |
143 | 6.81k | std::unique_lock aGuard(m_aMutex); |
144 | 6.81k | return mxPrimitive->getRange(rViewParameters); |
145 | 6.81k | } |
146 | | |
147 | | sal_Int64 SAL_CALL UnoPrimitive2D::estimateUsage() |
148 | 6.81k | { |
149 | 6.81k | std::unique_lock aGuard(m_aMutex); |
150 | 6.81k | return mxPrimitive->estimateUsage(); |
151 | 6.81k | } |
152 | | |
153 | | } // end of namespace drawinglayer::primitive2d |
154 | | |
155 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |