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

Generated by: LCOV version 1.10