LCOV - code coverage report
Current view: top level - svx/source/sdr/contact - viewcontactofsdrpathobj.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 39 45 86.7 %
Date: 2012-08-25 Functions: 4 4 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 66 130 50.8 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <svx/sdr/contact/viewcontactofsdrpathobj.hxx>
      31                 :            : #include <svx/svdopath.hxx>
      32                 :            : #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
      33                 :            : #include <basegfx/polygon/b2dpolypolygontools.hxx>
      34                 :            : #include <svx/sdr/primitive2d/sdrpathprimitive2d.hxx>
      35                 :            : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      36                 :            : 
      37                 :            : //////////////////////////////////////////////////////////////////////////////
      38                 :            : 
      39                 :            : namespace sdr
      40                 :            : {
      41                 :            :     namespace contact
      42                 :            :     {
      43                 :      19551 :         ViewContactOfSdrPathObj::ViewContactOfSdrPathObj(SdrPathObj& rPathObj)
      44                 :      19551 :         :   ViewContactOfTextObj(rPathObj)
      45                 :            :         {
      46                 :      19551 :         }
      47                 :            : 
      48                 :      19536 :         ViewContactOfSdrPathObj::~ViewContactOfSdrPathObj()
      49                 :            :         {
      50         [ -  + ]:      39072 :         }
      51                 :            : 
      52                 :      33552 :         drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrPathObj::createViewIndependentPrimitive2DSequence() const
      53                 :            :         {
      54         [ +  - ]:      33552 :             const SfxItemSet& rItemSet = GetPathObj().GetMergedItemSet();
      55                 :            :             const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
      56                 :            :                 drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
      57                 :            :                     rItemSet,
      58 [ +  - ][ +  - ]:      33552 :                     GetPathObj().getText(0)));
      59         [ +  - ]:      33552 :             basegfx::B2DPolyPolygon aUnitPolyPolygon(GetPathObj().GetPathPoly());
      60         [ +  - ]:      33552 :             sal_uInt32 nPolyCount(aUnitPolyPolygon.count());
      61                 :      33552 :             sal_uInt32 nPointCount(0);
      62                 :            : 
      63         [ +  + ]:     106869 :             for(sal_uInt32 a(0); a < nPolyCount; a++)
      64                 :            :             {
      65 [ +  - ][ +  - ]:      73317 :                 nPointCount += aUnitPolyPolygon.getB2DPolygon(a).count();
                 [ +  - ]
      66                 :            :             }
      67                 :            : 
      68         [ -  + ]:      33552 :             if(!nPointCount)
      69                 :            :             {
      70                 :            :                 OSL_FAIL("PolyPolygon object without geometry detected, this should not be created (!)");
      71         [ #  # ]:          0 :                 basegfx::B2DPolygon aFallbackLine;
      72         [ #  # ]:          0 :                 aFallbackLine.append(basegfx::B2DPoint(0.0, 0.0));
      73         [ #  # ]:          0 :                 aFallbackLine.append(basegfx::B2DPoint(1000.0, 1000.0));
      74 [ #  # ][ #  # ]:          0 :                 aUnitPolyPolygon = basegfx::B2DPolyPolygon(aFallbackLine);
                 [ #  # ]
      75                 :            : 
      76         [ #  # ]:          0 :                 nPolyCount = 1;
      77                 :            :             }
      78                 :            : 
      79                 :            :             // prepare object transformation and unit polygon (direct model data)
      80         [ +  - ]:      33552 :             basegfx::B2DHomMatrix aObjectMatrix;
      81                 :            :             const bool bIsLine(
      82         [ +  - ]:      33552 :                 !aUnitPolyPolygon.areControlPointsUsed()
      83                 :            :                 && 1 == nPolyCount
      84 [ +  + ][ +  + ]:      33552 :                 && 2 == aUnitPolyPolygon.getB2DPolygon(0).count());
         [ +  - ][ +  - ]
         [ +  + ][ +  + ]
         [ +  - ][ #  # ]
      85                 :            : 
      86         [ +  + ]:      33552 :             if(bIsLine)
      87                 :            :             {
      88                 :            :                 // special handling for single line mode (2 points)
      89         [ +  - ]:       6761 :                 const basegfx::B2DPolygon aSubPolygon(aUnitPolyPolygon.getB2DPolygon(0));
      90         [ +  - ]:       6761 :                 const basegfx::B2DPoint aStart(aSubPolygon.getB2DPoint(0));
      91         [ +  - ]:       6761 :                 const basegfx::B2DPoint aEnd(aSubPolygon.getB2DPoint(1));
      92                 :       6761 :                 const basegfx::B2DVector aLine(aEnd - aStart);
      93                 :            : 
      94                 :            :                 // #i102548# create new unit polygon for line (horizontal)
      95         [ +  - ]:       6761 :                 basegfx::B2DPolygon aNewPolygon;
      96         [ +  - ]:       6761 :                 aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
      97         [ +  - ]:       6761 :                 aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
      98         [ +  - ]:       6761 :                 aUnitPolyPolygon.setB2DPolygon(0, aNewPolygon);
      99                 :            : 
     100                 :            :                 // #i102548# fill objectMatrix with rotation and offset (no shear for lines)
     101                 :            :                 aObjectMatrix = basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
     102                 :            :                     aLine.getLength(), 1.0,
     103                 :            :                     0.0,
     104                 :            :                     atan2(aLine.getY(), aLine.getX()),
     105 [ +  - ][ +  - ]:       6761 :                     aStart.getX(), aStart.getY());
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     106                 :            :             }
     107                 :            :             else
     108                 :            :             {
     109                 :            :                 // #i102548# create unscaled, unsheared, unrotated and untranslated polygon
     110                 :            :                 // (unit polygon) by creating the object matrix and back-transforming the polygon
     111         [ +  - ]:      26791 :                 const basegfx::B2DRange aObjectRange(basegfx::tools::getRange(aUnitPolyPolygon));
     112                 :      26791 :                 const GeoStat& rGeoStat(GetPathObj().GetGeoStat());
     113         [ +  - ]:      26791 :                 const double fWidth(aObjectRange.getWidth());
     114         [ +  - ]:      26791 :                 const double fHeight(aObjectRange.getHeight());
     115         [ +  + ]:      26791 :                 const double fScaleX(basegfx::fTools::equalZero(fWidth) ? 1.0 : fWidth);
     116         [ +  + ]:      26791 :                 const double fScaleY(basegfx::fTools::equalZero(fHeight) ? 1.0 : fHeight);
     117                 :            : 
     118                 :            :                 aObjectMatrix = basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
     119                 :            :                     fScaleX, fScaleY,
     120                 :          0 :                     rGeoStat.nShearWink ? tan((36000 - rGeoStat.nShearWink) * F_PI18000) : 0.0,
     121                 :            :                     rGeoStat.nDrehWink ? (36000 - rGeoStat.nDrehWink) * F_PI18000 : 0.0,
     122 [ +  - ][ +  - ]:      26791 :                     aObjectRange.getMinX(), aObjectRange.getMinY());
         [ +  + ][ -  + ]
         [ +  - ][ +  - ]
                 [ +  - ]
     123                 :            : 
     124                 :            :                 // ceate unit polygon from object's absolute path
     125         [ +  - ]:      26791 :                 basegfx::B2DHomMatrix aInverse(aObjectMatrix);
     126         [ +  - ]:      26791 :                 aInverse.invert();
     127 [ +  - ][ +  - ]:      26791 :                 aUnitPolyPolygon.transform(aInverse);
     128                 :            :             }
     129                 :            : 
     130                 :            :             // create primitive. Always create primitives to allow the decomposition of
     131                 :            :             // SdrPathPrimitive2D to create needed invisible elements for HitTest and/or BoundRect
     132                 :            :             const drawinglayer::primitive2d::Primitive2DReference xReference(
     133                 :            :                 new drawinglayer::primitive2d::SdrPathPrimitive2D(
     134                 :            :                     aObjectMatrix,
     135                 :            :                     aAttribute,
     136 [ +  - ][ +  - ]:      33552 :                     aUnitPolyPolygon));
                 [ +  - ]
     137                 :            : 
     138 [ +  - ][ +  - ]:      33552 :             return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
         [ +  - ][ +  - ]
     139                 :            :         }
     140                 :            :     } // end of namespace contact
     141                 :            : } // end of namespace sdr
     142                 :            : 
     143                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10