LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/oox/source/ppt - pptshapecontext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 92 94 97.9 %
Date: 2013-07-09 Functions: 6 6 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 <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             : #include "oox/drawingml/transform2dcontext.hxx"
      38             : 
      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         140 : PPTShapeContext::PPTShapeContext( ContextHandler2Helper& rParent, const SlidePersistPtr pSlidePersistPtr, oox::drawingml::ShapePtr pMasterShapePtr, oox::drawingml::ShapePtr pShapePtr )
      51             : : oox::drawingml::ShapeContext( rParent, pMasterShapePtr, pShapePtr )
      52         140 : , mpSlidePersistPtr( pSlidePersistPtr )
      53             : {
      54         140 : }
      55             : 
      56         212 : oox::drawingml::ShapePtr findPlaceholder( const sal_Int32 nMasterPlaceholder, const OptValue< sal_Int32 >& oSubTypeIndex, std::vector< oox::drawingml::ShapePtr >& rShapes )
      57             : {
      58         212 :     oox::drawingml::ShapePtr aShapePtr;
      59         424 :     oox::drawingml::ShapePtr aChoiceShapePtr1;
      60         424 :     oox::drawingml::ShapePtr aChoiceShapePtr2;
      61         212 :     std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() );
      62         577 :     while( aRevIter != rShapes.rend() )
      63             :     {
      64         189 :         if ( (*aRevIter)->getSubType() == nMasterPlaceholder )
      65             :         {
      66          28 :             if( !oSubTypeIndex.has() && aChoiceShapePtr1 == 0 )
      67          10 :                 aChoiceShapePtr1 = *aRevIter;
      68          18 :             else if( aChoiceShapePtr2 == 0 )
      69          18 :                 aChoiceShapePtr2 = *aRevIter;
      70          28 :             if( (*aRevIter)->getSubTypeIndex() == oSubTypeIndex )
      71             :             {
      72           8 :                 aShapePtr = *aRevIter;
      73           8 :                 break;
      74             :             }
      75             :         }
      76         181 :         std::vector< oox::drawingml::ShapePtr >& rChildren = (*aRevIter)->getChildren();
      77         181 :         aShapePtr = findPlaceholder( nMasterPlaceholder, oSubTypeIndex, rChildren );
      78         181 :         if ( aShapePtr.get() )
      79          28 :             break;
      80         153 :         ++aRevIter;
      81             :     }
      82         212 :     if( aShapePtr == 0 )
      83         176 :         return aChoiceShapePtr1 ? aChoiceShapePtr1 : aChoiceShapePtr2;
      84         248 :     return aShapePtr;
      85             : }
      86             : 
      87             : // if nFirstPlaceholder can't be found, it will be searched for nSecondPlaceholder
      88          29 : oox::drawingml::ShapePtr findPlaceholder( sal_Int32 nFirstPlaceholder, sal_Int32 nSecondPlaceholder,
      89             :     const OptValue< sal_Int32 >& oSubTypeIndex, std::vector< oox::drawingml::ShapePtr >& rShapes )
      90             : {
      91          29 :     oox::drawingml::ShapePtr pPlaceholder = findPlaceholder( nFirstPlaceholder, oSubTypeIndex, rShapes );
      92          29 :     return !nSecondPlaceholder || pPlaceholder.get() ? pPlaceholder : findPlaceholder( nSecondPlaceholder, oSubTypeIndex, rShapes );
      93             : }
      94             : 
      95        1052 : ContextHandlerRef PPTShapeContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
      96             : {
      97        1052 :     if( getNamespace( aElementToken ) == NMSP_dsp )
      98           0 :         aElementToken = NMSP_ppt | getBaseToken( aElementToken );
      99             : 
     100        1052 :     switch( aElementToken )
     101             :     {
     102             :         // nvSpPr CT_ShapeNonVisual begin
     103             :         //  case PPT_TOKEN( drElemPr ):
     104             :         //      break;
     105             :         case PPT_TOKEN( cNvPr ):
     106             :         {
     107         140 :             mpShapePtr->setHidden( rAttribs.getBool( XML_hidden, false ) );
     108         140 :             mpShapePtr->setId( rAttribs.getString( XML_id ).get() );
     109         140 :             mpShapePtr->setName( rAttribs.getString( XML_name ).get() );
     110         140 :             break;
     111             :         }
     112             :         case PPT_TOKEN( ph ):
     113             :         {
     114          78 :             sal_Int32 nSubType( rAttribs.getToken( XML_type, XML_obj ) );
     115          78 :             mpShapePtr->setSubType( nSubType );
     116          78 :             if( rAttribs.hasAttribute( XML_idx ) )
     117          55 :                 mpShapePtr->setSubTypeIndex( rAttribs.getString( XML_idx ).get().toInt32() );
     118          78 :             if ( nSubType )
     119             :             {
     120          78 :                 PPTShape* pPPTShapePtr = dynamic_cast< PPTShape* >( mpShapePtr.get() );
     121          78 :                 if ( pPPTShapePtr )
     122             :                 {
     123          78 :                     oox::ppt::ShapeLocation eShapeLocation = pPPTShapePtr->getShapeLocation();
     124          78 :                     if ( ( eShapeLocation == Slide ) || ( eShapeLocation == Layout ) )
     125             :                     {
     126             :                         // inheriting properties from placeholder objects by cloning shape
     127          34 :                         sal_Int32 nFirstPlaceholder = 0;
     128          34 :                         sal_Int32 nSecondPlaceholder = 0;
     129          34 :                         switch( nSubType )
     130             :                         {
     131             :                             case XML_ctrTitle :     // slide/layout
     132           1 :                                   nFirstPlaceholder = XML_ctrTitle;
     133           1 :                                   nSecondPlaceholder = XML_title;
     134           1 :                               break;
     135             : 
     136             :                               case XML_subTitle :       // slide/layout
     137           2 :                                   nFirstPlaceholder = XML_subTitle;
     138           2 :                                   nSecondPlaceholder = XML_title;
     139           2 :                               break;
     140             : 
     141             :                              case XML_obj :         // slide/layout
     142           3 :                                   nFirstPlaceholder = XML_obj;
     143           3 :                                   nSecondPlaceholder = XML_body;
     144           3 :                               break;
     145             : 
     146             :                             case XML_dt :           // slide/layout/master/notes/notesmaster/handoutmaster
     147             :                               case XML_sldNum :     // slide/layout/master/notes/notesmaster/handoutmaster
     148             :                               case XML_ftr :            // slide/layout/master/notes/notesmaster/handoutmaster
     149             :                               case XML_hdr :            // notes/notesmaster/handoutmaster
     150             :                               case XML_body :           // slide/layout/master/notes/notesmaster
     151             :                               case XML_title :      // slide/layout/master/
     152             :                               case XML_chart :      // slide/layout
     153             :                               case XML_tbl :            // slide/layout
     154             :                               case XML_clipArt :        // slide/layout
     155             :                               case XML_dgm :            // slide/layout
     156             :                               case XML_media :      // slide/layout
     157             :                               case XML_sldImg :     // notes/notesmaster
     158             :                               case XML_pic :            // slide/layout
     159          28 :                                   nFirstPlaceholder = nSubType;
     160             :                               default:
     161          28 :                                   break;
     162             :                         }
     163          34 :                           if ( nFirstPlaceholder )
     164             :                           {
     165          34 :                               oox::drawingml::ShapePtr pPlaceholder;
     166          34 :                               if ( eShapeLocation == Layout )       // for layout objects the referenced object can be found within the same shape tree
     167             :                               {
     168          24 :                                   if( pPPTShapePtr->getSubTypeIndex().has() )
     169          17 :                                       pPlaceholder = PPTShape::findPlaceholderByIndex( pPPTShapePtr->getSubTypeIndex().get(), mpSlidePersistPtr->getShapes()->getChildren() );
     170          24 :                                   if ( !pPlaceholder.get() )
     171          42 :                                       pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, pPPTShapePtr->getSubTypeIndex(),
     172          63 :                                                                       mpSlidePersistPtr->getShapes()->getChildren() );
     173             :                               }
     174          10 :                               else if ( eShapeLocation == Slide )   // normal slide shapes have to search within the corresponding master tree for referenced objects
     175             :                               {
     176          10 :                                   SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
     177          10 :                                   if ( pMasterPersist.get() ) {
     178          10 :                                       if( pPPTShapePtr->getSubTypeIndex().has() )
     179           7 :                                           pPlaceholder = PPTShape::findPlaceholderByIndex( pPPTShapePtr->getSubTypeIndex().get(), pMasterPersist->getShapes()->getChildren() );
     180             :                                       // TODO: Check if this is required for non-notes pages as well...
     181          12 :                                       if ( !pPlaceholder.get() || ( pMasterPersist->isNotesPage() && pPlaceholder->getSubType() != nFirstPlaceholder &&
     182           2 :                                                                                                      pPlaceholder->getSubType() != nSecondPlaceholder ) )
     183             :                                       {
     184          16 :                                           pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder,
     185          24 :                                                                           pPPTShapePtr->getSubTypeIndex(), pMasterPersist->getShapes()->getChildren() );
     186             :                                       }
     187          10 :                                   }
     188             :                               }
     189          34 :                               if ( pPlaceholder.get() )
     190             :                               {
     191             :                                   OSL_TRACE("shape %s will get shape reference %s applied", OUStringToOString(mpShapePtr->getId(), RTL_TEXTENCODING_UTF8 ).getStr(), OUStringToOString(pPlaceholder->getId(), RTL_TEXTENCODING_UTF8 ).getStr());
     192          33 :                                   mpShapePtr->applyShapeReference( *pPlaceholder.get() );
     193          33 :                                   PPTShape* pPPTShape = dynamic_cast< PPTShape* >( pPlaceholder.get() );
     194          33 :                                   if ( pPPTShape )
     195          33 :                                       pPPTShape->setReferenced( sal_True );
     196          33 :                                   pPPTShapePtr->setPlaceholder( pPlaceholder );
     197          34 :                               }
     198             :                           }
     199             :                     }
     200             :                   }
     201             : 
     202             :               }
     203          78 :               break;
     204             :         }
     205             : 
     206             :         // nvSpPr CT_ShapeNonVisual end
     207             : 
     208             :         case PPT_TOKEN( spPr ):
     209         140 :             return new PPTShapePropertiesContext( *this, *mpShapePtr );
     210             : 
     211             :         case PPT_TOKEN( style ):
     212          49 :             return new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr );
     213             : 
     214             :         case PPT_TOKEN( txBody ):
     215             :         {
     216         137 :             oox::drawingml::TextBodyPtr xTextBody( new oox::drawingml::TextBody( mpShapePtr->getTextBody() ) );
     217         137 :             xTextBody->getTextProperties().maPropertyMap[ PROP_FontIndependentLineSpacing ] <<= static_cast< sal_Bool >( sal_True );
     218         137 :             mpShapePtr->setTextBody( xTextBody );
     219         137 :             return new oox::drawingml::TextBodyContext( *this, *xTextBody );
     220             :         }
     221             :         case PPT_TOKEN( txXfrm ):
     222             :         {
     223           0 :             return new oox::drawingml::Transform2DContext( *this, rAttribs, *mpShapePtr, true );
     224             :         }
     225             :     }
     226             : 
     227         726 :     return this;
     228             : }
     229             : 
     230             : 
     231         141 : } }
     232             : 
     233             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10