LCOV - code coverage report
Current view: top level - oox/source/drawingml/chart - titleconverter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 103 1.0 %
Date: 2012-08-25 Functions: 2 16 12.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 223 0.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                 :            : #include "oox/drawingml/chart/titleconverter.hxx"
      21                 :            : 
      22                 :            : #include <com/sun/star/chart/ChartLegendExpansion.hpp>
      23                 :            : #include <com/sun/star/chart2/LegendPosition.hpp>
      24                 :            : #include <com/sun/star/chart2/XDiagram.hpp>
      25                 :            : #include <com/sun/star/chart2/XFormattedString.hpp>
      26                 :            : #include <com/sun/star/chart2/XLegend.hpp>
      27                 :            : #include <com/sun/star/chart2/XTitle.hpp>
      28                 :            : #include <com/sun/star/chart2/XTitled.hpp>
      29                 :            : #include "oox/drawingml/textbody.hxx"
      30                 :            : #include "oox/drawingml/textparagraph.hxx"
      31                 :            : #include "oox/drawingml/chart/datasourceconverter.hxx"
      32                 :            : #include "oox/drawingml/chart/titlemodel.hxx"
      33                 :            : #include "oox/helper/containerhelper.hxx"
      34                 :            : 
      35                 :            : namespace oox {
      36                 :            : namespace drawingml {
      37                 :            : namespace chart {
      38                 :            : 
      39                 :            : // ============================================================================
      40                 :            : 
      41                 :            : using namespace ::com::sun::star::awt;
      42                 :            : using namespace ::com::sun::star::chart2;
      43                 :            : using namespace ::com::sun::star::chart2::data;
      44                 :            : using namespace ::com::sun::star::uno;
      45                 :            : 
      46                 :            : using ::oox::core::XmlFilterBase;
      47                 :            : using ::rtl::OUString;
      48                 :            : 
      49                 :            : // ============================================================================
      50                 :            : 
      51                 :          0 : TextConverter::TextConverter( const ConverterRoot& rParent, TextModel& rModel ) :
      52                 :          0 :     ConverterBase< TextModel >( rParent, rModel )
      53                 :            : {
      54                 :          0 : }
      55                 :            : 
      56                 :          0 : TextConverter::~TextConverter()
      57                 :            : {
      58         [ #  # ]:          0 : }
      59                 :            : 
      60                 :          0 : Reference< XDataSequence > TextConverter::createDataSequence( const OUString& rRole )
      61                 :            : {
      62                 :          0 :     Reference< XDataSequence > xDataSeq;
      63 [ #  # ][ #  # ]:          0 :     if( mrModel.mxDataSeq.is() )
      64                 :            :     {
      65         [ #  # ]:          0 :         DataSequenceConverter aDataSeqConv( *this, *mrModel.mxDataSeq );
      66 [ #  # ][ #  # ]:          0 :         xDataSeq = aDataSeqConv.createDataSequence( rRole );
                 [ #  # ]
      67                 :            :     }
      68                 :          0 :     return xDataSeq;
      69                 :            : }
      70                 :            : 
      71                 :          0 : Sequence< Reference< XFormattedString > > TextConverter::createStringSequence(
      72                 :            :         const OUString& rDefaultText, const ModelRef< TextBody >& rxTextProp, ObjectType eObjType )
      73                 :            : {
      74                 :            :     OSL_ENSURE( !mrModel.mxDataSeq || !mrModel.mxTextBody, "TextConverter::createStringSequence - linked string and rich text found" );
      75         [ #  # ]:          0 :     ::std::vector< Reference< XFormattedString > > aStringVec;
      76 [ #  # ][ #  # ]:          0 :     if( mrModel.mxTextBody.is() )
      77                 :            :     {
      78                 :            :         // rich-formatted text objects can be created, but currently Chart2 is not able to show them
      79                 :          0 :         const TextParagraphVector& rTextParas = mrModel.mxTextBody->getParagraphs();
      80 [ #  # ][ #  # ]:          0 :         for( TextParagraphVector::const_iterator aPIt = rTextParas.begin(), aPEnd = rTextParas.end(); aPIt != aPEnd; ++aPIt )
      81                 :            :         {
      82                 :          0 :             const TextParagraph& rTextPara = **aPIt;
      83                 :          0 :             const TextCharacterProperties& rParaProps = rTextPara.getProperties().getTextCharacterProperties();
      84 [ #  # ][ #  # ]:          0 :             for( TextRunVector::const_iterator aRIt = rTextPara.getRuns().begin(), aREnd = rTextPara.getRuns().end(); aRIt != aREnd; ++aRIt )
      85                 :            :             {
      86                 :          0 :                 const TextRun& rTextRun = **aRIt;
      87 [ #  # ][ #  # ]:          0 :                 bool bAddNewLine = (aRIt + 1 == aREnd) && (aPIt + 1 != aPEnd);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  #  
          #  #  #  #  #  
              # ][ #  # ]
      88         [ #  # ]:          0 :                 Reference< XFormattedString > xFmtStr = appendFormattedString( aStringVec, rTextRun.getText(), bAddNewLine );
      89         [ #  # ]:          0 :                 PropertySet aPropSet( xFmtStr );
      90         [ #  # ]:          0 :                 TextCharacterProperties aRunProps( rParaProps );
      91         [ #  # ]:          0 :                 aRunProps.assignUsed( rTextRun.getTextCharacterProperties() );
      92 [ #  # ][ #  # ]:          0 :                 getFormatter().convertTextFormatting( aPropSet, aRunProps, eObjType );
      93 [ #  # ][ #  # ]:          0 :             }
      94                 :            :         }
      95                 :            :     }
      96                 :            :     else
      97                 :            :     {
      98                 :          0 :         OUString aString;
      99                 :            :         // try to create string from linked data
     100 [ #  # ][ #  # ]:          0 :         if( mrModel.mxDataSeq.is() && !mrModel.mxDataSeq->maData.empty() )
         [ #  # ][ #  # ]
     101                 :          0 :             mrModel.mxDataSeq->maData.begin()->second >>= aString;
     102                 :            :         // no linked string -> fall back to default string
     103         [ #  # ]:          0 :         if( aString.isEmpty() )
     104                 :          0 :             aString = rDefaultText;
     105                 :            : 
     106                 :            :         // create formatted string object
     107         [ #  # ]:          0 :         if( !aString.isEmpty() )
     108                 :            :         {
     109         [ #  # ]:          0 :             Reference< XFormattedString > xFmtStr = appendFormattedString( aStringVec, aString, false );
     110         [ #  # ]:          0 :             PropertySet aPropSet( xFmtStr );
     111 [ #  # ][ #  # ]:          0 :             getFormatter().convertTextFormatting( aPropSet, rxTextProp, eObjType );
                 [ #  # ]
     112                 :          0 :         }
     113                 :            :     }
     114                 :            : 
     115         [ #  # ]:          0 :     return ContainerHelper::vectorToSequence( aStringVec );
     116                 :            : }
     117                 :            : 
     118                 :          0 : Reference< XFormattedString > TextConverter::appendFormattedString(
     119                 :            :         ::std::vector< Reference< XFormattedString > >& orStringVec, const OUString& rString, bool bAddNewLine ) const
     120                 :            : {
     121                 :          0 :     Reference< XFormattedString > xFmtStr;
     122                 :            :     try
     123                 :            :     {
     124 [ #  # ][ #  # ]:          0 :         xFmtStr.set( ConverterRoot::createInstance( CREATE_OUSTRING( "com.sun.star.chart2.FormattedString" ) ), UNO_QUERY_THROW );
                 [ #  # ]
     125 [ #  # ][ #  # ]:          0 :         xFmtStr->setString( bAddNewLine ? (rString + OUString( sal_Unicode( '\n' ) )) : rString );
                 [ #  # ]
           [ #  #  #  # ]
                 [ #  # ]
     126         [ #  # ]:          0 :         orStringVec.push_back( xFmtStr );
     127                 :            :     }
     128         [ #  # ]:          0 :     catch( Exception& )
     129                 :            :     {
     130                 :            :     }
     131                 :          0 :     return xFmtStr;
     132                 :            : }
     133                 :            : 
     134                 :            : // ============================================================================
     135                 :            : 
     136                 :          0 : TitleConverter::TitleConverter( const ConverterRoot& rParent, TitleModel& rModel ) :
     137                 :          0 :     ConverterBase< TitleModel >( rParent, rModel )
     138                 :            : {
     139                 :          0 : }
     140                 :            : 
     141                 :          0 : TitleConverter::~TitleConverter()
     142                 :            : {
     143         [ #  # ]:          0 : }
     144                 :            : 
     145                 :          0 : void TitleConverter::convertFromModel( const Reference< XTitled >& rxTitled, const OUString& rAutoTitle, ObjectType eObjType, sal_Int32 nMainIdx, sal_Int32 nSubIdx )
     146                 :            : {
     147         [ #  # ]:          0 :     if( rxTitled.is() )
     148                 :            :     {
     149                 :            :         // create the formatted strings
     150         [ #  # ]:          0 :         TextModel& rText = mrModel.mxText.getOrCreate();
     151         [ #  # ]:          0 :         TextConverter aTextConv( *this, rText );
     152         [ #  # ]:          0 :         Sequence< Reference< XFormattedString > > aStringSeq = aTextConv.createStringSequence( rAutoTitle, mrModel.mxTextProp, eObjType );
     153         [ #  # ]:          0 :         if( aStringSeq.hasElements() ) try
     154                 :            :         {
     155                 :            :             // create the title object and set the string data
     156 [ #  # ][ #  # ]:          0 :             Reference< XTitle > xTitle( createInstance( CREATE_OUSTRING( "com.sun.star.chart2.Title" ) ), UNO_QUERY_THROW );
                 [ #  # ]
     157 [ #  # ][ #  # ]:          0 :             xTitle->setText( aStringSeq );
     158 [ #  # ][ #  # ]:          0 :             rxTitled->setTitleObject( xTitle );
     159                 :            : 
     160                 :            :             // frame formatting (text formatting already done in TextConverter::createStringSequence())
     161         [ #  # ]:          0 :             PropertySet aPropSet( xTitle );
     162 [ #  # ][ #  # ]:          0 :             getFormatter().convertFrameFormatting( aPropSet, mrModel.mxShapeProp, eObjType );
     163                 :            : 
     164                 :            :             // frame rotation
     165                 :            :             OSL_ENSURE( !mrModel.mxTextProp || !rText.mxTextBody, "TitleConverter::convertFromModel - multiple text properties" );
     166 [ #  # ][ #  # ]:          0 :             ModelRef< TextBody > xTextProp = mrModel.mxTextProp.is() ? mrModel.mxTextProp : rText.mxTextBody;
                 [ #  # ]
     167 [ #  # ][ #  # ]:          0 :             getFormatter().convertTextRotation( aPropSet, xTextProp, true );
     168                 :            : 
     169                 :            :             // register the title and layout data for conversion of position
     170 [ #  # ][ #  # ]:          0 :             registerTitleLayout( xTitle, mrModel.mxLayout, eObjType, nMainIdx, nSubIdx );
         [ #  # ][ #  # ]
     171                 :            :         }
     172         [ #  # ]:          0 :         catch( Exception& )
     173                 :            :         {
     174 [ #  # ][ #  # ]:          0 :         }
     175                 :            :     }
     176                 :          0 : }
     177                 :            : 
     178                 :            : // ============================================================================
     179                 :            : 
     180                 :          0 : LegendConverter::LegendConverter( const ConverterRoot& rParent, LegendModel& rModel ) :
     181                 :          0 :     ConverterBase< LegendModel >( rParent, rModel )
     182                 :            : {
     183                 :          0 : }
     184                 :            : 
     185                 :          0 : LegendConverter::~LegendConverter()
     186                 :            : {
     187         [ #  # ]:          0 : }
     188                 :            : 
     189                 :          0 : void LegendConverter::convertFromModel( const Reference< XDiagram >& rxDiagram )
     190                 :            : {
     191         [ #  # ]:          0 :     if( rxDiagram.is() ) try
     192                 :            :     {
     193                 :            :         namespace cssc = ::com::sun::star::chart;
     194                 :            :         namespace cssc2 = ::com::sun::star::chart2;
     195                 :            : 
     196                 :            :         // create the legend
     197 [ #  # ][ #  # ]:          0 :         Reference< XLegend > xLegend( createInstance( CREATE_OUSTRING( "com.sun.star.chart2.Legend" ) ), UNO_QUERY_THROW );
                 [ #  # ]
     198 [ #  # ][ #  # ]:          0 :         rxDiagram->setLegend( xLegend );
     199         [ #  # ]:          0 :         PropertySet aPropSet( xLegend );
     200         [ #  # ]:          0 :         aPropSet.setProperty( PROP_Show, true );
     201                 :            : 
     202                 :            :         // legend formatting
     203 [ #  # ][ #  # ]:          0 :         getFormatter().convertFormatting( aPropSet, mrModel.mxShapeProp, mrModel.mxTextProp, OBJECTTYPE_LEGEND );
     204                 :            : 
     205                 :            :         // predefined legend position and expansion
     206                 :          0 :         cssc2::LegendPosition eLegendPos = cssc2::LegendPosition_CUSTOM;
     207                 :          0 :         cssc::ChartLegendExpansion eLegendExpand = cssc::ChartLegendExpansion_CUSTOM;
     208   [ #  #  #  #  :          0 :         switch( mrModel.mnPosition )
                      # ]
     209                 :            :         {
     210                 :            :             case XML_l:
     211                 :          0 :                 eLegendPos = cssc2::LegendPosition_LINE_START;
     212                 :          0 :                 eLegendExpand = cssc::ChartLegendExpansion_HIGH;
     213                 :          0 :             break;
     214                 :            :             case XML_r:
     215                 :            :             case XML_tr:    // top-right not supported
     216                 :          0 :                 eLegendPos = cssc2::LegendPosition_LINE_END;
     217                 :          0 :                 eLegendExpand = cssc::ChartLegendExpansion_HIGH;
     218                 :          0 :             break;
     219                 :            :             case XML_t:
     220                 :          0 :                 eLegendPos = cssc2::LegendPosition_PAGE_START;
     221                 :          0 :                 eLegendExpand = cssc::ChartLegendExpansion_WIDE;
     222                 :          0 :             break;
     223                 :            :             case XML_b:
     224                 :          0 :                 eLegendPos = cssc2::LegendPosition_PAGE_END;
     225                 :          0 :                 eLegendExpand = cssc::ChartLegendExpansion_WIDE;
     226                 :          0 :             break;
     227                 :            :         }
     228                 :            : 
     229                 :            :         // manual positioning and size
     230         [ #  # ]:          0 :         if( mrModel.mxLayout.get() )
     231                 :            :         {
     232         [ #  # ]:          0 :             LayoutConverter aLayoutConv( *this, *mrModel.mxLayout );
     233                 :            :             // manual size needs ChartLegendExpansion_CUSTOM
     234 [ #  # ][ #  # ]:          0 :             if( aLayoutConv.convertFromModel( aPropSet ) )
     235         [ #  # ]:          0 :                 eLegendExpand = cssc::ChartLegendExpansion_CUSTOM;
     236                 :            :         }
     237                 :            : 
     238                 :            :         // set position and expansion properties
     239         [ #  # ]:          0 :         aPropSet.setProperty( PROP_AnchorPosition, eLegendPos );
     240 [ #  # ][ #  # ]:          0 :         aPropSet.setProperty( PROP_Expansion, eLegendExpand );
                 [ #  # ]
     241                 :            :     }
     242                 :          0 :     catch( Exception& )
     243                 :            :     {
     244                 :            :     }
     245                 :          0 : }
     246                 :            : 
     247                 :            : // ============================================================================
     248                 :            : 
     249                 :            : } // namespace chart
     250                 :            : } // namespace drawingml
     251 [ +  - ][ +  - ]:        285 : } // namespace oox
     252                 :            : 
     253                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10