LCOV - code coverage report
Current view: top level - chart2/source/view/main - LabelPositionHelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 80 245 32.7 %
Date: 2012-08-25 Functions: 10 16 62.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 58 201 28.9 %

           Branch data     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 "LabelPositionHelper.hxx"
      22                 :            : #include "PlottingPositionHelper.hxx"
      23                 :            : #include "CommonConverters.hxx"
      24                 :            : #include "PropertyMapper.hxx"
      25                 :            : #include "ShapeFactory.hxx"
      26                 :            : #include "macros.hxx"
      27                 :            : #include "RelativeSizeHelper.hxx"
      28                 :            : #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
      29                 :            : #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
      30                 :            : 
      31                 :            : //.............................................................................
      32                 :            : namespace chart
      33                 :            : {
      34                 :            : //.............................................................................
      35                 :            : using namespace ::com::sun::star;
      36                 :            : using namespace ::com::sun::star::chart2;
      37                 :            : 
      38                 :       2272 : LabelPositionHelper::LabelPositionHelper(
      39                 :            :                     PlottingPositionHelper* pPosHelper
      40                 :            :                     , sal_Int32 nDimensionCount
      41                 :            :                     , const uno::Reference< drawing::XShapes >& xLogicTarget
      42                 :            :                     , ShapeFactory* pShapeFactory )
      43                 :            :                     : m_pPosHelper(pPosHelper)
      44                 :            :                     , m_nDimensionCount(nDimensionCount)
      45                 :            :                     , m_xLogicTarget(xLogicTarget)
      46                 :       2272 :                     , m_pShapeFactory(pShapeFactory)
      47                 :            : {
      48                 :       2272 : }
      49                 :            : 
      50                 :       2272 : LabelPositionHelper::~LabelPositionHelper()
      51                 :            : {
      52         [ -  + ]:       2272 : }
      53                 :            : 
      54                 :       2272 : awt::Point LabelPositionHelper::transformSceneToScreenPosition( const drawing::Position3D& rScenePosition3D ) const
      55                 :            : {
      56                 :            :     return PlottingPositionHelper::transformSceneToScreenPosition(
      57                 :       2272 :                   rScenePosition3D, m_xLogicTarget, m_pShapeFactory, m_nDimensionCount );
      58                 :            : }
      59                 :            : 
      60                 :       5692 : void LabelPositionHelper::changeTextAdjustment( tAnySequence& rPropValues, const tNameSequence& rPropNames, LabelAlignment eAlignment)
      61                 :            : {
      62                 :            :     //HorizontalAdjustment
      63                 :            :     {
      64                 :       5692 :         drawing::TextHorizontalAdjust eHorizontalAdjust = drawing::TextHorizontalAdjust_CENTER;
      65 [ +  + ][ +  - ]:       5692 :         if( LABEL_ALIGN_RIGHT==eAlignment || LABEL_ALIGN_RIGHT_TOP==eAlignment || LABEL_ALIGN_RIGHT_BOTTOM==eAlignment )
                 [ -  + ]
      66                 :         44 :             eHorizontalAdjust = drawing::TextHorizontalAdjust_LEFT;
      67 [ +  + ][ +  - ]:       5648 :         else if( LABEL_ALIGN_LEFT==eAlignment || LABEL_ALIGN_LEFT_TOP==eAlignment || LABEL_ALIGN_LEFT_BOTTOM==eAlignment )
                 [ -  + ]
      68                 :       1452 :             eHorizontalAdjust = drawing::TextHorizontalAdjust_RIGHT;
      69 [ +  - ][ +  - ]:       5692 :         uno::Any* pHorizontalAdjustAny = PropertyMapper::getValuePointer(rPropValues,rPropNames,C2U("TextHorizontalAdjust"));
      70         [ +  - ]:       5692 :         if(pHorizontalAdjustAny)
      71         [ +  - ]:       5692 :             *pHorizontalAdjustAny = uno::makeAny(eHorizontalAdjust);
      72                 :            :     }
      73                 :            : 
      74                 :            :     //VerticalAdjustment
      75                 :            :     {
      76                 :       5692 :         drawing::TextVerticalAdjust eVerticalAdjust = drawing::TextVerticalAdjust_CENTER;
      77 [ +  + ][ +  - ]:       5692 :         if( LABEL_ALIGN_TOP==eAlignment || LABEL_ALIGN_RIGHT_TOP==eAlignment || LABEL_ALIGN_LEFT_TOP==eAlignment )
                 [ -  + ]
      78                 :       2416 :             eVerticalAdjust = drawing::TextVerticalAdjust_BOTTOM;
      79 [ +  + ][ +  - ]:       3276 :         else if( LABEL_ALIGN_BOTTOM==eAlignment || LABEL_ALIGN_RIGHT_BOTTOM==eAlignment || LABEL_ALIGN_LEFT_BOTTOM==eAlignment )
                 [ -  + ]
      80                 :       1780 :             eVerticalAdjust = drawing::TextVerticalAdjust_TOP;
      81 [ +  - ][ +  - ]:       5692 :         uno::Any* pVerticalAdjustAny = PropertyMapper::getValuePointer(rPropValues,rPropNames,C2U("TextVerticalAdjust"));
      82         [ +  - ]:       5692 :         if(pVerticalAdjustAny)
      83         [ +  - ]:       5692 :             *pVerticalAdjustAny = uno::makeAny(eVerticalAdjust);
      84                 :            :     }
      85                 :       5692 : }
      86                 :            : 
      87                 :          0 : void lcl_doDynamicFontResize( uno::Any* pAOldAndNewFontHeightAny
      88                 :            :                           , const awt::Size& rOldReferenceSize
      89                 :            :                           , const awt::Size& rNewReferenceSize  )
      90                 :            : {
      91                 :          0 :     double fOldFontHeight = 0;
      92 [ #  # ][ #  # ]:          0 :     if( pAOldAndNewFontHeightAny && ( *pAOldAndNewFontHeightAny >>= fOldFontHeight ) )
                 [ #  # ]
      93                 :            :     {
      94         [ #  # ]:          0 :         double fNewFontHeight = RelativeSizeHelper::calculate( fOldFontHeight, rOldReferenceSize, rNewReferenceSize );
      95         [ #  # ]:          0 :         *pAOldAndNewFontHeightAny = uno::makeAny(fNewFontHeight);
      96                 :            :     }
      97                 :          0 : }
      98                 :            : 
      99                 :       3820 : void LabelPositionHelper::doDynamicFontResize( tAnySequence& rPropValues
     100                 :            :                     , const tNameSequence& rPropNames
     101                 :            :                     , const uno::Reference< beans::XPropertySet >& xAxisModelProps
     102                 :            :                     , const awt::Size& rNewReferenceSize
     103                 :            :                     )
     104                 :            : {
     105                 :            :     //-------------------------
     106                 :            :     //handle dynamic font resize:
     107                 :       3820 :     awt::Size aOldReferenceSize;
     108 [ +  - ][ +  - ]:       3820 :     if( xAxisModelProps->getPropertyValue( C2U("ReferencePageSize")) >>= aOldReferenceSize )
         [ +  - ][ -  + ]
                 [ +  - ]
     109                 :            :     {
     110 [ #  # ][ #  # ]:          0 :         uno::Any* pAOldAndNewFontHeightAny = PropertyMapper::getValuePointer( rPropValues, rPropNames, C2U("CharHeight") );
     111         [ #  # ]:          0 :         lcl_doDynamicFontResize( pAOldAndNewFontHeightAny, aOldReferenceSize, rNewReferenceSize );
     112 [ #  # ][ #  # ]:          0 :         pAOldAndNewFontHeightAny = PropertyMapper::getValuePointer( rPropValues, rPropNames, C2U("CharHeightAsian") );
     113         [ #  # ]:          0 :         lcl_doDynamicFontResize( pAOldAndNewFontHeightAny, aOldReferenceSize, rNewReferenceSize );
     114 [ #  # ][ #  # ]:          0 :         pAOldAndNewFontHeightAny = PropertyMapper::getValuePointer( rPropValues, rPropNames, C2U("CharHeightComplex") );
     115         [ #  # ]:          0 :         lcl_doDynamicFontResize( pAOldAndNewFontHeightAny, aOldReferenceSize, rNewReferenceSize );
     116                 :            :     }
     117                 :       3820 : }
     118                 :            : 
     119                 :            : namespace
     120                 :            : {
     121                 :            : 
     122                 :      12504 : void lcl_correctRotation_Left( double& rfXCorrection, double& rfYCorrection
     123                 :            :                            , double fAnglePositiveDegree, const awt::Size& aSize, bool bRotateAroundCenter )
     124                 :            : {
     125                 :            :     //correct label positions for labels on a left side of something with a right centered alignment
     126                 :      12504 :     double fAnglePi = fAnglePositiveDegree*F_PI/180.0;
     127         [ +  + ]:      12504 :     if( fAnglePositiveDegree==0.0 )
     128                 :            :     {
     129                 :            :     }
     130         [ +  - ]:         66 :     else if( fAnglePositiveDegree<= 90.0 )
     131                 :            :     {
     132                 :         66 :         rfXCorrection = -aSize.Height*rtl::math::sin( fAnglePi )/2.0;
     133         [ -  + ]:         66 :         if( bRotateAroundCenter )
     134                 :          0 :             rfYCorrection = -aSize.Width*rtl::math::sin( fAnglePi )/2.0;
     135                 :            :     }
     136         [ #  # ]:          0 :     else if( fAnglePositiveDegree<= 180.0 )
     137                 :            :     {
     138                 :          0 :         double beta = fAnglePi-F_PI/2.0;
     139                 :          0 :         rfXCorrection = -aSize.Width *rtl::math::sin( beta )
     140                 :          0 :             -aSize.Height *rtl::math::cos( beta )/2.0;
     141         [ #  # ]:          0 :         if( bRotateAroundCenter )
     142                 :          0 :             rfYCorrection = -aSize.Width *rtl::math::cos( beta )/2.0;
     143                 :            :         else
     144                 :          0 :             rfYCorrection = -aSize.Width *rtl::math::cos( beta );
     145                 :            :     }
     146         [ #  # ]:          0 :     else if( fAnglePositiveDegree<= 270.0 )
     147                 :            :     {
     148                 :          0 :         double beta = fAnglePi - F_PI;
     149                 :          0 :         rfXCorrection = -aSize.Width *rtl::math::cos( beta )
     150                 :          0 :             -aSize.Height*rtl::math::sin( beta )/2.0;
     151         [ #  # ]:          0 :         if( bRotateAroundCenter )
     152                 :          0 :             rfYCorrection = aSize.Width *rtl::math::sin( beta )/2.0;
     153                 :            :         else
     154                 :          0 :             rfYCorrection = aSize.Width *rtl::math::sin( beta );
     155                 :            :     }
     156                 :            :     else
     157                 :            :     {
     158                 :          0 :         double beta = 2*F_PI - fAnglePi;
     159                 :          0 :         rfXCorrection = -aSize.Height*rtl::math::sin( beta )/2.0;
     160         [ #  # ]:          0 :         if( bRotateAroundCenter )
     161                 :          0 :             rfYCorrection = aSize.Width*rtl::math::sin( beta )/2.0;
     162                 :            :     }
     163                 :      12504 : }
     164                 :            : 
     165                 :        273 : void lcl_correctRotation_Right( double& rfXCorrection, double& rfYCorrection
     166                 :            :                            , double fAnglePositiveDegree, const awt::Size& aSize, bool bRotateAroundCenter )
     167                 :            : {
     168                 :            :     //correct label positions for labels on a right side of something with a left centered alignment
     169                 :        273 :     double fAnglePi = fAnglePositiveDegree*F_PI/180.0;
     170         [ +  + ]:        273 :     if( fAnglePositiveDegree== 0.0 )
     171                 :            :     {
     172                 :            :     }
     173         [ +  - ]:        192 :     else if( fAnglePositiveDegree<= 90.0 )
     174                 :            :     {
     175                 :        192 :         rfXCorrection = aSize.Height*rtl::math::sin( fAnglePi )/2.0;
     176         [ -  + ]:        192 :         if( bRotateAroundCenter )
     177                 :          0 :             rfYCorrection = aSize.Width*rtl::math::sin( fAnglePi )/2.0;
     178                 :            :     }
     179         [ #  # ]:          0 :     else if( fAnglePositiveDegree<= 180.0 )
     180                 :            :     {
     181                 :          0 :         double beta = F_PI - fAnglePi;
     182                 :          0 :         rfXCorrection = aSize.Width *rtl::math::cos( beta )
     183                 :          0 :             + aSize.Height*rtl::math::sin( beta )/2.0;
     184         [ #  # ]:          0 :         if( bRotateAroundCenter )
     185                 :          0 :             rfYCorrection = aSize.Width *rtl::math::sin( beta )/2.0;
     186                 :            :         else
     187                 :          0 :             rfYCorrection = aSize.Width *rtl::math::sin( beta );
     188                 :            :     }
     189         [ #  # ]:          0 :     else if( fAnglePositiveDegree<= 270.0 )
     190                 :            :     {
     191                 :          0 :         double beta = 3*F_PI/2.0 - fAnglePi;
     192                 :          0 :         rfXCorrection = aSize.Width *rtl::math::sin( beta )
     193                 :          0 :                     +aSize.Height*rtl::math::cos( beta )/2.0;
     194         [ #  # ]:          0 :         if( bRotateAroundCenter )
     195                 :          0 :             rfYCorrection = -aSize.Width *rtl::math::cos( beta )/2.0;
     196                 :            :         else
     197                 :          0 :             rfYCorrection = -aSize.Width *rtl::math::cos( beta );
     198                 :            :     }
     199                 :            :     else
     200                 :            :     {
     201                 :          0 :         rfXCorrection  = aSize.Height*rtl::math::sin( 2*F_PI - fAnglePi )/2.0;
     202         [ #  # ]:          0 :         if( bRotateAroundCenter )
     203                 :          0 :             rfYCorrection = -aSize.Width*rtl::math::sin( 2*F_PI - fAnglePi )/2.0;
     204                 :            :     }
     205                 :        273 : }
     206                 :            : 
     207                 :       1002 : void lcl_correctRotation_Top( double& rfXCorrection, double& rfYCorrection
     208                 :            :                            , double fAnglePositiveDegree, const awt::Size& aSize, bool bRotateAroundCenter )
     209                 :            : {
     210                 :            :     //correct label positions for labels on top of something with a bottom centered alignment
     211                 :       1002 :     double fAnglePi = fAnglePositiveDegree*F_PI/180.0;
     212         [ +  + ]:       1002 :     if( fAnglePositiveDegree== 0.0 )
     213                 :            :     {
     214                 :            :     }
     215         [ +  - ]:        138 :     else if( fAnglePositiveDegree<= 90.0 )
     216                 :            :     {
     217                 :        138 :         rfXCorrection = aSize.Height*rtl::math::sin( fAnglePi )/2.0;
     218         [ -  + ]:        138 :         if( !bRotateAroundCenter )
     219                 :          0 :             rfXCorrection += aSize.Width*rtl::math::cos( fAnglePi )/2.0;
     220                 :        138 :         rfYCorrection = -aSize.Width*rtl::math::sin( fAnglePi )/2.0;
     221                 :            :     }
     222         [ #  # ]:          0 :     else if( fAnglePositiveDegree<= 180.0 )
     223                 :            :     {
     224                 :          0 :         double beta = fAnglePi - F_PI/2.0;
     225                 :          0 :         rfXCorrection = aSize.Height*rtl::math::cos( beta )/2.0;
     226         [ #  # ]:          0 :         if( !bRotateAroundCenter )
     227                 :          0 :             rfXCorrection -= aSize.Width*rtl::math::sin( beta )/2.0;
     228                 :          0 :         rfYCorrection = -aSize.Width*rtl::math::cos( beta )/2.0
     229                 :          0 :             - aSize.Height*rtl::math::sin( beta );
     230                 :            :     }
     231         [ #  # ]:          0 :     else if( fAnglePositiveDegree<= 270.0 )
     232                 :            :     {
     233                 :          0 :         double beta = fAnglePi - F_PI;
     234                 :          0 :         rfXCorrection = -aSize.Height *rtl::math::sin( beta )/2.0;
     235         [ #  # ]:          0 :         if( !bRotateAroundCenter )
     236                 :          0 :             rfXCorrection += aSize.Width *rtl::math::cos( beta )/2.0;
     237                 :          0 :         rfYCorrection = -aSize.Width *rtl::math::sin( beta )/2.0
     238                 :          0 :             -aSize.Height *rtl::math::cos( beta );
     239                 :            :     }
     240                 :            :     else
     241                 :            :     {
     242                 :          0 :         rfXCorrection = aSize.Height*rtl::math::sin( fAnglePi )/2.0;
     243         [ #  # ]:          0 :         if( !bRotateAroundCenter )
     244                 :          0 :             rfXCorrection -= aSize.Width*rtl::math::cos( fAnglePi )/2.0;
     245                 :          0 :         rfYCorrection = aSize.Width*rtl::math::sin( fAnglePi )/2.0;
     246                 :            :     }
     247                 :       1002 : }
     248                 :            : 
     249                 :      11550 : void lcl_correctRotation_Bottom( double& rfXCorrection, double& rfYCorrection
     250                 :            :                            , double fAnglePositiveDegree, const awt::Size& aSize, bool bRotateAroundCenter )
     251                 :            : {
     252                 :            :     //correct label positions for labels below something with a top centered alignment
     253                 :      11550 :     double fAnglePi = fAnglePositiveDegree*F_PI/180.0;
     254         [ +  + ]:      11550 :     if( fAnglePositiveDegree==0.0 )
     255                 :            :     {
     256                 :            :     }
     257         [ +  - ]:         78 :     else if( fAnglePositiveDegree<= 90.0 )
     258                 :            :     {
     259                 :         78 :         rfXCorrection = -aSize.Height*rtl::math::sin( fAnglePi )/2.0;
     260         [ +  - ]:         78 :         if( !bRotateAroundCenter )
     261                 :         78 :             rfXCorrection -= aSize.Width *rtl::math::cos( fAnglePi )/2.0;
     262                 :         78 :         rfYCorrection = aSize.Width*rtl::math::sin( fAnglePi )/2.0;
     263                 :            :     }
     264         [ #  # ]:          0 :     else if( fAnglePositiveDegree<= 180.0 )
     265                 :            :     {
     266                 :          0 :         double beta = fAnglePi-F_PI/2.0;
     267                 :          0 :         rfXCorrection = -aSize.Height*rtl::math::cos( beta )/2.0;
     268         [ #  # ]:          0 :         if( !bRotateAroundCenter )
     269                 :          0 :             rfXCorrection += aSize.Width *rtl::math::sin( beta )/2.0;
     270                 :          0 :         rfYCorrection = aSize.Width *rtl::math::cos( beta )/2.0
     271                 :          0 :             +aSize.Height*rtl::math::sin( beta );
     272                 :            :     }
     273         [ #  # ]:          0 :     else if( fAnglePositiveDegree<= 270.0 )
     274                 :            :     {
     275                 :          0 :         double beta = 3*F_PI/2.0 - fAnglePi;
     276                 :          0 :         rfXCorrection = aSize.Height*rtl::math::cos( beta )/2.0;
     277         [ #  # ]:          0 :         if( !bRotateAroundCenter )
     278                 :          0 :             rfXCorrection -= aSize.Width *rtl::math::sin( beta )/2.0;
     279                 :          0 :         rfYCorrection = aSize.Height*rtl::math::sin( beta )
     280                 :          0 :                         +aSize.Width*rtl::math::cos( beta )/2.0;
     281                 :            :     }
     282                 :            :     else
     283                 :            :     {
     284                 :          0 :         double beta = 2*F_PI - fAnglePi;
     285                 :          0 :         rfXCorrection = aSize.Height*rtl::math::sin( beta )/2.0;
     286         [ #  # ]:          0 :         if( !bRotateAroundCenter )
     287                 :          0 :             rfXCorrection += aSize.Width*rtl::math::cos( beta )/2.0;
     288                 :          0 :         rfYCorrection = aSize.Width*rtl::math::sin( beta )/2.0;
     289                 :            :     }
     290                 :      11550 : }
     291                 :            : 
     292                 :          0 : void lcl_correctRotation_Left_Top( double& rfXCorrection, double& rfYCorrection
     293                 :            :                            , double fAnglePositiveDegree, const awt::Size& aSize )
     294                 :            : {
     295                 :            :     //correct position for labels at the left top corner of something with a bottom right alignment
     296                 :          0 :     double fAnglePi = fAnglePositiveDegree*F_PI/180.0;
     297         [ #  # ]:          0 :     if( fAnglePositiveDegree==0.0 )
     298                 :            :     {
     299                 :            :     }
     300         [ #  # ]:          0 :     else if( fAnglePositiveDegree<= 90.0 )
     301                 :            :     {
     302                 :          0 :         rfYCorrection = -aSize.Width*rtl::math::sin( fAnglePi );
     303                 :            :     }
     304         [ #  # ]:          0 :     else if( fAnglePositiveDegree<= 180.0 )
     305                 :            :     {
     306                 :          0 :         double beta = fAnglePi-F_PI/2.0;
     307                 :          0 :         rfXCorrection = -aSize.Width*rtl::math::sin( beta );
     308                 :          0 :         rfYCorrection = -aSize.Height*rtl::math::sin( beta )
     309                 :          0 :                         -aSize.Width*rtl::math::cos( beta );
     310                 :            :     }
     311         [ #  # ]:          0 :     else if( fAnglePositiveDegree<= 270.0 )
     312                 :            :     {
     313                 :          0 :         double beta = 3*F_PI/2.0 - fAnglePi;
     314                 :          0 :         rfXCorrection = -aSize.Height*rtl::math::cos( beta )
     315                 :          0 :                         -aSize.Width*rtl::math::sin( beta );
     316                 :          0 :         rfYCorrection = -aSize.Height*rtl::math::sin( beta );
     317                 :            :     }
     318                 :            :     else
     319                 :            :     {
     320                 :          0 :         rfXCorrection = aSize.Height*rtl::math::sin( fAnglePi );
     321                 :            :     }
     322                 :          0 : }
     323                 :            : 
     324                 :          0 : void lcl_correctRotation_Left_Bottom( double& rfXCorrection, double& rfYCorrection
     325                 :            :                            , double fAnglePositiveDegree, const awt::Size& aSize )
     326                 :            : {
     327                 :            :     //correct position for labels at the left bottom corner of something with a top right alignment
     328                 :          0 :     double fAnglePi = fAnglePositiveDegree*F_PI/180.0;
     329         [ #  # ]:          0 :     if( fAnglePositiveDegree==0.0 )
     330                 :            :     {
     331                 :            :     }
     332         [ #  # ]:          0 :     else if( fAnglePositiveDegree<= 90.0 )
     333                 :            :     {
     334                 :          0 :         rfXCorrection = -aSize.Height*rtl::math::sin( fAnglePi );
     335                 :            :     }
     336         [ #  # ]:          0 :     else if( fAnglePositiveDegree<= 180.0 )
     337                 :            :     {
     338                 :          0 :         double beta = fAnglePi-F_PI/2.0;
     339                 :          0 :         rfXCorrection = -aSize.Width*rtl::math::sin( beta )
     340                 :          0 :                         -aSize.Height*rtl::math::cos( beta );;
     341                 :          0 :         rfYCorrection = aSize.Height*rtl::math::sin( beta );
     342                 :            :     }
     343         [ #  # ]:          0 :     else if( fAnglePositiveDegree<= 270.0 )
     344                 :            :     {
     345                 :          0 :         double beta = 3*F_PI/2.0 - fAnglePi;
     346                 :          0 :         rfXCorrection = -aSize.Width*rtl::math::sin( beta );
     347                 :          0 :         rfYCorrection = aSize.Width*rtl::math::cos( beta )
     348                 :          0 :                         +aSize.Height*rtl::math::sin( beta );
     349                 :            :     }
     350                 :            :     else
     351                 :            :     {
     352                 :          0 :         rfYCorrection = -aSize.Width*rtl::math::sin( fAnglePi );
     353                 :            :     }
     354                 :          0 : }
     355                 :            : 
     356                 :          0 : void lcl_correctRotation_Right_Top( double& rfXCorrection, double& rfYCorrection
     357                 :            :                            , double fAnglePositiveDegree, const awt::Size& aSize )
     358                 :            : {
     359                 :            :     //correct position for labels at the right top corner of something with a bottom left alignment
     360                 :          0 :     double fAnglePi = fAnglePositiveDegree*F_PI/180.0;
     361         [ #  # ]:          0 :     if( fAnglePositiveDegree==0.0 )
     362                 :            :     {
     363                 :            :     }
     364         [ #  # ]:          0 :     else if( fAnglePositiveDegree<= 90.0 )
     365                 :            :     {
     366                 :          0 :         rfXCorrection = aSize.Height*rtl::math::sin( fAnglePi );
     367                 :            :     }
     368         [ #  # ]:          0 :     else if( fAnglePositiveDegree<= 180.0 )
     369                 :            :     {
     370                 :          0 :         double beta = fAnglePi-F_PI/2.0;
     371                 :          0 :         rfXCorrection = aSize.Width*rtl::math::sin( beta )
     372                 :          0 :                         +aSize.Height*rtl::math::cos( beta );
     373                 :          0 :         rfYCorrection = -aSize.Height*rtl::math::sin( beta );
     374                 :            :     }
     375         [ #  # ]:          0 :     else if( fAnglePositiveDegree<= 270.0 )
     376                 :            :     {
     377                 :          0 :         double beta = 3*F_PI/2.0 - fAnglePi;
     378                 :          0 :         rfXCorrection = aSize.Width*rtl::math::sin( beta );
     379                 :          0 :         rfYCorrection = -aSize.Width*rtl::math::cos( beta )
     380                 :          0 :                         -aSize.Height*rtl::math::sin( beta );
     381                 :            :     }
     382                 :            :     else
     383                 :            :     {
     384                 :          0 :         rfYCorrection = aSize.Width*rtl::math::sin( fAnglePi );
     385                 :            :     }
     386                 :          0 : }
     387                 :            : 
     388                 :          0 : void lcl_correctRotation_Right_Bottom( double& rfXCorrection, double& rfYCorrection
     389                 :            :                            , double fAnglePositiveDegree, const awt::Size& aSize )
     390                 :            : {
     391                 :            :     //correct position for labels at the right bottom corner of something with a top left alignment
     392                 :          0 :     double fAnglePi = fAnglePositiveDegree*F_PI/180.0;
     393         [ #  # ]:          0 :     if( fAnglePositiveDegree==0.0 )
     394                 :            :     {
     395                 :            :     }
     396         [ #  # ]:          0 :     else if( fAnglePositiveDegree<= 90.0 )
     397                 :            :     {
     398                 :          0 :         rfYCorrection = aSize.Width*rtl::math::sin( fAnglePi );
     399                 :            :     }
     400         [ #  # ]:          0 :     else if( fAnglePositiveDegree<= 180.0 )
     401                 :            :     {
     402                 :          0 :         double beta = fAnglePi-F_PI/2.0;
     403                 :          0 :         rfXCorrection = aSize.Width*rtl::math::sin( beta );
     404                 :          0 :         rfYCorrection = aSize.Height*rtl::math::sin( beta )
     405                 :          0 :                         +aSize.Width*rtl::math::cos( beta );
     406                 :            :     }
     407         [ #  # ]:          0 :     else if( fAnglePositiveDegree<= 270.0 )
     408                 :            :     {
     409                 :          0 :         double beta = 3*F_PI/2.0 - fAnglePi;
     410                 :          0 :         rfXCorrection = aSize.Height*rtl::math::cos( beta )
     411                 :          0 :                         +aSize.Width*rtl::math::sin( beta );
     412                 :          0 :         rfYCorrection = aSize.Height*rtl::math::sin( beta );
     413                 :            :     }
     414                 :            :     else
     415                 :            :     {
     416                 :          0 :         rfXCorrection = -aSize.Height*rtl::math::sin( fAnglePi );
     417                 :            :     }
     418                 :          0 : }
     419                 :            : 
     420                 :            : }//end anonymous namespace
     421                 :            : 
     422                 :      25329 : void LabelPositionHelper::correctPositionForRotation( const uno::Reference< drawing::XShape >& xShape2DText
     423                 :            :                      , LabelAlignment eLabelAlignment, const double fRotationAngle, bool bRotateAroundCenter )
     424                 :            : {
     425         [ +  - ]:      25329 :     if( !xShape2DText.is() )
     426                 :      25329 :         return;
     427                 :            : 
     428 [ +  - ][ +  - ]:      25329 :     awt::Point aOldPos = xShape2DText->getPosition();
     429 [ +  - ][ +  - ]:      25329 :     awt::Size  aSize   = xShape2DText->getSize();
     430                 :            : 
     431                 :      25329 :     double fYCorrection = 0.0;
     432                 :      25329 :     double fXCorrection  = 0.0;
     433                 :            : 
     434                 :      25329 :     double fAnglePositiveDegree = fRotationAngle;
     435         [ -  + ]:      25329 :     while(fAnglePositiveDegree<0.0)
     436                 :          0 :         fAnglePositiveDegree+=360.0;
     437                 :            : 
     438   [ +  +  +  +  :      25329 :     switch(eLabelAlignment)
             -  -  -  -  
                      - ]
     439                 :            :     {
     440                 :            :         case LABEL_ALIGN_LEFT:
     441                 :      12504 :             lcl_correctRotation_Left( fXCorrection, fYCorrection, fAnglePositiveDegree, aSize, bRotateAroundCenter );
     442                 :      12504 :             break;
     443                 :            :         case LABEL_ALIGN_RIGHT:
     444                 :        273 :             lcl_correctRotation_Right( fXCorrection, fYCorrection, fAnglePositiveDegree, aSize, bRotateAroundCenter );
     445                 :        273 :             break;
     446                 :            :         case LABEL_ALIGN_TOP:
     447                 :       1002 :             lcl_correctRotation_Top( fXCorrection, fYCorrection, fAnglePositiveDegree, aSize, bRotateAroundCenter );
     448                 :       1002 :             break;
     449                 :            :         case LABEL_ALIGN_BOTTOM:
     450                 :      11550 :             lcl_correctRotation_Bottom( fXCorrection, fYCorrection, fAnglePositiveDegree, aSize, bRotateAroundCenter );
     451                 :      11550 :             break;
     452                 :            :         case LABEL_ALIGN_LEFT_TOP:
     453                 :          0 :             lcl_correctRotation_Left_Top( fXCorrection, fYCorrection, fAnglePositiveDegree, aSize );
     454                 :          0 :             break;
     455                 :            :         case LABEL_ALIGN_LEFT_BOTTOM:
     456                 :          0 :             lcl_correctRotation_Left_Bottom( fXCorrection, fYCorrection, fAnglePositiveDegree, aSize );
     457                 :          0 :             break;
     458                 :            :         case LABEL_ALIGN_RIGHT_TOP:
     459                 :          0 :             lcl_correctRotation_Right_Top( fXCorrection, fYCorrection, fAnglePositiveDegree, aSize );
     460                 :          0 :             break;
     461                 :            :         case LABEL_ALIGN_RIGHT_BOTTOM:
     462                 :          0 :             lcl_correctRotation_Right_Bottom( fXCorrection, fYCorrection, fAnglePositiveDegree, aSize );
     463                 :          0 :             break;
     464                 :            :         default: //LABEL_ALIGN_CENTER
     465                 :          0 :             break;
     466                 :            :     }
     467                 :            : 
     468         [ +  - ]:      25329 :     xShape2DText->setPosition( awt::Point(
     469                 :            :           static_cast<sal_Int32>(aOldPos.X + fXCorrection  )
     470         [ +  - ]:      25329 :         , static_cast<sal_Int32>(aOldPos.Y + fYCorrection ) ) );
     471                 :            : }
     472                 :            : 
     473                 :            : //.............................................................................
     474                 :            : } //namespace chart
     475                 :            : //.............................................................................
     476                 :            : 
     477                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10