LCOV - code coverage report
Current view: top level - svx/source/sdr/contact - viewcontactofsdrpathobj.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 52 0.0 %
Date: 2014-04-14 Functions: 0 4 0.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 <svx/sdr/contact/viewcontactofsdrpathobj.hxx>
      22             : #include <svx/svdopath.hxx>
      23             : #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
      24             : #include <basegfx/polygon/b2dpolypolygontools.hxx>
      25             : #include <svx/sdr/primitive2d/sdrpathprimitive2d.hxx>
      26             : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      27             : 
      28             : 
      29             : 
      30             : namespace sdr
      31             : {
      32             :     namespace contact
      33             :     {
      34           0 :         ViewContactOfSdrPathObj::ViewContactOfSdrPathObj(SdrPathObj& rPathObj)
      35           0 :         :   ViewContactOfTextObj(rPathObj)
      36             :         {
      37           0 :         }
      38             : 
      39           0 :         ViewContactOfSdrPathObj::~ViewContactOfSdrPathObj()
      40             :         {
      41           0 :         }
      42             : 
      43           0 :         drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrPathObj::createViewIndependentPrimitive2DSequence() const
      44             :         {
      45           0 :             const SfxItemSet& rItemSet = GetPathObj().GetMergedItemSet();
      46             :             const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
      47             :                 drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
      48             :                     rItemSet,
      49           0 :                     GetPathObj().getText(0),
      50           0 :                     false));
      51           0 :             basegfx::B2DPolyPolygon aUnitPolyPolygon(GetPathObj().GetPathPoly());
      52           0 :             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           0 :             aUnitPolyPolygon.transform( basegfx::tools::createTranslateB2DHomMatrix( aGridOff.X(), aGridOff.Y() ) );
      57           0 :             sal_uInt32 nPolyCount(aUnitPolyPolygon.count());
      58           0 :             sal_uInt32 nPointCount(0);
      59             : 
      60           0 :             for(sal_uInt32 a(0); a < nPolyCount; a++)
      61             :             {
      62           0 :                 nPointCount += aUnitPolyPolygon.getB2DPolygon(a).count();
      63             :             }
      64             : 
      65           0 :             if(!nPointCount)
      66             :             {
      67             :                 OSL_FAIL("PolyPolygon object without geometry detected, this should not be created (!)");
      68           0 :                 basegfx::B2DPolygon aFallbackLine;
      69           0 :                 aFallbackLine.append(basegfx::B2DPoint(0.0, 0.0));
      70           0 :                 aFallbackLine.append(basegfx::B2DPoint(1000.0, 1000.0));
      71           0 :                 aUnitPolyPolygon = basegfx::B2DPolyPolygon(aFallbackLine);
      72             : 
      73           0 :                 nPolyCount = 1;
      74             :             }
      75             : 
      76             :             // prepare object transformation and unit polygon (direct model data)
      77           0 :             basegfx::B2DHomMatrix aObjectMatrix;
      78             :             const bool bIsLine(
      79           0 :                 !aUnitPolyPolygon.areControlPointsUsed()
      80           0 :                 && 1 == nPolyCount
      81           0 :                 && 2 == aUnitPolyPolygon.getB2DPolygon(0).count());
      82             : 
      83           0 :             if(bIsLine)
      84             :             {
      85             :                 // special handling for single line mode (2 points)
      86           0 :                 const basegfx::B2DPolygon aSubPolygon(aUnitPolyPolygon.getB2DPolygon(0));
      87           0 :                 const basegfx::B2DPoint aStart(aSubPolygon.getB2DPoint(0));
      88           0 :                 const basegfx::B2DPoint aEnd(aSubPolygon.getB2DPoint(1));
      89           0 :                 const basegfx::B2DVector aLine(aEnd - aStart);
      90             : 
      91             :                 // #i102548# create new unit polygon for line (horizontal)
      92           0 :                 basegfx::B2DPolygon aNewPolygon;
      93           0 :                 aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
      94           0 :                 aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
      95           0 :                 aUnitPolyPolygon.setB2DPolygon(0, aNewPolygon);
      96             : 
      97             :                 // #i102548# fill objectMatrix with rotation and offset (no shear for lines)
      98           0 :                 aObjectMatrix = basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
      99             :                     aLine.getLength(), 1.0,
     100             :                     0.0,
     101             :                     atan2(aLine.getY(), aLine.getX()),
     102           0 :                     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           0 :                 const basegfx::B2DRange aObjectRange(basegfx::tools::getRange(aUnitPolyPolygon));
     109           0 :                 const GeoStat& rGeoStat(GetPathObj().GetGeoStat());
     110           0 :                 const double fWidth(aObjectRange.getWidth());
     111           0 :                 const double fHeight(aObjectRange.getHeight());
     112           0 :                 const double fScaleX(basegfx::fTools::equalZero(fWidth) ? 1.0 : fWidth);
     113           0 :                 const double fScaleY(basegfx::fTools::equalZero(fHeight) ? 1.0 : fHeight);
     114             : 
     115           0 :                 aObjectMatrix = basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
     116             :                     fScaleX, fScaleY,
     117           0 :                     rGeoStat.nShearWink ? tan((36000 - rGeoStat.nShearWink) * F_PI18000) : 0.0,
     118           0 :                     rGeoStat.nDrehWink ? (36000 - rGeoStat.nDrehWink) * F_PI18000 : 0.0,
     119           0 :                     aObjectRange.getMinX(), aObjectRange.getMinY());
     120             : 
     121             :                 // ceate unit polygon from object's absolute path
     122           0 :                 basegfx::B2DHomMatrix aInverse(aObjectMatrix);
     123           0 :                 aInverse.invert();
     124           0 :                 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           0 :                     aUnitPolyPolygon));
     134             : 
     135           0 :             return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
     136             :         }
     137             :     } // end of namespace contact
     138             : } // end of namespace sdr
     139             : 
     140             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10