LibreOffice Module svx (master) 1
polypolygoneditor.cxx
Go to the documentation of this file.
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
23
25#include <utility>
26
27namespace sdr {
28
30: maPolyPolygon(std::move( aPolyPolygon ))
31{
32}
33
35{
36 bool bPolyPolyChanged = false;
37
38 auto aIter( rAbsPoints.rbegin() );
39 for( ; aIter != rAbsPoints.rend(); ++aIter )
40 {
41 sal_uInt32 nPoly, nPnt;
42 if( GetRelativePolyPoint(maPolyPolygon,(*aIter), nPoly, nPnt) )
43 {
44 // remove point
46
47 aCandidate.remove(nPnt);
48
49
50 if( aCandidate.count() < 2 )
51 {
52 maPolyPolygon.remove(nPoly);
53 }
54 else
55 {
56 maPolyPolygon.setB2DPolygon(nPoly, aCandidate);
57 }
58
59 bPolyPolyChanged = true;
60 }
61 }
62
63 return bPolyPolyChanged;
64}
65
67{
68 bool bPolyPolyChanged = false;
69
70 auto aIter( rAbsPoints.rbegin() );
71 for( ; aIter != rAbsPoints.rend(); ++aIter )
72 {
73 sal_uInt32 nPolyNum, nPntNum;
74
75 if(PolyPolygonEditor::GetRelativePolyPoint(maPolyPolygon, (*aIter), nPolyNum, nPntNum))
76 {
77 // do change at aNewPolyPolygon. Take a look at edge.
79 const sal_uInt32 nCount(aCandidate.count());
80
81 if(nCount && (nPntNum + 1 < nCount || aCandidate.isClosed()))
82 {
83 bool bCandidateChanged(false);
84
85 // it's a valid edge, check control point usage
86 const sal_uInt32 nNextIndex((nPntNum + 1) % nCount);
87 const bool bContolUsed(aCandidate.areControlPointsUsed()
88 && (aCandidate.isNextControlPointUsed(nPntNum) || aCandidate.isPrevControlPointUsed(nNextIndex)));
89
90 if(bContolUsed)
91 {
93 {
94 // remove control
95 aCandidate.resetNextControlPoint(nPntNum);
96 aCandidate.resetPrevControlPoint(nNextIndex);
97 bCandidateChanged = true;
98 }
99 }
100 else
101 {
103 {
104 // add control
105 const basegfx::B2DPoint aStart(aCandidate.getB2DPoint(nPntNum));
106 const basegfx::B2DPoint aEnd(aCandidate.getB2DPoint(nNextIndex));
107
108 aCandidate.setNextControlPoint(nPntNum, interpolate(aStart, aEnd, (1.0 / 3.0)));
109 aCandidate.setPrevControlPoint(nNextIndex, interpolate(aStart, aEnd, (2.0 / 3.0)));
110 bCandidateChanged = true;
111 }
112 }
113
114 if(bCandidateChanged)
115 {
116 maPolyPolygon.setB2DPolygon(nPolyNum, aCandidate);
117 bPolyPolyChanged = true;
118 }
119 }
120 }
121 }
122
123 return bPolyPolyChanged;
124}
125
127{
128 bool bPolyPolygonChanged(false);
129
130 auto aIter( rAbsPoints.rbegin() );
131 for( ; aIter != rAbsPoints.rend(); ++aIter )
132 {
133 sal_uInt32 nPolyNum, nPntNum;
134
135 if(PolyPolygonEditor::GetRelativePolyPoint(maPolyPolygon, (*aIter), nPolyNum, nPntNum))
136 {
137 // do change at aNewPolyPolygon...
138 basegfx::B2DPolygon aCandidate(maPolyPolygon.getB2DPolygon(nPolyNum));
139
140 // set continuity in point, make sure there is a curve
141 bool bPolygonChanged = basegfx::utils::expandToCurveInPoint(aCandidate, nPntNum);
142 bPolygonChanged |= basegfx::utils::setContinuityInPoint(aCandidate, nPntNum, eFlags);
143
144 if(bPolygonChanged)
145 {
146 maPolyPolygon.setB2DPolygon(nPolyNum, aCandidate);
147 bPolyPolygonChanged = true;
148 }
149 }
150 }
151
152 return bPolyPolygonChanged;
153}
154
155bool PolyPolygonEditor::GetRelativePolyPoint( const basegfx::B2DPolyPolygon& rPoly, sal_uInt32 nAbsPnt, sal_uInt32& rPolyNum, sal_uInt32& rPointNum )
156{
157 const sal_uInt32 nPolyCount(rPoly.count());
158 sal_uInt32 nPolyNum(0);
159
160 while(nPolyNum < nPolyCount)
161 {
162 const sal_uInt32 nPointCount(rPoly.getB2DPolygon(nPolyNum).count());
163
164 if(nAbsPnt < nPointCount)
165 {
166 rPolyNum = nPolyNum;
167 rPointNum = nAbsPnt;
168
169 return true;
170 }
171 else
172 {
173 nPolyNum++;
174 nAbsPnt -= nPointCount;
175 }
176 }
177
178 return false;
179}
180
181} // end of namespace sdr
182
183/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
B2DPolygon const & getB2DPolygon(sal_uInt32 nIndex) const
void setB2DPolygon(sal_uInt32 nIndex, const B2DPolygon &rPolygon)
void remove(sal_uInt32 nIndex, sal_uInt32 nCount=1)
sal_uInt32 count() const
bool isPrevControlPointUsed(sal_uInt32 nIndex) const
bool isNextControlPointUsed(sal_uInt32 nIndex) const
void resetNextControlPoint(sal_uInt32 nIndex)
void setPrevControlPoint(sal_uInt32 nIndex, const basegfx::B2DPoint &rValue)
bool isClosed() const
basegfx::B2DPoint const & getB2DPoint(sal_uInt32 nIndex) const
void setNextControlPoint(sal_uInt32 nIndex, const basegfx::B2DPoint &rValue)
bool areControlPointsUsed() const
sal_uInt32 count() const
void resetPrevControlPoint(sal_uInt32 nIndex)
void remove(sal_uInt32 nIndex, sal_uInt32 nCount=1)
const_reverse_iterator rend() const
const_reverse_iterator rbegin() const
bool SetPointsSmooth(basegfx::B2VectorContinuity eFlags, const o3tl::sorted_vector< sal_uInt16 > &rAbsPoints)
returns true if the B2DPolyPolygon was changed.
static bool GetRelativePolyPoint(const basegfx::B2DPolyPolygon &rPoly, sal_uInt32 nAbsPnt, sal_uInt32 &rPolyNum, sal_uInt32 &rPointNum)
Outputs the relative position ( polygon number and point number in that polygon ) from the absolute p...
basegfx::B2DPolyPolygon maPolyPolygon
bool DeletePoints(const o3tl::sorted_vector< sal_uInt16 > &rAbsPoints)
returns true if the B2DPolyPolygon was changed.
bool SetSegmentsKind(SdrPathSegmentKind eKind, const o3tl::sorted_vector< sal_uInt16 > &rAbsPoints)
returns true if the B2DPolyPolygon was changed.
PolyPolygonEditor(basegfx::B2DPolyPolygon aPolyPolygon)
int nCount
bool expandToCurveInPoint(B2DPolygon &rCandidate, sal_uInt32 nIndex)
bool setContinuityInPoint(B2DPolygon &rCandidate, sal_uInt32 nIndex, B2VectorContinuity eContinuity)
B2VectorContinuity
HSLColor interpolate(const HSLColor &rFrom, const HSLColor &rTo, double t, bool bCCW)
basegfx::B2DPolyPolygon maPolyPolygon
the basegfx::B2DPolyPolygon geometry