LCOV - code coverage report
Current view: top level - libreoffice/svx/source/svdraw - polypolygoneditor.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 9 69 13.0 %
Date: 2012-12-27 Functions: 1 5 20.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      21             : #include <basegfx/polygon/b2dpolygon.hxx>
      22             : #include <basegfx/polygon/b2dpolygontools.hxx>
      23             : 
      24             : #include "svx/polypolygoneditor.hxx"
      25             : 
      26             : namespace sdr {
      27             : 
      28           0 : PolyPolygonEditor::PolyPolygonEditor( const basegfx::B2DPolyPolygon& rPolyPolygon, bool bClosed )
      29             : : maPolyPolygon( rPolyPolygon )
      30           0 : , mbIsClosed( bClosed )
      31             : {
      32           0 : }
      33             : 
      34           0 : bool PolyPolygonEditor::DeletePoints( const std::set< sal_uInt16 >& rAbsPoints )
      35             : {
      36           0 :     bool bPolyPolyChanged = false;
      37             : 
      38           0 :     std::set< sal_uInt16 >::const_reverse_iterator aIter;( rAbsPoints.rbegin() );
      39           0 :     for( aIter = rAbsPoints.rbegin(); aIter != rAbsPoints.rend(); ++aIter )
      40             :     {
      41             :         sal_uInt32 nPoly, nPnt;
      42           0 :         if( GetRelativePolyPoint(maPolyPolygon,(*aIter), nPoly, nPnt) )
      43             :         {
      44             :             // remove point
      45           0 :             basegfx::B2DPolygon aCandidate(maPolyPolygon.getB2DPolygon(nPoly));
      46             : 
      47           0 :             aCandidate.remove(nPnt);
      48             : 
      49           0 :             if( ( mbIsClosed && aCandidate.count() < 3L) || (aCandidate.count() < 2L) )
      50             :             {
      51           0 :                 maPolyPolygon.remove(nPoly);
      52             :             }
      53             :             else
      54             :             {
      55           0 :                 maPolyPolygon.setB2DPolygon(nPoly, aCandidate);
      56             :             }
      57             : 
      58           0 :             bPolyPolyChanged = true;
      59             :         }
      60             :     }
      61             : 
      62           0 :     return bPolyPolyChanged;
      63             : }
      64             : 
      65           0 : bool PolyPolygonEditor::SetSegmentsKind(SdrPathSegmentKind eKind, const std::set< sal_uInt16 >& rAbsPoints )
      66             : {
      67           0 :     bool bPolyPolyChanged = false;
      68             : 
      69           0 :     std::set< sal_uInt16 >::const_reverse_iterator aIter;( rAbsPoints.rbegin() );
      70           0 :     for( aIter = rAbsPoints.rbegin(); aIter != rAbsPoints.rend(); ++aIter )
      71             :     {
      72             :         sal_uInt32 nPolyNum, nPntNum;
      73             : 
      74           0 :         if(PolyPolygonEditor::GetRelativePolyPoint(maPolyPolygon, (*aIter), nPolyNum, nPntNum))
      75             :         {
      76             :             // do change at aNewPolyPolygon. Take a look at edge.
      77           0 :             basegfx::B2DPolygon aCandidate(maPolyPolygon.getB2DPolygon(nPolyNum));
      78           0 :             bool bCandidateChanged(false);
      79           0 :             const sal_uInt32 nCount(aCandidate.count());
      80             : 
      81           0 :             if(nCount && (nPntNum + 1 < nCount || aCandidate.isClosed()))
      82             :             {
      83             :                 // it's a valid edge, check control point usage
      84           0 :                 const sal_uInt32 nNextIndex((nPntNum + 1) % nCount);
      85           0 :                 const bool bContolUsed(aCandidate.areControlPointsUsed()
      86           0 :                     && (aCandidate.isNextControlPointUsed(nPntNum) || aCandidate.isPrevControlPointUsed(nNextIndex)));
      87             : 
      88           0 :                 if(bContolUsed)
      89             :                 {
      90           0 :                     if(SDRPATHSEGMENT_TOGGLE == eKind || SDRPATHSEGMENT_LINE == eKind)
      91             :                     {
      92             :                         // remove control
      93           0 :                         aCandidate.resetNextControlPoint(nPntNum);
      94           0 :                         aCandidate.resetPrevControlPoint(nNextIndex);
      95           0 :                         bCandidateChanged = true;
      96             :                     }
      97             :                 }
      98             :                 else
      99             :                 {
     100           0 :                     if(SDRPATHSEGMENT_TOGGLE == eKind || SDRPATHSEGMENT_CURVE == eKind)
     101             :                     {
     102             :                         // add control
     103           0 :                         const basegfx::B2DPoint aStart(aCandidate.getB2DPoint(nPntNum));
     104           0 :                         const basegfx::B2DPoint aEnd(aCandidate.getB2DPoint(nNextIndex));
     105             : 
     106           0 :                         aCandidate.setNextControlPoint(nPntNum, interpolate(aStart, aEnd, (1.0 / 3.0)));
     107           0 :                         aCandidate.setPrevControlPoint(nNextIndex, interpolate(aStart, aEnd, (2.0 / 3.0)));
     108           0 :                         bCandidateChanged = true;
     109             :                     }
     110             :                 }
     111             : 
     112           0 :                 if(bCandidateChanged)
     113             :                 {
     114           0 :                     maPolyPolygon.setB2DPolygon(nPolyNum, aCandidate);
     115           0 :                     bPolyPolyChanged = true;
     116             :                 }
     117           0 :             }
     118             :         }
     119             :     }
     120             : 
     121           0 :     return bPolyPolyChanged;
     122             : }
     123             : 
     124           0 : bool PolyPolygonEditor::SetPointsSmooth( basegfx::B2VectorContinuity eFlags, const std::set< sal_uInt16 >& rAbsPoints)
     125             : {
     126           0 :     bool bPolyPolygonChanged(false);
     127             : 
     128           0 :     std::set< sal_uInt16 >::const_reverse_iterator aIter;( rAbsPoints.rbegin() );
     129           0 :     for( aIter = rAbsPoints.rbegin(); aIter != rAbsPoints.rend(); ++aIter )
     130             :     {
     131             :         sal_uInt32 nPolyNum, nPntNum;
     132             : 
     133           0 :         if(PolyPolygonEditor::GetRelativePolyPoint(maPolyPolygon, (*aIter), nPolyNum, nPntNum))
     134             :         {
     135             :             // do change at aNewPolyPolygon...
     136           0 :             basegfx::B2DPolygon aCandidate(maPolyPolygon.getB2DPolygon(nPolyNum));
     137             : 
     138             :             // set continuity in point, make sure there is a curve
     139           0 :             bool bPolygonChanged(false);
     140           0 :             bPolygonChanged = basegfx::tools::expandToCurveInPoint(aCandidate, nPntNum);
     141           0 :             bPolygonChanged |= basegfx::tools::setContinuityInPoint(aCandidate, nPntNum, eFlags);
     142             : 
     143           0 :             if(bPolygonChanged)
     144             :             {
     145           0 :                 maPolyPolygon.setB2DPolygon(nPolyNum, aCandidate);
     146           0 :                 bPolyPolygonChanged = true;
     147           0 :             }
     148             :         }
     149             :     }
     150             : 
     151           0 :     return bPolyPolygonChanged;
     152             : }
     153             : 
     154           2 : bool PolyPolygonEditor::GetRelativePolyPoint( const basegfx::B2DPolyPolygon& rPoly, sal_uInt32 nAbsPnt, sal_uInt32& rPolyNum, sal_uInt32& rPointNum )
     155             : {
     156           2 :     const sal_uInt32 nPolyCount(rPoly.count());
     157           2 :     sal_uInt32 nPolyNum(0L);
     158             : 
     159           4 :     while(nPolyNum < nPolyCount)
     160             :     {
     161           2 :         const sal_uInt32 nPointCount(rPoly.getB2DPolygon(nPolyNum).count());
     162             : 
     163           2 :         if(nAbsPnt < nPointCount)
     164             :         {
     165           2 :             rPolyNum = nPolyNum;
     166           2 :             rPointNum = nAbsPnt;
     167             : 
     168           2 :             return true;
     169             :         }
     170             :         else
     171             :         {
     172           0 :             nPolyNum++;
     173           0 :             nAbsPnt -= nPointCount;
     174             :         }
     175             :     }
     176             : 
     177           0 :     return false;
     178             : }
     179             : 
     180             : } // end of namespace sdr
     181             : 
     182             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10