LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/view/main - VTitle.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 119 0.0 %
Date: 2012-12-27 Functions: 0 9 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 "VTitle.hxx"
      21             : #include "CommonConverters.hxx"
      22             : #include "macros.hxx"
      23             : #include "PropertyMapper.hxx"
      24             : #include "ShapeFactory.hxx"
      25             : #include "RelativeSizeHelper.hxx"
      26             : #include <com/sun/star/chart2/XFormattedString.hpp>
      27             : #include <rtl/math.hxx>
      28             : #include <com/sun/star/beans/XPropertySet.hpp>
      29             : #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
      30             : #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
      31             : #include <com/sun/star/text/ControlCharacter.hpp>
      32             : #include <com/sun/star/text/XText.hpp>
      33             : #include <com/sun/star/text/XTextCursor.hpp>
      34             : 
      35             : //.............................................................................
      36             : namespace chart
      37             : {
      38             : //.............................................................................
      39             : using namespace ::com::sun::star;
      40             : using namespace ::com::sun::star::chart2;
      41             : 
      42           0 : VTitle::VTitle( const uno::Reference< XTitle > & xTitle )
      43             :                 : m_xTarget(NULL)
      44             :                 , m_xShapeFactory(NULL)
      45             :                 , m_xTitle(xTitle)
      46             :                 , m_xShape(NULL)
      47             :                 , m_aCID()
      48             :                 , m_fRotationAngleDegree(0.0)
      49             :                 , m_nXPos(0)
      50           0 :                 , m_nYPos(0)
      51             : {
      52           0 : }
      53             : 
      54           0 : VTitle::~VTitle()
      55             : {
      56           0 : }
      57             : 
      58           0 : void VTitle::init(
      59             :               const uno::Reference< drawing::XShapes >& xTargetPage
      60             :             , const uno::Reference< lang::XMultiServiceFactory >& xFactory
      61             :             , const rtl::OUString& rCID )
      62             : {
      63           0 :     m_xTarget = xTargetPage;
      64           0 :     m_xShapeFactory = xFactory;
      65           0 :     m_aCID = rCID;
      66           0 : }
      67             : 
      68           0 : double VTitle::getRotationAnglePi() const
      69             : {
      70           0 :     return m_fRotationAngleDegree*F_PI/180.0;
      71             : }
      72             : 
      73           0 : awt::Size VTitle::getUnrotatedSize() const //size before rotation
      74             : {
      75           0 :     awt::Size aRet;
      76           0 :     if(m_xShape.is())
      77           0 :         aRet = m_xShape->getSize();
      78           0 :     return aRet;
      79             : }
      80             : 
      81           0 : awt::Size VTitle::getFinalSize() const //size after rotation
      82             : {
      83             :     return ShapeFactory::getSizeAfterRotation(
      84           0 :          m_xShape, m_fRotationAngleDegree );
      85             : }
      86             : 
      87           0 : void VTitle::changePosition( const awt::Point& rPos )
      88             : {
      89           0 :     if(!m_xShape.is())
      90             :         return;
      91           0 :     uno::Reference< beans::XPropertySet > xShapeProp( m_xShape, uno::UNO_QUERY );
      92           0 :     if(!xShapeProp.is())
      93             :         return;
      94             :     try
      95             :     {
      96           0 :         m_nXPos = rPos.X;
      97           0 :         m_nYPos = rPos.Y;
      98             : 
      99             :         //set position matrix
     100             :         //the matrix needs to be set at the end behind autogrow and such position influencing properties
     101           0 :         ::basegfx::B2DHomMatrix aM;
     102           0 :         aM.rotate( -m_fRotationAngleDegree*F_PI/180.0 );//#i78696#->#i80521#
     103           0 :         aM.translate( m_nXPos, m_nYPos);
     104           0 :         xShapeProp->setPropertyValue( C2U( "Transformation" ), uno::makeAny( B2DHomMatrixToHomogenMatrix3(aM) ) );
     105             :     }
     106           0 :     catch( const uno::Exception& e )
     107             :     {
     108             :         ASSERT_EXCEPTION( e );
     109           0 :     }
     110             : }
     111             : 
     112           0 : void VTitle::createShapes(
     113             :       const awt::Point& rPos
     114             :     , const awt::Size& rReferenceSize )
     115             : {
     116             :     try
     117             :     {
     118           0 :         if(!m_xTitle.is())
     119             :             return;
     120             : 
     121           0 :         uno::Sequence< uno::Reference< XFormattedString > > aStringList = m_xTitle->getText();
     122           0 :         if(aStringList.getLength()<=0)
     123             :             return;
     124             : 
     125             :         //create shape and add to page
     126             :         uno::Reference< drawing::XShape > xShape(
     127           0 :                 m_xShapeFactory->createInstance( C2U(
     128           0 :                 "com.sun.star.drawing.TextShape" ) ), uno::UNO_QUERY );
     129           0 :         m_xTarget->add(xShape);
     130           0 :         m_xShape = xShape;
     131             : 
     132             :         //set text and text properties
     133           0 :         uno::Reference< text::XText > xText( xShape, uno::UNO_QUERY );
     134           0 :         uno::Reference< text::XTextCursor > xTextCursor( xText->createTextCursor() );
     135           0 :         uno::Reference< text::XTextRange > xTextRange( xTextCursor, uno::UNO_QUERY );
     136           0 :         uno::Reference< beans::XPropertySet > xShapeProp( xShape, uno::UNO_QUERY );
     137           0 :         uno::Reference< beans::XPropertySet > xTitleProperties( m_xTitle, uno::UNO_QUERY );
     138           0 :         if( !xText.is() || !xTextRange.is() || !xTextCursor.is() || !xShapeProp.is() || !xTitleProperties.is() )
     139             :             return;
     140             : 
     141           0 :         tPropertyNameValueMap aValueMap;
     142             :         //fill line-, fill- and paragraph-properties into the ValueMap
     143             :         {
     144           0 :             tMakePropertyNameMap aNameMap = PropertyMapper::getPropertyNameMapForParagraphProperties();
     145           0 :             aNameMap( PropertyMapper::getPropertyNameMapForFillAndLineProperties() );
     146             : 
     147           0 :             PropertyMapper::getValueMap( aValueMap, aNameMap, xTitleProperties );
     148             :         }
     149             : 
     150             :         //fill some more shape properties into the ValueMap
     151             :         {
     152           0 :             drawing::TextHorizontalAdjust eHorizontalAdjust = drawing::TextHorizontalAdjust_CENTER;
     153           0 :             drawing::TextVerticalAdjust eVerticalAdjust = drawing::TextVerticalAdjust_CENTER;
     154             : 
     155           0 :             aValueMap.insert( tPropertyNameValueMap::value_type( C2U("TextHorizontalAdjust"), uno::makeAny(eHorizontalAdjust) ) ); // drawing::TextHorizontalAdjust
     156           0 :             aValueMap.insert( tPropertyNameValueMap::value_type( C2U("TextVerticalAdjust"), uno::makeAny(eVerticalAdjust) ) ); //drawing::TextVerticalAdjust
     157           0 :             aValueMap.insert( tPropertyNameValueMap::value_type( C2U("TextAutoGrowHeight"), uno::makeAny(sal_True) ) ); // sal_Bool
     158           0 :             aValueMap.insert( tPropertyNameValueMap::value_type( C2U("TextAutoGrowWidth"), uno::makeAny(sal_True) ) ); // sal_Bool
     159             : 
     160             :             //set name/classified ObjectID (CID)
     161           0 :             if( !m_aCID.isEmpty() )
     162           0 :                 aValueMap.insert( tPropertyNameValueMap::value_type( C2U("Name"), uno::makeAny( m_aCID ) ) ); //CID rtl::OUString
     163             :         }
     164             : 
     165             :         //set global title properties
     166             :         {
     167           0 :             tNameSequence aPropNames;
     168           0 :             tAnySequence aPropValues;
     169           0 :             PropertyMapper::getMultiPropertyListsFromValueMap( aPropNames, aPropValues, aValueMap );
     170           0 :             PropertyMapper::setMultiProperties( aPropNames, aPropValues, xShapeProp );
     171             :         }
     172             : 
     173           0 :         sal_Bool bStackCharacters(sal_False);
     174             :         try
     175             :         {
     176           0 :             xTitleProperties->getPropertyValue( C2U( "StackCharacters" ) ) >>= bStackCharacters;
     177             :         }
     178           0 :         catch( const uno::Exception& e )
     179             :         {
     180             :             ASSERT_EXCEPTION( e );
     181             :         }
     182           0 :         if(bStackCharacters)
     183             :         {
     184             :             //if the characters should be stacked we use only the first character properties for code simplicity
     185           0 :             if( aStringList.getLength()>0 )
     186             :             {
     187           0 :                 rtl::OUString aLabel;
     188           0 :                 for( sal_Int32 nN=0; nN<aStringList.getLength();nN++ )
     189           0 :                     aLabel += aStringList[nN]->getString();
     190           0 :                 aLabel = ShapeFactory::getStackedString( aLabel, bStackCharacters );
     191             : 
     192           0 :                 xTextCursor->gotoEnd(false);
     193           0 :                 xText->insertString( xTextRange, aLabel, false );
     194           0 :                 xTextCursor->gotoEnd(true);
     195           0 :                 uno::Reference< beans::XPropertySet > xTargetProps( xShape, uno::UNO_QUERY );
     196           0 :                 uno::Reference< beans::XPropertySet > xSourceProps( aStringList[0], uno::UNO_QUERY );
     197             : 
     198             :                 PropertyMapper::setMappedProperties( xTargetProps, xSourceProps
     199           0 :                     , PropertyMapper::getPropertyNameMapForCharacterProperties() );
     200             : 
     201             :                 // adapt font size according to page size
     202           0 :                 awt::Size aOldRefSize;
     203           0 :                 if( xTitleProperties->getPropertyValue( C2U("ReferencePageSize")) >>= aOldRefSize )
     204             :                 {
     205           0 :                     RelativeSizeHelper::adaptFontSizes( xTargetProps, aOldRefSize, rReferenceSize );
     206           0 :                 }
     207             :             }
     208             :         }
     209             :         else
     210             :         {
     211           0 :             uno::Sequence< uno::Reference< text::XTextCursor > > aCursorList( aStringList.getLength() );
     212           0 :             sal_Int32 nN = 0;
     213           0 :             for( nN=0; nN<aStringList.getLength();nN++ )
     214             :             {
     215           0 :                 xTextCursor->gotoEnd(false);
     216           0 :                 xText->insertString( xTextRange, aStringList[nN]->getString(), false );
     217           0 :                 xTextCursor->gotoEnd(true);
     218           0 :                 aCursorList[nN] = xText->createTextCursorByRange( uno::Reference< text::XTextRange >(xTextCursor,uno::UNO_QUERY) );
     219             :             }
     220           0 :             awt::Size aOldRefSize;
     221             :             bool bHasRefPageSize =
     222           0 :                 ( xTitleProperties->getPropertyValue( C2U("ReferencePageSize")) >>= aOldRefSize );
     223             : 
     224           0 :             if( aStringList.getLength()>0 )
     225             :             {
     226           0 :                 uno::Reference< beans::XPropertySet > xTargetProps( xShape, uno::UNO_QUERY );
     227           0 :                 uno::Reference< beans::XPropertySet > xSourceProps( aStringList[0], uno::UNO_QUERY );
     228           0 :                 PropertyMapper::setMappedProperties( xTargetProps, xSourceProps, PropertyMapper::getPropertyNameMapForCharacterProperties() );
     229             : 
     230             :                 // adapt font size according to page size
     231           0 :                 if( bHasRefPageSize )
     232             :                 {
     233           0 :                     RelativeSizeHelper::adaptFontSizes( xTargetProps, aOldRefSize, rReferenceSize );
     234           0 :                 }
     235           0 :             }
     236             :         }
     237             : 
     238             :         // #i109336# Improve auto positioning in chart
     239           0 :         float fFontHeight = 0.0;
     240           0 :         if ( xShapeProp.is() && ( xShapeProp->getPropertyValue( C2U( "CharHeight" ) ) >>= fFontHeight ) )
     241             :         {
     242           0 :             fFontHeight *= ( 2540.0f / 72.0f );  // pt -> 1/100 mm
     243           0 :             float fXFraction = 0.18f;
     244           0 :             sal_Int32 nXDistance = static_cast< sal_Int32 >( ::rtl::math::round( fFontHeight * fXFraction ) );
     245           0 :             float fYFraction = 0.30f;
     246           0 :             sal_Int32 nYDistance = static_cast< sal_Int32 >( ::rtl::math::round( fFontHeight * fYFraction ) );
     247           0 :             xShapeProp->setPropertyValue( C2U( "TextLeftDistance" ), uno::makeAny( nXDistance ) );
     248           0 :             xShapeProp->setPropertyValue( C2U( "TextRightDistance" ), uno::makeAny( nXDistance ) );
     249           0 :             xShapeProp->setPropertyValue( C2U( "TextUpperDistance" ), uno::makeAny( nYDistance ) );
     250           0 :             xShapeProp->setPropertyValue( C2U( "TextLowerDistance" ), uno::makeAny( nYDistance ) );
     251             :         }
     252             : 
     253             :         try
     254             :         {
     255           0 :             double fAngleDegree = 0;
     256           0 :             xTitleProperties->getPropertyValue( C2U( "TextRotation" ) ) >>= fAngleDegree;
     257           0 :             m_fRotationAngleDegree += fAngleDegree;
     258             :         }
     259           0 :         catch( const uno::Exception& e )
     260             :         {
     261             :             ASSERT_EXCEPTION( e );
     262             :         }
     263           0 :         m_nXPos = rPos.X;
     264           0 :         m_nYPos = rPos.Y;
     265             : 
     266             :         //set position matrix
     267             :         //the matrix needs to be set at the end behind autogrow and such position influencing properties
     268           0 :         ::basegfx::B2DHomMatrix aM;
     269           0 :         aM.rotate( -m_fRotationAngleDegree*F_PI/180.0 );//#i78696#->#i80521#
     270           0 :         aM.translate( m_nXPos, m_nYPos );
     271           0 :         xShapeProp->setPropertyValue( C2U( "Transformation" ), uno::makeAny( B2DHomMatrixToHomogenMatrix3(aM) ) );
     272             :     }
     273           0 :     catch( const uno::Exception& e )
     274             :     {
     275             :         ASSERT_EXCEPTION( e );
     276             :     }
     277             : }
     278             : 
     279             : //.............................................................................
     280             : } //namespace chart
     281             : //.............................................................................
     282             : 
     283             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10