/src/libreoffice/include/basegfx/polygon/b2dpolypolygon.hxx
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 | | #pragma once |
21 | | |
22 | | #include <ostream> |
23 | | #include <vector> |
24 | | |
25 | | #include <sal/types.h> |
26 | | #include <o3tl/cow_wrapper.hxx> |
27 | | #include <basegfx/range/b2drange.hxx> |
28 | | #include <basegfx/basegfxdllapi.h> |
29 | | #include <basegfx/polygon/b2dpolygon.hxx> |
30 | | |
31 | | namespace basegfx |
32 | | { |
33 | | class B2DHomMatrix; |
34 | | class ImplB2DPolyPolygon; |
35 | | |
36 | | class BASEGFX_DLLPUBLIC B2DPolyPolygon |
37 | | { |
38 | | private: |
39 | | o3tl::cow_wrapper<ImplB2DPolyPolygon, o3tl::ThreadSafeRefCountingPolicy> mpPolyPolygon; |
40 | | |
41 | | public: |
42 | | B2DPolyPolygon(); |
43 | | B2DPolyPolygon(const B2DPolyPolygon& rPolyPolygon); |
44 | | B2DPolyPolygon(B2DPolyPolygon&& rPolyPolygon); |
45 | | explicit B2DPolyPolygon(const B2DPolygon& rPolygon); |
46 | | ~B2DPolyPolygon(); |
47 | | |
48 | | // assignment operator |
49 | | B2DPolyPolygon& operator=(const B2DPolyPolygon& rPolyPolygon); |
50 | | B2DPolyPolygon& operator=(B2DPolyPolygon&& rPolyPolygon); |
51 | | |
52 | | /// unshare this poly-polygon (and all included polygons) with all internally shared instances |
53 | | void makeUnique(); |
54 | | |
55 | | // compare operators |
56 | | bool operator==(const B2DPolyPolygon& rPolyPolygon) const; |
57 | | |
58 | | // polygon interface |
59 | | sal_uInt32 count() const; |
60 | | |
61 | | B2DPolygon const & getB2DPolygon(sal_uInt32 nIndex) const; |
62 | | void setB2DPolygon(sal_uInt32 nIndex, const B2DPolygon& rPolygon); |
63 | | |
64 | | // test for curve |
65 | | bool areControlPointsUsed() const; |
66 | | |
67 | | // insert/append single polygon |
68 | | void insert(sal_uInt32 nIndex, const B2DPolygon& rPolygon, sal_uInt32 nCount = 1); |
69 | | void append(const B2DPolygon& rPolygon, sal_uInt32 nCount = 1); |
70 | | void reserve(sal_uInt32 nCount); |
71 | | |
72 | | /** Default adaptive subdivision access |
73 | | |
74 | | For details refer to B2DPolygon::getDefaultAdaptiveSubdivision() |
75 | | |
76 | | @return |
77 | | The default subdivision of this polygon |
78 | | */ |
79 | | B2DPolyPolygon getDefaultAdaptiveSubdivision() const; |
80 | | |
81 | | /** Get the B2DRange (Rectangle dimensions) of this B2DPolyPolygon |
82 | | |
83 | | For details refer to B2DPolygon::getB2DRange() |
84 | | |
85 | | @return |
86 | | The outer range of the bezier curve/polygon |
87 | | */ |
88 | | B2DRange getB2DRange() const; |
89 | | |
90 | | // insert/append multiple polygons |
91 | | void insert(sal_uInt32 nIndex, const B2DPolyPolygon& rPolyPolygon); |
92 | | void append(const B2DPolyPolygon& rPolyPolygon); |
93 | | |
94 | | // remove |
95 | | void remove(sal_uInt32 nIndex, sal_uInt32 nCount = 1); |
96 | | |
97 | | // reset to empty state |
98 | | void clear(); |
99 | | |
100 | | // closed state |
101 | | bool isClosed() const; |
102 | | void setClosed(bool bNew); |
103 | | |
104 | | // flip polygon direction |
105 | | void flip(); |
106 | | |
107 | | // test if tools::PolyPolygon has double points |
108 | | bool hasDoublePoints() const; |
109 | | |
110 | | // remove double points, at the begin/end and follow-ups, too |
111 | | void removeDoublePoints(); |
112 | | |
113 | | // apply transformation given in matrix form to the polygon |
114 | | void transform(const basegfx::B2DHomMatrix& rMatrix); |
115 | | |
116 | | /** Translate (ie. move). |
117 | | Much faster equivalent of transform(createTranslateB2DHomMatrix(xx)). */ |
118 | | void translate(double fTranslateX, double fTranslateY); |
119 | | |
120 | | inline void translate(const B2DTuple& rTranslate) |
121 | 0 | { |
122 | 0 | translate(rTranslate.getX(), rTranslate.getY()); |
123 | 0 | } |
124 | | |
125 | | // polygon iterators (same iterator validity conditions as for vector) |
126 | | const B2DPolygon* begin() const; |
127 | | const B2DPolygon* end() const; |
128 | | B2DPolygon* begin(); |
129 | | B2DPolygon* end(); |
130 | | |
131 | | // exclusive management op's for SystemDependentData at B2DPolygon |
132 | | template<class T> |
133 | | std::shared_ptr<T> getSystemDependentData(basegfx::SDD_Type aType) const |
134 | 7.61M | { |
135 | 7.61M | return std::static_pointer_cast<T>(getSystemDependantDataInternal(aType)); |
136 | 7.61M | } std::__1::shared_ptr<SystemDependentData_CairoPath> basegfx::B2DPolyPolygon::getSystemDependentData<SystemDependentData_CairoPath>(basegfx::SDD_Type) const Line | Count | Source | 134 | 7.61M | { | 135 | 7.61M | return std::static_pointer_cast<T>(getSystemDependantDataInternal(aType)); | 136 | 7.61M | } |
cairopixelprocessor2d.cxx:std::__1::shared_ptr<(anonymous namespace)::SystemDependentData_CairoPathGeometry> basegfx::B2DPolyPolygon::getSystemDependentData<(anonymous namespace)::SystemDependentData_CairoPathGeometry>(basegfx::SDD_Type) const Line | Count | Source | 134 | 421 | { | 135 | 421 | return std::static_pointer_cast<T>(getSystemDependantDataInternal(aType)); | 136 | 421 | } |
|
137 | | |
138 | | template<class T, class... Args> |
139 | | std::shared_ptr<T> addOrReplaceSystemDependentData(Args&&... args) const |
140 | 7.61M | { |
141 | 7.61M | std::shared_ptr<T> r = std::make_shared<T>(std::forward<Args>(args)...); |
142 | | |
143 | | // tdf#129845 only add to buffer if a relevant buffer time is estimated |
144 | 7.61M | if(r->calculateCombinedHoldCyclesInSeconds() > 0) |
145 | 0 | { |
146 | 0 | basegfx::SystemDependentData_SharedPtr r2(r); |
147 | 0 | addOrReplaceSystemDependentDataInternal(r2); |
148 | 0 | } |
149 | | |
150 | 7.61M | return r; |
151 | 7.61M | } std::__1::shared_ptr<SystemDependentData_CairoPath> basegfx::B2DPolyPolygon::addOrReplaceSystemDependentData<SystemDependentData_CairoPath, unsigned long&, _cairo*&, bool, bool, decltype(nullptr)>(unsigned long&, _cairo*&, bool&&, bool&&, decltype(nullptr)&&) const Line | Count | Source | 140 | 7.61M | { | 141 | 7.61M | std::shared_ptr<T> r = std::make_shared<T>(std::forward<Args>(args)...); | 142 | | | 143 | | // tdf#129845 only add to buffer if a relevant buffer time is estimated | 144 | 7.61M | if(r->calculateCombinedHoldCyclesInSeconds() > 0) | 145 | 0 | { | 146 | 0 | basegfx::SystemDependentData_SharedPtr r2(r); | 147 | 0 | addOrReplaceSystemDependentDataInternal(r2); | 148 | 0 | } | 149 | | | 150 | 7.61M | return r; | 151 | 7.61M | } |
cairopixelprocessor2d.cxx:std::__1::shared_ptr<(anonymous namespace)::SystemDependentData_CairoPathGeometry> basegfx::B2DPolyPolygon::addOrReplaceSystemDependentData<(anonymous namespace)::SystemDependentData_CairoPathGeometry, std::__1::shared_ptr<(anonymous namespace)::CairoPathHelper>&>(std::__1::shared_ptr<(anonymous namespace)::CairoPathHelper>&) const Line | Count | Source | 140 | 24 | { | 141 | 24 | std::shared_ptr<T> r = std::make_shared<T>(std::forward<Args>(args)...); | 142 | | | 143 | | // tdf#129845 only add to buffer if a relevant buffer time is estimated | 144 | 24 | if(r->calculateCombinedHoldCyclesInSeconds() > 0) | 145 | 0 | { | 146 | 0 | basegfx::SystemDependentData_SharedPtr r2(r); | 147 | 0 | addOrReplaceSystemDependentDataInternal(r2); | 148 | 0 | } | 149 | | | 150 | 24 | return r; | 151 | 24 | } |
|
152 | | |
153 | | private: |
154 | | void addOrReplaceSystemDependentDataInternal(SystemDependentData_SharedPtr& rData) const; |
155 | | SystemDependentData_SharedPtr getSystemDependantDataInternal(basegfx::SDD_Type aType) const; |
156 | | }; |
157 | | |
158 | | // typedef for a vector of B2DPolyPolygons |
159 | | typedef ::std::vector< B2DPolyPolygon > B2DPolyPolygonVector; |
160 | | |
161 | | template< typename charT, typename traits > |
162 | | inline std::basic_ostream<charT, traits> & operator <<( |
163 | | std::basic_ostream<charT, traits> & stream, const B2DPolyPolygon& poly ) |
164 | 0 | { |
165 | 0 | stream << "[" << poly.count() << ":"; |
166 | 0 | for (sal_uInt32 i = 0; i < poly.count(); i++) |
167 | 0 | { |
168 | 0 | if (i > 0) |
169 | 0 | stream << ","; |
170 | 0 | stream << poly.getB2DPolygon(i); |
171 | 0 | } |
172 | 0 | stream << "]"; |
173 | |
|
174 | 0 | return stream; |
175 | 0 | } |
176 | | |
177 | | } // end of namespace basegfx |
178 | | |
179 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |