LCOV - code coverage report
Current view: top level - oox/source/ppt - pptshapecontext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 93 102 91.2 %
Date: 2012-08-25 Functions: 6 6 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 151 278 54.3 %

           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 <com/sun/star/xml/sax/FastToken.hpp>
      21                 :            : #include <com/sun/star/drawing/LineStyle.hpp>
      22                 :            : #include <com/sun/star/beans/XMultiPropertySet.hpp>
      23                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      24                 :            : #include <com/sun/star/container/XNamed.hpp>
      25                 :            : 
      26                 :            : #include "oox/helper/attributelist.hxx"
      27                 :            : #include "oox/ppt/pptshape.hxx"
      28                 :            : #include "oox/ppt/pptshapecontext.hxx"
      29                 :            : #include "oox/ppt/pptshapepropertiescontext.hxx"
      30                 :            : #include "oox/ppt/slidepersist.hxx"
      31                 :            : #include "oox/drawingml/shapestylecontext.hxx"
      32                 :            : #include "oox/drawingml/fillpropertiesgroupcontext.hxx"
      33                 :            : #include "oox/drawingml/lineproperties.hxx"
      34                 :            : #include "oox/drawingml/drawingmltypes.hxx"
      35                 :            : #include "oox/drawingml/customshapegeometry.hxx"
      36                 :            : #include "oox/drawingml/textbodycontext.hxx"
      37                 :            : 
      38                 :            : using rtl::OUString;
      39                 :            : using namespace oox::core;
      40                 :            : using namespace ::com::sun::star;
      41                 :            : using namespace ::com::sun::star::uno;
      42                 :            : using namespace ::com::sun::star::drawing;
      43                 :            : using namespace ::com::sun::star::beans;
      44                 :            : using namespace ::com::sun::star::text;
      45                 :            : using namespace ::com::sun::star::xml::sax;
      46                 :            : 
      47                 :            : namespace oox { namespace ppt {
      48                 :            : 
      49                 :            : // CT_Shape
      50                 :        111 : PPTShapeContext::PPTShapeContext( ContextHandler& rParent, const SlidePersistPtr pSlidePersistPtr, oox::drawingml::ShapePtr pMasterShapePtr, oox::drawingml::ShapePtr pShapePtr )
      51                 :            : : oox::drawingml::ShapeContext( rParent, pMasterShapePtr, pShapePtr )
      52 [ +  - ][ +  - ]:        111 : , mpSlidePersistPtr( pSlidePersistPtr )
         [ +  - ][ +  - ]
      53                 :            : {
      54                 :        111 : }
      55                 :            : 
      56                 :        324 : oox::drawingml::ShapePtr findPlaceholder( const sal_Int32 nMasterPlaceholder, const OptValue< sal_Int32 >& oSubTypeIndex, std::vector< oox::drawingml::ShapePtr >& rShapes )
      57                 :            : {
      58         [ +  - ]:        324 :     oox::drawingml::ShapePtr aShapePtr;
      59         [ +  - ]:        324 :     oox::drawingml::ShapePtr aChoiceShapePtr1;
      60         [ +  - ]:        324 :     oox::drawingml::ShapePtr aChoiceShapePtr2;
      61                 :        324 :     std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() );
      62 [ +  - ][ +  + ]:        564 :     while( aRevIter != rShapes.rend() )
      63                 :            :     {
      64 [ +  - ][ +  + ]:        291 :         if ( (*aRevIter)->getSubType() == nMasterPlaceholder )
      65                 :            :         {
      66 [ +  + ][ +  - ]:         39 :             if( !oSubTypeIndex.has() && aChoiceShapePtr1 == NULL )
                 [ +  + ]
      67 [ +  - ][ +  - ]:         15 :                 aChoiceShapePtr1 = *aRevIter;
      68         [ +  - ]:         24 :             else if( aChoiceShapePtr2 == NULL )
      69 [ +  - ][ +  - ]:         24 :                 aChoiceShapePtr2 = *aRevIter;
      70 [ +  - ][ +  + ]:         39 :             if( (*aRevIter)->getSubTypeIndex() == oSubTypeIndex )
      71                 :            :             {
      72 [ +  - ][ +  - ]:         12 :                 aShapePtr = *aRevIter;
      73                 :         12 :                 break;
      74                 :            :             }
      75                 :            :         }
      76         [ +  - ]:        279 :         std::vector< oox::drawingml::ShapePtr >& rChildren = (*aRevIter)->getChildren();
      77 [ +  - ][ +  - ]:        279 :         aShapePtr = findPlaceholder( nMasterPlaceholder, oSubTypeIndex, rChildren );
                 [ +  - ]
      78         [ +  + ]:        279 :         if ( aShapePtr.get() )
      79                 :         39 :             break;
      80         [ +  - ]:        240 :         ++aRevIter;
      81                 :            :     }
      82         [ +  + ]:        324 :     if( aShapePtr == NULL )
      83 [ +  + ][ +  - ]:        273 :         return aChoiceShapePtr1 ? aChoiceShapePtr1 : aChoiceShapePtr2;
      84 [ +  - ][ +  - ]:        324 :     return aShapePtr;
         [ +  - ][ +  - ]
      85                 :            : }
      86                 :            : 
      87                 :            : // if nFirstPlaceholder can't be found, it will be searched for nSecondPlaceholder
      88                 :         39 : oox::drawingml::ShapePtr findPlaceholder( sal_Int32 nFirstPlaceholder, sal_Int32 nSecondPlaceholder,
      89                 :            :     const OptValue< sal_Int32 >& oSubTypeIndex, std::vector< oox::drawingml::ShapePtr >& rShapes )
      90                 :            : {
      91         [ +  - ]:         39 :     oox::drawingml::ShapePtr pPlaceholder = findPlaceholder( nFirstPlaceholder, oSubTypeIndex, rShapes );
      92 [ +  + ][ -  + ]:         39 :     return !nSecondPlaceholder || pPlaceholder.get() ? pPlaceholder : findPlaceholder( nSecondPlaceholder, oSubTypeIndex, rShapes );
         [ +  - ][ +  - ]
                 [ +  - ]
      93                 :            : }
      94                 :            : 
      95                 :        873 : Reference< XFastContextHandler > PPTShapeContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
      96                 :            : {
      97                 :        873 :     Reference< XFastContextHandler > xRet;
      98         [ -  + ]:        873 :     if( getNamespace( aElementToken ) == NMSP_dsp )
      99                 :          0 :         aElementToken = NMSP_ppt | getBaseToken( aElementToken );
     100                 :            : 
     101   [ +  +  +  -  :        873 :     switch( aElementToken )
                +  -  + ]
     102                 :            :     {
     103                 :            :         // nvSpPr CT_ShapeNonVisual begin
     104                 :            :         //  case PPT_TOKEN( drElemPr ):
     105                 :            :         //      break;
     106                 :            :         case PPT_TOKEN( cNvPr ):
     107                 :            :         {
     108         [ +  - ]:        111 :             AttributeList aAttribs( xAttribs );
     109         [ +  - ]:        111 :             mpShapePtr->setHidden( aAttribs.getBool( XML_hidden, false ) );
     110 [ +  - ][ +  - ]:        111 :             mpShapePtr->setId( xAttribs->getOptionalValue( XML_id ) );
     111 [ +  - ][ +  - ]:        111 :             mpShapePtr->setName( xAttribs->getOptionalValue( XML_name ) );
     112         [ +  - ]:        111 :             break;
     113                 :            :         }
     114                 :            :         case PPT_TOKEN( ph ):
     115                 :            :         {
     116 [ +  - ][ +  - ]:        105 :             sal_Int32 nSubType( xAttribs->getOptionalValueToken( XML_type, XML_obj ) );
     117                 :        105 :             mpShapePtr->setSubType( nSubType );
     118 [ +  - ][ +  + ]:        105 :             if( xAttribs->hasAttribute( XML_idx ) )
                 [ +  - ]
     119 [ +  - ][ +  - ]:         66 :                 mpShapePtr->setSubTypeIndex( xAttribs->getOptionalValue( XML_idx ).toInt32() );
                 [ +  - ]
     120         [ +  - ]:        105 :             if ( nSubType )
     121                 :            :             {
     122         [ -  + ]:        105 :                 PPTShape* pPPTShapePtr = dynamic_cast< PPTShape* >( mpShapePtr.get() );
     123         [ +  - ]:        105 :                 if ( pPPTShapePtr )
     124                 :            :                 {
     125                 :        105 :                     oox::ppt::ShapeLocation eShapeLocation = pPPTShapePtr->getShapeLocation();
     126 [ +  + ][ +  + ]:        105 :                     if ( ( eShapeLocation == Slide ) || ( eShapeLocation == Layout ) )
     127                 :            :                     {
     128                 :            :                         // inheriting properties from placeholder objects by cloning shape
     129                 :         42 :                         sal_Int32 nFirstPlaceholder = 0;
     130                 :         42 :                         sal_Int32 nSecondPlaceholder = 0;
     131   [ +  +  -  +  :         42 :                         switch( nSubType )
                      - ]
     132                 :            :                         {
     133                 :            :                             case XML_ctrTitle :     // slide/layout
     134                 :          3 :                                   nFirstPlaceholder = XML_ctrTitle;
     135                 :          3 :                                   nSecondPlaceholder = XML_title;
     136                 :          3 :                               break;
     137                 :            : 
     138                 :            :                               case XML_subTitle :       // slide/layout
     139                 :          6 :                                   nFirstPlaceholder = XML_subTitle;
     140                 :          6 :                                   nSecondPlaceholder = XML_title;
     141                 :          6 :                               break;
     142                 :            : 
     143                 :            :                              case XML_obj :         // slide/layout
     144                 :          0 :                                   nFirstPlaceholder = XML_obj;
     145                 :          0 :                                   nSecondPlaceholder = XML_body;
     146                 :          0 :                               break;
     147                 :            : 
     148                 :            :                             case XML_dt :           // slide/layout/master/notes/notesmaster/handoutmaster
     149                 :            :                               case XML_sldNum :     // slide/layout/master/notes/notesmaster/handoutmaster
     150                 :            :                               case XML_ftr :            // slide/layout/master/notes/notesmaster/handoutmaster
     151                 :            :                               case XML_hdr :            // notes/notesmaster/handoutmaster
     152                 :            :                               case XML_body :           // slide/layout/master/notes/notesmaster
     153                 :            :                               case XML_title :      // slide/layout/master/
     154                 :            :                               case XML_chart :      // slide/layout
     155                 :            :                               case XML_tbl :            // slide/layout
     156                 :            :                               case XML_clipArt :        // slide/layout
     157                 :            :                               case XML_dgm :            // slide/layout
     158                 :            :                               case XML_media :      // slide/layout
     159                 :            :                               case XML_sldImg :     // notes/notesmaster
     160                 :            :                               case XML_pic :            // slide/layout
     161                 :         33 :                                   nFirstPlaceholder = nSubType;
     162                 :            :                               default:
     163                 :         33 :                                   break;
     164                 :            :                         }
     165         [ +  - ]:         42 :                           if ( nFirstPlaceholder )
     166                 :            :                           {
     167         [ +  - ]:         42 :                               oox::drawingml::ShapePtr pPlaceholder;
     168         [ +  + ]:         42 :                               if ( eShapeLocation == Layout )       // for layout objects the referenced object can be found within the same shape tree
     169                 :            :                               {
     170         [ +  + ]:         30 :                                   if( pPPTShapePtr->getSubTypeIndex().has() )
     171 [ +  - ][ +  - ]:         18 :                                       pPlaceholder = PPTShape::findPlaceholderByIndex( pPPTShapePtr->getSubTypeIndex().get(), mpSlidePersistPtr->getShapes()->getChildren() );
         [ +  - ][ +  - ]
                 [ +  - ]
     172         [ +  + ]:         30 :                                   if ( !pPlaceholder.get() )
     173                 :         27 :                                       pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, pPPTShapePtr->getSubTypeIndex(),
     174 [ +  - ][ +  - ]:         54 :                                                                       mpSlidePersistPtr->getShapes()->getChildren() );
         [ +  - ][ +  - ]
                 [ +  - ]
     175                 :            :                               }
     176         [ +  - ]:         12 :                               else if ( eShapeLocation == Slide )   // normal slide shapes have to search within the corresponding master tree for referenced objects
     177                 :            :                               {
     178         [ +  - ]:         12 :                                   SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
     179         [ +  - ]:         12 :                                   if ( pMasterPersist.get() ) {
     180         [ +  + ]:         12 :                                       if( pPPTShapePtr->getSubTypeIndex().has() )
     181 [ +  - ][ +  - ]:          9 :                                           pPlaceholder = PPTShape::findPlaceholderByIndex( pPPTShapePtr->getSubTypeIndex().get(), pMasterPersist->getShapes()->getChildren() );
         [ +  - ][ +  - ]
                 [ +  - ]
     182                 :            :                                       // TODO: Check if this is required for non-notes pages as well...
     183 [ +  + ][ +  - ]:         15 :                                       if ( !pPlaceholder.get() || ( pMasterPersist->isNotesPage() && pPlaceholder->getSubType() != nFirstPlaceholder &&
           [ +  -  +  - ]
                 [ +  - ]
     184                 :          3 :                                                                                                      pPlaceholder->getSubType() != nSecondPlaceholder ) )
     185                 :            :                                       {
     186                 :            :                                           pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder,
     187 [ +  - ][ +  - ]:         12 :                                                                           pPPTShapePtr->getSubTypeIndex(), pMasterPersist->getShapes()->getChildren() );
         [ +  - ][ +  - ]
                 [ +  - ]
     188                 :            :                                       }
     189         [ +  - ]:         12 :                                   }
     190                 :            :                               }
     191         [ +  - ]:         42 :                               if ( pPlaceholder.get() )
     192                 :            :                               {
     193                 :            :                                   OSL_TRACE("shape %s will get shape reference %s applied", rtl::OUStringToOString(mpShapePtr->getId(), RTL_TEXTENCODING_UTF8 ).getStr(), rtl::OUStringToOString(pPlaceholder->getId(), RTL_TEXTENCODING_UTF8 ).getStr());
     194         [ +  - ]:         42 :                                   mpShapePtr->applyShapeReference( *pPlaceholder.get() );
     195         [ -  + ]:         42 :                                   PPTShape* pPPTShape = dynamic_cast< PPTShape* >( pPlaceholder.get() );
     196         [ +  - ]:         42 :                                   if ( pPPTShape )
     197                 :         42 :                                       pPPTShape->setReferenced( sal_True );
     198 [ +  - ][ +  - ]:         42 :                                   pPPTShapePtr->setPlaceholder( pPlaceholder );
                 [ +  - ]
     199         [ +  - ]:         42 :                               }
     200                 :            :                           }
     201                 :            :                     }
     202                 :            :                   }
     203                 :            : 
     204                 :            :               }
     205                 :        105 :               break;
     206                 :            :         }
     207                 :            : 
     208                 :            :         // nvSpPr CT_ShapeNonVisual end
     209                 :            : 
     210                 :            :         case PPT_TOKEN( spPr ):
     211 [ +  - ][ +  - ]:        111 :             xRet = new PPTShapePropertiesContext( *this, *mpShapePtr );
                 [ +  - ]
     212                 :        111 :             break;
     213                 :            : 
     214                 :            :         case PPT_TOKEN( style ):
     215 [ #  # ][ #  # ]:          0 :             xRet = new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr );
                 [ #  # ]
     216                 :          0 :             break;
     217                 :            : 
     218                 :            :         case PPT_TOKEN( txBody ):
     219                 :            :         {
     220 [ +  - ][ +  - ]:        108 :             oox::drawingml::TextBodyPtr xTextBody( new oox::drawingml::TextBody( mpShapePtr->getTextBody() ) );
         [ +  - ][ +  - ]
                 [ +  - ]
     221 [ +  - ][ +  - ]:        108 :             xTextBody->getTextProperties().maPropertyMap[ PROP_FontIndependentLineSpacing ] <<= static_cast< sal_Bool >( sal_True );
     222         [ +  - ]:        108 :             mpShapePtr->setTextBody( xTextBody );
     223 [ +  - ][ +  - ]:        108 :             xRet = new oox::drawingml::TextBodyContext( *this, *xTextBody );
                 [ +  - ]
     224         [ +  - ]:        108 :             break;
     225                 :            :         }
     226                 :            :         case PPT_TOKEN( txXfrm ):
     227                 :            :         {
     228         [ #  # ]:          0 :             AttributeList aAttribs( xAttribs );
     229 [ #  # ][ #  # ]:          0 :             mpShapePtr->getTextBody()->getTextProperties().moRotation = aAttribs.getInteger( XML_rot );
                 [ #  # ]
     230         [ #  # ]:          0 :             break;
     231                 :            :         }
     232                 :            :     }
     233                 :            : 
     234         [ +  + ]:        873 :     if( !xRet.is() )
     235         [ +  - ]:        654 :         xRet.set( this );
     236                 :            : 
     237                 :        873 :     return xRet;
     238                 :            : }
     239                 :            : 
     240                 :            : 
     241 [ +  - ][ +  - ]:        285 : } }
     242                 :            : 
     243                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10