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