nss: upgrade to release 3.73
[LibreOffice.git] / svx / source / svdraw / polypolygoneditor.cxx
blobb3f6d3bc5175353682261010a8761673ca456081
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include <basegfx/polygon/b2dpolygon.hxx>
22 #include <basegfx/polygon/b2dpolygontools.hxx>
24 #include <svx/polypolygoneditor.hxx>
26 namespace sdr {
28 PolyPolygonEditor::PolyPolygonEditor( const basegfx::B2DPolyPolygon& rPolyPolygon)
29 : maPolyPolygon( rPolyPolygon )
33 bool PolyPolygonEditor::DeletePoints( const o3tl::sorted_vector< sal_uInt16 >& rAbsPoints )
35 bool bPolyPolyChanged = false;
37 auto aIter( rAbsPoints.rbegin() );
38 for( ; aIter != rAbsPoints.rend(); ++aIter )
40 sal_uInt32 nPoly, nPnt;
41 if( GetRelativePolyPoint(maPolyPolygon,(*aIter), nPoly, nPnt) )
43 // remove point
44 basegfx::B2DPolygon aCandidate(maPolyPolygon.getB2DPolygon(nPoly));
46 aCandidate.remove(nPnt);
49 if( aCandidate.count() < 2 )
51 maPolyPolygon.remove(nPoly);
53 else
55 maPolyPolygon.setB2DPolygon(nPoly, aCandidate);
58 bPolyPolyChanged = true;
62 return bPolyPolyChanged;
65 bool PolyPolygonEditor::SetSegmentsKind(SdrPathSegmentKind eKind, const o3tl::sorted_vector< sal_uInt16 >& rAbsPoints )
67 bool bPolyPolyChanged = false;
69 auto aIter( rAbsPoints.rbegin() );
70 for( ; aIter != rAbsPoints.rend(); ++aIter )
72 sal_uInt32 nPolyNum, nPntNum;
74 if(PolyPolygonEditor::GetRelativePolyPoint(maPolyPolygon, (*aIter), nPolyNum, nPntNum))
76 // do change at aNewPolyPolygon. Take a look at edge.
77 basegfx::B2DPolygon aCandidate(maPolyPolygon.getB2DPolygon(nPolyNum));
78 const sal_uInt32 nCount(aCandidate.count());
80 if(nCount && (nPntNum + 1 < nCount || aCandidate.isClosed()))
82 bool bCandidateChanged(false);
84 // it's a valid edge, check control point usage
85 const sal_uInt32 nNextIndex((nPntNum + 1) % nCount);
86 const bool bContolUsed(aCandidate.areControlPointsUsed()
87 && (aCandidate.isNextControlPointUsed(nPntNum) || aCandidate.isPrevControlPointUsed(nNextIndex)));
89 if(bContolUsed)
91 if(SdrPathSegmentKind::Toggle == eKind || SdrPathSegmentKind::Line == eKind)
93 // remove control
94 aCandidate.resetNextControlPoint(nPntNum);
95 aCandidate.resetPrevControlPoint(nNextIndex);
96 bCandidateChanged = true;
99 else
101 if(SdrPathSegmentKind::Toggle == eKind || SdrPathSegmentKind::Curve == eKind)
103 // add control
104 const basegfx::B2DPoint aStart(aCandidate.getB2DPoint(nPntNum));
105 const basegfx::B2DPoint aEnd(aCandidate.getB2DPoint(nNextIndex));
107 aCandidate.setNextControlPoint(nPntNum, interpolate(aStart, aEnd, (1.0 / 3.0)));
108 aCandidate.setPrevControlPoint(nNextIndex, interpolate(aStart, aEnd, (2.0 / 3.0)));
109 bCandidateChanged = true;
113 if(bCandidateChanged)
115 maPolyPolygon.setB2DPolygon(nPolyNum, aCandidate);
116 bPolyPolyChanged = true;
122 return bPolyPolyChanged;
125 bool PolyPolygonEditor::SetPointsSmooth( basegfx::B2VectorContinuity eFlags, const o3tl::sorted_vector< sal_uInt16 >& rAbsPoints)
127 bool bPolyPolygonChanged(false);
129 auto aIter( rAbsPoints.rbegin() );
130 for( ; aIter != rAbsPoints.rend(); ++aIter )
132 sal_uInt32 nPolyNum, nPntNum;
134 if(PolyPolygonEditor::GetRelativePolyPoint(maPolyPolygon, (*aIter), nPolyNum, nPntNum))
136 // do change at aNewPolyPolygon...
137 basegfx::B2DPolygon aCandidate(maPolyPolygon.getB2DPolygon(nPolyNum));
139 // set continuity in point, make sure there is a curve
140 bool bPolygonChanged = basegfx::utils::expandToCurveInPoint(aCandidate, nPntNum);
141 bPolygonChanged |= basegfx::utils::setContinuityInPoint(aCandidate, nPntNum, eFlags);
143 if(bPolygonChanged)
145 maPolyPolygon.setB2DPolygon(nPolyNum, aCandidate);
146 bPolyPolygonChanged = true;
151 return bPolyPolygonChanged;
154 bool PolyPolygonEditor::GetRelativePolyPoint( const basegfx::B2DPolyPolygon& rPoly, sal_uInt32 nAbsPnt, sal_uInt32& rPolyNum, sal_uInt32& rPointNum )
156 const sal_uInt32 nPolyCount(rPoly.count());
157 sal_uInt32 nPolyNum(0);
159 while(nPolyNum < nPolyCount)
161 const sal_uInt32 nPointCount(rPoly.getB2DPolygon(nPolyNum).count());
163 if(nAbsPnt < nPointCount)
165 rPolyNum = nPolyNum;
166 rPointNum = nAbsPnt;
168 return true;
170 else
172 nPolyNum++;
173 nAbsPnt -= nPointCount;
177 return false;
180 } // end of namespace sdr
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */