LCOV - code coverage report
Current view: top level - svx/source/sdr/contact - viewcontactofsdrobjcustomshape.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 87 0.0 %
Date: 2014-04-14 Functions: 0 5 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             : #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           0 :         ViewContactOfSdrObjCustomShape::ViewContactOfSdrObjCustomShape(SdrObjCustomShape& rCustomShape)
      39           0 :         :   ViewContactOfTextObj(rCustomShape)
      40             :         {
      41           0 :         }
      42             : 
      43           0 :         ViewContactOfSdrObjCustomShape::~ViewContactOfSdrObjCustomShape()
      44             :         {
      45           0 :         }
      46             : 
      47           0 :         basegfx::B2DRange ViewContactOfSdrObjCustomShape::getCorrectedTextBoundRect() const
      48             :         {
      49           0 :             Rectangle aObjectBound(GetCustomShapeObj().GetGeoRect());
      50           0 :             aObjectBound += GetCustomShapeObj().GetGridOffset();
      51           0 :             Rectangle aTextBound(aObjectBound);
      52           0 :             GetCustomShapeObj().GetTextBounds(aTextBound);
      53           0 :             aTextBound += GetCustomShapeObj().GetGridOffset();
      54           0 :             basegfx::B2DRange aTextRange(aTextBound.Left(), aTextBound.Top(), aTextBound.Right(), aTextBound.Bottom());
      55           0 :             const basegfx::B2DRange aObjectRange(aObjectBound.Left(), aObjectBound.Top(), aObjectBound.Right(), aObjectBound.Bottom());
      56             : 
      57             :             // no need to correct if no extra text range
      58           0 :             if(aTextRange != aObjectRange)
      59             :             {
      60           0 :                 const GeoStat& rGeoStat(GetCustomShapeObj().GetGeoStat());
      61             : 
      62             :                 // only correct when rotation and/or shear is used
      63           0 :                 if(rGeoStat.nShearWink || rGeoStat.nDrehWink )
      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           0 :                     basegfx::B2DVector aTranslation(aObjectRange.getCenter());
      70             : 
      71             :                     // get rotated and sheared object's range
      72           0 :                     basegfx::B2DRange aRotObjectRange(aObjectRange);
      73           0 :                     basegfx::B2DHomMatrix aRotMatrix;
      74             : 
      75           0 :                     aRotMatrix.translate(-aObjectRange.getMinimum().getX(), -aObjectRange.getMinimum().getY());
      76             : 
      77           0 :                     if(rGeoStat.nShearWink)
      78             :                     {
      79           0 :                         aRotMatrix.shearX(tan((36000 - rGeoStat.nShearWink) * F_PI18000));
      80             :                     }
      81             : 
      82           0 :                     if(rGeoStat.nDrehWink)
      83             :                     {
      84           0 :                         aRotMatrix.rotate((36000 - rGeoStat.nDrehWink) * F_PI18000);
      85             :                     }
      86             : 
      87           0 :                     aRotMatrix.translate(aObjectRange.getMinimum().getX(), aObjectRange.getMinimum().getY());
      88           0 :                     aRotObjectRange.transform(aRotMatrix);
      89             : 
      90             :                     // add negative translation part
      91           0 :                     aTranslation -= aRotObjectRange.getCenter();
      92             : 
      93             :                     // create new range
      94             :                     aTextRange = basegfx::B2DRange(
      95           0 :                         aTextRange.getMinX() + aTranslation.getX(), aTextRange.getMinY() + aTranslation.getY(),
      96           0 :                         aTextRange.getMaxX() + aTranslation.getX(), aTextRange.getMaxY() + aTranslation.getY());
      97             :                 }
      98             :             }
      99             : 
     100           0 :             return aTextRange;
     101             :         }
     102             : 
     103           0 :         drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrObjCustomShape::createViewIndependentPrimitive2DSequence() const
     104             :         {
     105           0 :             drawinglayer::primitive2d::Primitive2DSequence xRetval;
     106           0 :             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           0 :                     GetCustomShapeObj().getText(0),
     114           0 :                     GetCustomShapeObj().IsTextPath()));
     115           0 :             drawinglayer::primitive2d::Primitive2DSequence xGroup;
     116           0 :             bool bHasText(!aAttribute.getText().isDefault());
     117             : 
     118             :             // create Primitive2DSequence from sub-geometry
     119           0 :             const SdrObject* pSdrObjRepresentation = GetCustomShapeObj().GetSdrObjectFromCustomShape();
     120           0 :             bool b3DShape(false);
     121             : 
     122           0 :             Point aGridOff = GetCustomShapeObj().GetGridOffset();
     123             : 
     124           0 :             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           0 :                 const_cast< SdrObject* >( pSdrObjRepresentation )->SetGridOffset( aGridOff );
     130           0 :                 SdrObjListIter aIterator(*pSdrObjRepresentation);
     131             : 
     132           0 :                 while(aIterator.IsMore())
     133             :                 {
     134           0 :                     SdrObject& rCandidate = *aIterator.Next();
     135             :                     // apply offset to each part
     136           0 :                     rCandidate.SetGridOffset( aGridOff );
     137           0 :                     if(!b3DShape && dynamic_cast< E3dObject* >(&rCandidate))
     138             :                     {
     139           0 :                         b3DShape = true;
     140             :                     }
     141             : 
     142           0 :                     const drawinglayer::primitive2d::Primitive2DSequence xNew(rCandidate.GetViewContact().getViewIndependentPrimitive2DSequence());
     143           0 :                     drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xGroup, xNew);
     144           0 :                 }
     145             :             }
     146             : 
     147           0 :             if(bHasText || xGroup.hasElements())
     148             :             {
     149             :                 // prepare text box geometry
     150           0 :                 basegfx::B2DHomMatrix aTextBoxMatrix;
     151           0 :                 bool bWordWrap(false);
     152             : 
     153           0 :                 if(bHasText)
     154             :                 {
     155             :                     // take unrotated snap rect as default, then get the
     156             :                     // unrotated text box. Rotation needs to be done centered
     157           0 :                     Rectangle aObjectBound(GetCustomShapeObj().GetGeoRect());
     158             :                     // hack for calc grid sync
     159           0 :                     aObjectBound += GetCustomShapeObj().GetGridOffset();
     160           0 :                     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           0 :                     const basegfx::B2DRange aTextRange(getCorrectedTextBoundRect());
     164             : 
     165             :                     // Rotation before scaling
     166           0 :                     if(!basegfx::fTools::equalZero(GetCustomShapeObj().GetExtraTextRotation(true)))
     167             :                     {
     168           0 :                         basegfx::B2DVector aTranslation(0.5, 0.5);
     169           0 :                         aTextBoxMatrix.translate( -aTranslation.getX(), -aTranslation.getY() );
     170           0 :                         aTextBoxMatrix.rotate((360.0 - GetCustomShapeObj().GetExtraTextRotation(true)) * F_PI180);
     171           0 :                         aTextBoxMatrix.translate( aTranslation.getX(), aTranslation.getY() );
     172             :                     }
     173             :                     // give text object a size
     174           0 :                     aTextBoxMatrix.scale(aTextRange.getWidth(), aTextRange.getHeight());
     175             : 
     176             :                     // check if we have a rotation/shear at all to take care of
     177           0 :                     const double fExtraTextRotation(GetCustomShapeObj().GetExtraTextRotation());
     178           0 :                     const GeoStat& rGeoStat(GetCustomShapeObj().GetGeoStat());
     179             : 
     180           0 :                     if(rGeoStat.nShearWink || rGeoStat.nDrehWink || !basegfx::fTools::equalZero(fExtraTextRotation))
     181             :                     {
     182           0 :                         if(aObjectRange != aTextRange)
     183             :                         {
     184             :                             // move relative to unrotated object range
     185             :                             aTextBoxMatrix.translate(
     186           0 :                                 aTextRange.getMinX() - aObjectRange.getMinimum().getX(),
     187           0 :                                 aTextRange.getMinY() - aObjectRange.getMinimum().getY());
     188             :                         }
     189             : 
     190           0 :                         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           0 :                         if(rGeoStat.nShearWink)
     201             :                         {
     202           0 :                             aTextBoxMatrix.shearX(tan((36000 - rGeoStat.nShearWink) * F_PI18000));
     203             :                         }
     204             : 
     205           0 :                         if(rGeoStat.nDrehWink)
     206             :                         {
     207           0 :                             aTextBoxMatrix.rotate((36000 - rGeoStat.nDrehWink) * F_PI18000);
     208             :                         }
     209             : 
     210             :                         // give text it's target position
     211           0 :                         aTextBoxMatrix.translate(aObjectRange.getMinimum().getX(), aObjectRange.getMinimum().getY());
     212             :                     }
     213             :                     else
     214             :                     {
     215           0 :                         aTextBoxMatrix.translate(aTextRange.getMinX(), aTextRange.getMinY());
     216             :                     }
     217             : 
     218             :                     // check if SdrTextWordWrapItem is set
     219           0 :                     bWordWrap = ((SdrTextWordWrapItem&)(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           0 :                         false));        // #SJ# New parameter to force to clipped BlockText for SC
     231           0 :                 xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
     232             :             }
     233             : 
     234           0 :             return xRetval;
     235             :         }
     236             :     } // end of namespace contact
     237             : } // end of namespace sdr
     238             : 
     239             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10