LCOV - code coverage report
Current view: top level - svx/source/sdr/contact - viewcontactofsdrpathobj.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 53 53 100.0 %
Date: 2014-11-03 Functions: 6 6 100.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 <sdr/contact/viewcontactofsdrpathobj.hxx>
      22             : #include <svx/svdopath.hxx>
      23             : #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
      24             : #include <basegfx/polygon/b2dpolypolygontools.hxx>
      25             : #include <sdr/primitive2d/sdrpathprimitive2d.hxx>
      26             : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      27             : 
      28             : 
      29             : 
      30             : namespace sdr
      31             : {
      32             :     namespace contact
      33             :     {
      34       19079 :         ViewContactOfSdrPathObj::ViewContactOfSdrPathObj(SdrPathObj& rPathObj)
      35       19079 :         :   ViewContactOfTextObj(rPathObj)
      36             :         {
      37       19079 :         }
      38             : 
      39       37248 :         ViewContactOfSdrPathObj::~ViewContactOfSdrPathObj()
      40             :         {
      41       37248 :         }
      42             : 
      43       27734 :         drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrPathObj::createViewIndependentPrimitive2DSequence() const
      44             :         {
      45       27734 :             const SfxItemSet& rItemSet = GetPathObj().GetMergedItemSet();
      46             :             const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
      47             :                 drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
      48             :                     rItemSet,
      49       55468 :                     GetPathObj().getText(0),
      50       55468 :                     false));
      51       55468 :             basegfx::B2DPolyPolygon aUnitPolyPolygon(GetPathObj().GetPathPoly());
      52       27734 :             Point aGridOff = GetPathObj().GetGridOffset();
      53             :             // Hack for calc, transform position of object according
      54             :             // to current zoom so as objects relative position to grid
      55             :             // appears stable
      56       27734 :             aUnitPolyPolygon.transform( basegfx::tools::createTranslateB2DHomMatrix( aGridOff.X(), aGridOff.Y() ) );
      57       27734 :             sal_uInt32 nPolyCount(aUnitPolyPolygon.count());
      58       27734 :             sal_uInt32 nPointCount(0);
      59             : 
      60       96931 :             for(sal_uInt32 a(0); a < nPolyCount; a++)
      61             :             {
      62       69197 :                 nPointCount += aUnitPolyPolygon.getB2DPolygon(a).count();
      63             :             }
      64             : 
      65       27734 :             if(!nPointCount)
      66             :             {
      67             :                 OSL_FAIL("PolyPolygon object without geometry detected, this should not be created (!)");
      68         732 :                 basegfx::B2DPolygon aFallbackLine;
      69         732 :                 aFallbackLine.append(basegfx::B2DPoint(0.0, 0.0));
      70         732 :                 aFallbackLine.append(basegfx::B2DPoint(1000.0, 1000.0));
      71         732 :                 aUnitPolyPolygon = basegfx::B2DPolyPolygon(aFallbackLine);
      72             : 
      73         732 :                 nPolyCount = 1;
      74             :             }
      75             : 
      76             :             // prepare object transformation and unit polygon (direct model data)
      77       55468 :             basegfx::B2DHomMatrix aObjectMatrix;
      78             :             const bool bIsLine(
      79       27734 :                 !aUnitPolyPolygon.areControlPointsUsed()
      80       25079 :                 && 1 == nPolyCount
      81       68890 :                 && 2 == aUnitPolyPolygon.getB2DPolygon(0).count());
      82             : 
      83       27734 :             if(bIsLine)
      84             :             {
      85             :                 // special handling for single line mode (2 points)
      86        4709 :                 const basegfx::B2DPolygon aSubPolygon(aUnitPolyPolygon.getB2DPolygon(0));
      87        9418 :                 const basegfx::B2DPoint aStart(aSubPolygon.getB2DPoint(0));
      88        9418 :                 const basegfx::B2DPoint aEnd(aSubPolygon.getB2DPoint(1));
      89        9418 :                 const basegfx::B2DVector aLine(aEnd - aStart);
      90             : 
      91             :                 // #i102548# create new unit polygon for line (horizontal)
      92        9418 :                 basegfx::B2DPolygon aNewPolygon;
      93        4709 :                 aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
      94        4709 :                 aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
      95        4709 :                 aUnitPolyPolygon.setB2DPolygon(0, aNewPolygon);
      96             : 
      97             :                 // #i102548# fill objectMatrix with rotation and offset (no shear for lines)
      98        9418 :                 aObjectMatrix = basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
      99             :                     aLine.getLength(), 1.0,
     100             :                     0.0,
     101             :                     atan2(aLine.getY(), aLine.getX()),
     102        9418 :                     aStart.getX(), aStart.getY());
     103             :             }
     104             :             else
     105             :             {
     106             :                 // #i102548# create unscaled, unsheared, unrotated and untranslated polygon
     107             :                 // (unit polygon) by creating the object matrix and back-transforming the polygon
     108       23025 :                 const basegfx::B2DRange aObjectRange(basegfx::tools::getRange(aUnitPolyPolygon));
     109       23025 :                 const GeoStat& rGeoStat(GetPathObj().GetGeoStat());
     110       23025 :                 const double fWidth(aObjectRange.getWidth());
     111       23025 :                 const double fHeight(aObjectRange.getHeight());
     112       23025 :                 const double fScaleX(basegfx::fTools::equalZero(fWidth) ? 1.0 : fWidth);
     113       23025 :                 const double fScaleY(basegfx::fTools::equalZero(fHeight) ? 1.0 : fHeight);
     114             : 
     115       47984 :                 aObjectMatrix = basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
     116             :                     fScaleX, fScaleY,
     117           4 :                     rGeoStat.nShearAngle ? tan((36000 - rGeoStat.nShearAngle) * F_PI18000) : 0.0,
     118        1930 :                     rGeoStat.nRotationAngle ? (36000 - rGeoStat.nRotationAngle) * F_PI18000 : 0.0,
     119       23025 :                     aObjectRange.getMinX(), aObjectRange.getMinY());
     120             : 
     121             :                 // ceate unit polygon from object's absolute path
     122       23025 :                 basegfx::B2DHomMatrix aInverse(aObjectMatrix);
     123       23025 :                 aInverse.invert();
     124       23025 :                 aUnitPolyPolygon.transform(aInverse);
     125             :             }
     126             : 
     127             :             // create primitive. Always create primitives to allow the decomposition of
     128             :             // SdrPathPrimitive2D to create needed invisible elements for HitTest and/or BoundRect
     129             :             const drawinglayer::primitive2d::Primitive2DReference xReference(
     130             :                 new drawinglayer::primitive2d::SdrPathPrimitive2D(
     131             :                     aObjectMatrix,
     132             :                     aAttribute,
     133       55468 :                     aUnitPolyPolygon));
     134             : 
     135       55468 :             return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
     136             :         }
     137             :     } // end of namespace contact
     138         651 : } // end of namespace sdr
     139             : 
     140             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10