LCOV - code coverage report
Current view: top level - svx/source/sdr/contact - viewcontactofsdrobjcustomshape.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 80 88 90.9 %
Date: 2014-11-03 Functions: 7 7 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             : #include <sdr/contact/viewcontactofsdrobjcustomshape.hxx>
      21             : #include <svx/svdoashp.hxx>
      22             : #include <svx/sdr/contact/displayinfo.hxx>
      23             : #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
      24             : #include <svx/svditer.hxx>
      25             : #include <sdr/primitive2d/sdrcustomshapeprimitive2d.hxx>
      26             : #include <basegfx/polygon/b2dpolygontools.hxx>
      27             : #include <basegfx/polygon/b2dpolygon.hxx>
      28             : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      29             : #include <svx/obj3d.hxx>
      30             : #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
      31             : 
      32             : 
      33             : 
      34             : namespace sdr
      35             : {
      36             :     namespace contact
      37             :     {
      38        6318 :         ViewContactOfSdrObjCustomShape::ViewContactOfSdrObjCustomShape(SdrObjCustomShape& rCustomShape)
      39        6318 :         :   ViewContactOfTextObj(rCustomShape)
      40             :         {
      41        6318 :         }
      42             : 
      43       12636 :         ViewContactOfSdrObjCustomShape::~ViewContactOfSdrObjCustomShape()
      44             :         {
      45       12636 :         }
      46             : 
      47        2326 :         basegfx::B2DRange ViewContactOfSdrObjCustomShape::getCorrectedTextBoundRect() const
      48             :         {
      49        2326 :             Rectangle aObjectBound(GetCustomShapeObj().GetGeoRect());
      50        2326 :             aObjectBound += GetCustomShapeObj().GetGridOffset();
      51        2326 :             Rectangle aTextBound(aObjectBound);
      52        2326 :             GetCustomShapeObj().GetTextBounds(aTextBound);
      53        2326 :             aTextBound += GetCustomShapeObj().GetGridOffset();
      54        2326 :             basegfx::B2DRange aTextRange(aTextBound.Left(), aTextBound.Top(), aTextBound.Right(), aTextBound.Bottom());
      55        2326 :             const basegfx::B2DRange aObjectRange(aObjectBound.Left(), aObjectBound.Top(), aObjectBound.Right(), aObjectBound.Bottom());
      56             : 
      57             :             // no need to correct if no extra text range
      58        2326 :             if(aTextRange != aObjectRange)
      59             :             {
      60        1160 :                 const GeoStat& rGeoStat(GetCustomShapeObj().GetGeoStat());
      61             : 
      62             :                 // only correct when rotation and/or shear is used
      63        1160 :                 if(rGeoStat.nShearAngle || rGeoStat.nRotationAngle )
      64             :                 {
      65             :                     // text range needs to be corrected by
      66             :                     // aObjectRange.getCenter() - aRotObjectRange.getCenter() since it's
      67             :                     // defined differenly by using rotation around object center. Start
      68             :                     // with positive part
      69          32 :                     basegfx::B2DVector aTranslation(aObjectRange.getCenter());
      70             : 
      71             :                     // get rotated and sheared object's range
      72          32 :                     basegfx::B2DRange aRotObjectRange(aObjectRange);
      73          64 :                     basegfx::B2DHomMatrix aRotMatrix;
      74             : 
      75          32 :                     aRotMatrix.translate(-aObjectRange.getMinimum().getX(), -aObjectRange.getMinimum().getY());
      76             : 
      77          32 :                     if(rGeoStat.nShearAngle)
      78             :                     {
      79           0 :                         aRotMatrix.shearX(tan((36000 - rGeoStat.nShearAngle) * F_PI18000));
      80             :                     }
      81             : 
      82          32 :                     if(rGeoStat.nRotationAngle)
      83             :                     {
      84          32 :                         aRotMatrix.rotate((36000 - rGeoStat.nRotationAngle) * F_PI18000);
      85             :                     }
      86             : 
      87          32 :                     aRotMatrix.translate(aObjectRange.getMinimum().getX(), aObjectRange.getMinimum().getY());
      88          32 :                     aRotObjectRange.transform(aRotMatrix);
      89             : 
      90             :                     // add negative translation part
      91          32 :                     aTranslation -= aRotObjectRange.getCenter();
      92             : 
      93             :                     // create new range
      94             :                     aTextRange = basegfx::B2DRange(
      95          64 :                         aTextRange.getMinX() + aTranslation.getX(), aTextRange.getMinY() + aTranslation.getY(),
      96         128 :                         aTextRange.getMaxX() + aTranslation.getX(), aTextRange.getMaxY() + aTranslation.getY());
      97             :                 }
      98             :             }
      99             : 
     100        2326 :             return aTextRange;
     101             :         }
     102             : 
     103       13896 :         drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrObjCustomShape::createViewIndependentPrimitive2DSequence() const
     104             :         {
     105       13896 :             drawinglayer::primitive2d::Primitive2DSequence xRetval;
     106       13896 :             const SfxItemSet& rItemSet = GetCustomShapeObj().GetMergedItemSet();
     107             : 
     108             :             // #i98072# Get shandow and text; eventually suppress the text if it's
     109             :             // a TextPath FontworkGallery object
     110             :             const drawinglayer::attribute::SdrShadowTextAttribute aAttribute(
     111             :                 drawinglayer::primitive2d::createNewSdrShadowTextAttribute(
     112             :                     rItemSet,
     113       27792 :                     GetCustomShapeObj().getText(0),
     114       55584 :                     GetCustomShapeObj().IsTextPath()));
     115       27792 :             drawinglayer::primitive2d::Primitive2DSequence xGroup;
     116       13896 :             bool bHasText(!aAttribute.getText().isDefault());
     117             : 
     118             :             // create Primitive2DSequence from sub-geometry
     119       13896 :             const SdrObject* pSdrObjRepresentation = GetCustomShapeObj().GetSdrObjectFromCustomShape();
     120       13896 :             bool b3DShape(false);
     121             : 
     122       13896 :             Point aGridOff = GetCustomShapeObj().GetGridOffset();
     123             : 
     124       13896 :             if(pSdrObjRepresentation)
     125             :             {
     126             :                 // Hack for calc, transform position of object according
     127             :                 // to current zoom so as objects relative position to grid
     128             :                 // appears stable
     129        8424 :                 const_cast< SdrObject* >( pSdrObjRepresentation )->SetGridOffset( aGridOff );
     130        8424 :                 SdrObjListIter aIterator(*pSdrObjRepresentation);
     131             : 
     132       28116 :                 while(aIterator.IsMore())
     133             :                 {
     134       11268 :                     SdrObject& rCandidate = *aIterator.Next();
     135             :                     // apply offset to each part
     136       11268 :                     rCandidate.SetGridOffset( aGridOff );
     137       11268 :                     if(!b3DShape && dynamic_cast< E3dObject* >(&rCandidate))
     138             :                     {
     139           0 :                         b3DShape = true;
     140             :                     }
     141             : 
     142       11268 :                     const drawinglayer::primitive2d::Primitive2DSequence xNew(rCandidate.GetViewContact().getViewIndependentPrimitive2DSequence());
     143       11268 :                     drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xGroup, xNew);
     144       19692 :                 }
     145             :             }
     146             : 
     147       13896 :             if(bHasText || xGroup.hasElements())
     148             :             {
     149             :                 // prepare text box geometry
     150        9194 :                 basegfx::B2DHomMatrix aTextBoxMatrix;
     151        9194 :                 bool bWordWrap(false);
     152             : 
     153        9194 :                 if(bHasText)
     154             :                 {
     155             :                     // take unrotated snap rect as default, then get the
     156             :                     // unrotated text box. Rotation needs to be done centered
     157        2326 :                     Rectangle aObjectBound(GetCustomShapeObj().GetGeoRect());
     158             :                     // hack for calc grid sync
     159        2326 :                     aObjectBound += GetCustomShapeObj().GetGridOffset();
     160        2326 :                     const basegfx::B2DRange aObjectRange(aObjectBound.Left(), aObjectBound.Top(), aObjectBound.Right(), aObjectBound.Bottom());
     161             : 
     162             :                     // #i101684# get the text range unrotated and absolute to the object range
     163        2326 :                     const basegfx::B2DRange aTextRange(getCorrectedTextBoundRect());
     164             : 
     165             :                     // Rotation before scaling
     166        2326 :                     if(!basegfx::fTools::equalZero(GetCustomShapeObj().GetExtraTextRotation(true)))
     167             :                     {
     168          56 :                         basegfx::B2DVector aTranslation(0.5, 0.5);
     169          56 :                         aTextBoxMatrix.translate( -aTranslation.getX(), -aTranslation.getY() );
     170          56 :                         aTextBoxMatrix.rotate((360.0 - GetCustomShapeObj().GetExtraTextRotation(true)) * F_PI180);
     171          56 :                         aTextBoxMatrix.translate( aTranslation.getX(), aTranslation.getY() );
     172             :                     }
     173             :                     // give text object a size
     174        2326 :                     aTextBoxMatrix.scale(aTextRange.getWidth(), aTextRange.getHeight());
     175             : 
     176             :                     // check if we have a rotation/shear at all to take care of
     177        2326 :                     const double fExtraTextRotation(GetCustomShapeObj().GetExtraTextRotation());
     178        2326 :                     const GeoStat& rGeoStat(GetCustomShapeObj().GetGeoStat());
     179             : 
     180        2326 :                     if(rGeoStat.nShearAngle || rGeoStat.nRotationAngle || !basegfx::fTools::equalZero(fExtraTextRotation))
     181             :                     {
     182         184 :                         if(aObjectRange != aTextRange)
     183             :                         {
     184             :                             // move relative to unrotated object range
     185             :                             aTextBoxMatrix.translate(
     186          64 :                                 aTextRange.getMinX() - aObjectRange.getMinimum().getX(),
     187          96 :                                 aTextRange.getMinY() - aObjectRange.getMinimum().getY());
     188             :                         }
     189             : 
     190         184 :                         if(!basegfx::fTools::equalZero(fExtraTextRotation))
     191             :                         {
     192             :                             basegfx::B2DVector aTranslation(
     193           0 :                                 ( aTextRange.getWidth() / 2 ) + ( aTextRange.getMinX() - aObjectRange.getMinimum().getX() ),
     194           0 :                                 ( aTextRange.getHeight() / 2 ) + ( aTextRange.getMinY() - aObjectRange.getMinimum().getY() ) );
     195           0 :                             aTextBoxMatrix.translate( -aTranslation.getX(), -aTranslation.getY() );
     196           0 :                             aTextBoxMatrix.rotate((360.0 - fExtraTextRotation) * F_PI180);
     197           0 :                             aTextBoxMatrix.translate( aTranslation.getX(), aTranslation.getY() );
     198             :                         }
     199             : 
     200         184 :                         if(rGeoStat.nShearAngle)
     201             :                         {
     202           0 :                             aTextBoxMatrix.shearX(tan((36000 - rGeoStat.nShearAngle) * F_PI18000));
     203             :                         }
     204             : 
     205         184 :                         if(rGeoStat.nRotationAngle)
     206             :                         {
     207         184 :                             aTextBoxMatrix.rotate((36000 - rGeoStat.nRotationAngle) * F_PI18000);
     208             :                         }
     209             : 
     210             :                         // give text it's target position
     211         184 :                         aTextBoxMatrix.translate(aObjectRange.getMinimum().getX(), aObjectRange.getMinimum().getY());
     212             :                     }
     213             :                     else
     214             :                     {
     215        2142 :                         aTextBoxMatrix.translate(aTextRange.getMinX(), aTextRange.getMinY());
     216             :                     }
     217             : 
     218             :                     // check if SdrTextWordWrapItem is set
     219        2326 :                     bWordWrap = (static_cast<const SdrOnOffItem&>(GetCustomShapeObj().GetMergedItem(SDRATTR_TEXT_WORDWRAP))).GetValue();
     220             :                 }
     221             : 
     222             :                 // create primitive
     223             :                 const drawinglayer::primitive2d::Primitive2DReference xReference(
     224             :                     new drawinglayer::primitive2d::SdrCustomShapePrimitive2D(
     225             :                         aAttribute,
     226             :                         xGroup,
     227             :                         aTextBoxMatrix,
     228             :                         bWordWrap,
     229             :                         b3DShape,
     230       18388 :                         false));        // #SJ# New parameter to force to clipped BlockText for SC
     231       18388 :                 xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
     232             :             }
     233             : 
     234       27792 :             return xRetval;
     235             :         }
     236             :     } // end of namespace contact
     237         651 : } // end of namespace sdr
     238             : 
     239             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10