LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/oox/source/ppt - slidepersist.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 113 154 73.4 %
Date: 2013-07-09 Functions: 9 10 90.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 "oox/ppt/timenode.hxx"
      21             : #include "oox/ppt/pptshape.hxx"
      22             : #include "oox/ppt/slidepersist.hxx"
      23             : #include "oox/drawingml/fillproperties.hxx"
      24             : #include "oox/drawingml/shapepropertymap.hxx"
      25             : #include "oox/helper/propertyset.hxx"
      26             : #include "oox/vml/vmldrawing.hxx"
      27             : #include "oox/core/xmlfilterbase.hxx"
      28             : 
      29             : #include <com/sun/star/style/XStyle.hpp>
      30             : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
      31             : #include <com/sun/star/container/XNamed.hpp>
      32             : #include <com/sun/star/beans/XMultiPropertySet.hpp>
      33             : #include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
      34             : 
      35             : using namespace ::com::sun::star;
      36             : using namespace ::oox::core;
      37             : using namespace ::com::sun::star::uno;
      38             : using namespace ::com::sun::star::drawing;
      39             : using namespace ::com::sun::star::container;
      40             : using namespace ::com::sun::star::animations;
      41             : 
      42             : namespace oox { namespace ppt {
      43             : 
      44          22 : SlidePersist::SlidePersist( XmlFilterBase& rFilter, sal_Bool bMaster, sal_Bool bNotes,
      45             :     const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& rxPage,
      46             :         oox::drawingml::ShapePtr pShapesPtr, const drawingml::TextListStylePtr & pDefaultTextStyle )
      47          22 : : mpDrawingPtr( new oox::vml::Drawing( rFilter, rxPage, oox::vml::VMLDRAWING_POWERPOINT ) )
      48             : , mxPage( rxPage )
      49             : , maShapesPtr( pShapesPtr )
      50             : , mnLayoutValueToken( 0 )
      51             : , mbMaster( bMaster )
      52             : , mbNotes ( bNotes )
      53             : , maDefaultTextStylePtr( pDefaultTextStyle )
      54          22 : , maTitleTextStylePtr( new oox::drawingml::TextListStyle )
      55          22 : , maBodyTextStylePtr( new oox::drawingml::TextListStyle )
      56          22 : , maNotesTextStylePtr( new oox::drawingml::TextListStyle )
      57         110 : , maOtherTextStylePtr( new oox::drawingml::TextListStyle )
      58             : {
      59             : #if OSL_DEBUG_LEVEL > 0
      60             :     mxDebugPage = mxPage;
      61             : #endif
      62          22 : }
      63             : 
      64             : #if OSL_DEBUG_LEVEL > 0
      65             : ::com::sun::star::uno::WeakReference< ::com::sun::star::drawing::XDrawPage > SlidePersist::mxDebugPage;
      66             : #endif
      67             : 
      68          22 : SlidePersist::~SlidePersist()
      69             : {
      70          22 : }
      71             : 
      72           8 : sal_Int16 SlidePersist::getLayoutFromValueToken()
      73             : {
      74           8 :     sal_Int16 nLayout = 20;     // 20 == blanc (so many magic numbers :-( the description at com.sun.star.presentation.DrawPage.Layout does not help)
      75           8 :     switch( mnLayoutValueToken )
      76             :     {
      77           1 :         case XML_blank:             nLayout = 20; break;
      78           0 :         case XML_chart:             nLayout =  2; break;
      79           0 :         case XML_chartAndTx:        nLayout =  7; break;
      80           0 :         case XML_clipArtAndTx:      nLayout =  9; break;
      81           0 :         case XML_clipArtAndVertTx:  nLayout = 24; break;
      82           0 :         case XML_fourObj:           nLayout = 18; break;
      83           2 :         case XML_obj:               nLayout = 11; break;
      84           0 :         case XML_objAndTx:          nLayout = 13; break;
      85           0 :         case XML_objOverTx:         nLayout = 14; break;
      86           0 :         case XML_tbl:               nLayout =  8; break;
      87           1 :         case XML_title:             nLayout =  0; break;
      88           1 :         case XML_titleOnly:         nLayout = 19; break;
      89             :         case XML_twoObj:
      90           0 :         case XML_twoColTx:          nLayout =  3; break;
      91           0 :         case XML_twoObjAndTx:       nLayout = 15; break;
      92           0 :         case XML_twoObjOverTx:      nLayout = 16; break;
      93           1 :         case XML_tx:                nLayout =  1; break;
      94           0 :         case XML_txAndChart:        nLayout =  4; break;
      95           0 :         case XML_txAndClipArt:      nLayout =  6; break;
      96           0 :         case XML_txAndMedia:        nLayout =  6; break;
      97           0 :         case XML_txAndObj:          nLayout = 10; break;
      98           0 :         case XML_txAndTwoObj:       nLayout = 12; break;
      99           0 :         case XML_txOverObj:         nLayout = 17; break;
     100           0 :         case XML_vertTitleAndTx:    nLayout = 22; break;
     101           0 :         case XML_vertTitleAndTxOverChart: nLayout = 21; break;
     102           0 :         case XML_vertTx:            nLayout = 23; break;
     103             : 
     104             :         case XML_twoTxTwoObj:
     105             :         case XML_twoObjAndObj:
     106             :         case XML_objTx:
     107             :         case XML_picTx:
     108             :         case XML_secHead:
     109             :         case XML_objOnly:
     110             :         case XML_objAndTwoObj:
     111             :         case XML_mediaAndTx:
     112             :         case XML_dgm:
     113             :         case XML_cust:
     114             :         default:
     115           2 :             nLayout = 20;
     116             :     }
     117           8 :     return nLayout;
     118             : }
     119             : 
     120          19 : void SlidePersist::createXShapes( XmlFilterBase& rFilterBase )
     121             : {
     122          19 :     applyTextStyles( rFilterBase );
     123             : 
     124          19 :     Reference< XShapes > xShapes( getPage(), UNO_QUERY );
     125             : 
     126          19 :     std::vector< oox::drawingml::ShapePtr >& rShapes( maShapesPtr->getChildren() );
     127          19 :     const std::vector< oox::drawingml::ShapePtr >::const_iterator aShapesEnd( rShapes.end() );
     128          46 :     for (std::vector< oox::drawingml::ShapePtr >::const_iterator aShapesIter( rShapes.begin() );
     129             :          aShapesIter != aShapesEnd ; ++aShapesIter)
     130             :     {
     131          27 :         std::vector< oox::drawingml::ShapePtr >& rChildren( (*aShapesIter)->getChildren() );
     132          27 :         const std::vector< oox::drawingml::ShapePtr >::const_iterator aChildEnd( rChildren.end() );
     133         159 :         for (std::vector< oox::drawingml::ShapePtr >::const_iterator aChildIter( rChildren.begin() );
     134             :              aChildIter != aChildEnd ; ++aChildIter)
     135             :         {
     136         132 :             PPTShape* pPPTShape = dynamic_cast< PPTShape* >( (*aChildIter).get() );
     137         132 :             basegfx::B2DHomMatrix aTransformation;
     138         132 :             if ( pPPTShape )
     139         132 :                 pPPTShape->addShape( rFilterBase, *this, getTheme().get(), xShapes, aTransformation, 0, &getShapeMap() );
     140             :             else
     141           0 :                 (*aChildIter)->addShape( rFilterBase, getTheme().get(), xShapes, aTransformation, maShapesPtr->getFillProperties(), 0, &getShapeMap() );
     142         132 :         }
     143             :     }
     144             : 
     145          38 :     Reference< XAnimationNodeSupplier > xNodeSupplier( getPage(), UNO_QUERY);
     146          19 :     if( xNodeSupplier.is() )
     147             :     {
     148          16 :         Reference< XAnimationNode > xNode( xNodeSupplier->getAnimationNode() );
     149          16 :         if( xNode.is() && !maTimeNodeList.empty() )
     150             :         {
     151           9 :             SlidePersistPtr pSlidePtr( shared_from_this() );
     152          18 :             TimeNodePtr pNode(maTimeNodeList.front());
     153             :             OSL_ENSURE( pNode, "pNode" );
     154             : 
     155          18 :             pNode->setNode( rFilterBase, xNode, pSlidePtr );
     156          16 :         }
     157          19 :     }
     158          19 : }
     159             : 
     160          19 : void SlidePersist::createBackground( const XmlFilterBase& rFilterBase )
     161             : {
     162          19 :     if ( mpBackgroundPropertiesPtr )
     163             :     {
     164           7 :         sal_Int32 nPhClr = maBackgroundColor.isUsed() ?
     165           7 :             maBackgroundColor.getColor( rFilterBase.getGraphicHelper() ) : API_RGB_TRANSPARENT;
     166             : 
     167           7 :         ::oox::drawingml::ShapePropertyMap aPropMap( rFilterBase.getModelObjectHelper() );
     168           7 :         mpBackgroundPropertiesPtr->pushToPropMap( aPropMap, rFilterBase.getGraphicHelper(), 0, nPhClr );
     169           7 :         PropertySet( mxPage ).setProperty( PROP_Background, aPropMap.makePropertySet() );
     170             :     }
     171          19 : }
     172             : 
     173         128 : void setTextStyle( Reference< beans::XPropertySet >& rxPropSet, const XmlFilterBase& rFilter,
     174             :     oox::drawingml::TextListStylePtr& pTextListStylePtr, int nLevel )
     175             : {
     176         128 :     ::oox::drawingml::TextParagraphPropertiesPtr pTextParagraphPropertiesPtr( pTextListStylePtr->getListStyle()[ nLevel ] );
     177         128 :     if( pTextParagraphPropertiesPtr == 0 )
     178             :     {
     179             :         // no properties. return
     180         128 :         return;
     181             :     }
     182             : 
     183         128 :     PropertyMap& rTextParagraphPropertyMap( pTextParagraphPropertiesPtr->getTextParagraphPropertyMap() );
     184             : 
     185         256 :     PropertySet aPropSet( rxPropSet );
     186         128 :     aPropSet.setProperties( rTextParagraphPropertyMap );
     187         256 :     pTextParagraphPropertiesPtr->getTextCharacterProperties().pushToPropSet( aPropSet, rFilter );
     188             : }
     189             : 
     190          19 : void SlidePersist::applyTextStyles( const XmlFilterBase& rFilterBase )
     191             : {
     192          19 :     if ( mbMaster )
     193             :     {
     194             :         try
     195             :         {
     196           8 :             Reference< style::XStyleFamiliesSupplier > aXStyleFamiliesSupplier( rFilterBase.getModel(), UNO_QUERY_THROW );
     197          16 :             Reference< container::XNameAccess > aXNameAccess( aXStyleFamiliesSupplier->getStyleFamilies() );
     198          16 :             Reference< container::XNamed > aXNamed( mxPage, UNO_QUERY_THROW );
     199             : 
     200           8 :             if ( aXNameAccess.is() && aXNamed.is() )
     201             :             {
     202           8 :                 oox::drawingml::TextListStylePtr pTextListStylePtr;
     203          16 :                 OUString aStyle;
     204          16 :                 OUString aFamily;
     205             : 
     206          16 :                 const OUString sOutline( "outline1" );
     207          16 :                 const OUString sTitle( "title" );
     208          16 :                 const OUString sStandard( "standard" );
     209          16 :                 const OUString sSubtitle( "subtitle" );
     210             : 
     211          40 :                 for( int i = 0; i < 4; i++ )    // todo: aggregation of bodystyle (subtitle)
     212             :                 {
     213          32 :                     switch( i )
     214             :                     {
     215             :                         case 0 :    // title style
     216             :                         {
     217           8 :                             pTextListStylePtr = maTitleTextStylePtr;
     218           8 :                             aStyle = sTitle;
     219           8 :                             aFamily= aXNamed->getName();
     220           8 :                             break;
     221             :                         }
     222             :                         case 1 :    // body style
     223             :                         {
     224           8 :                             pTextListStylePtr = maBodyTextStylePtr;
     225           8 :                             aStyle = sOutline;
     226           8 :                             aFamily= aXNamed->getName();
     227           8 :                             break;
     228             :                         }
     229             :                         case 3 :    // notes style
     230             :                         {
     231           8 :                             pTextListStylePtr = maNotesTextStylePtr;
     232           8 :                             aStyle = sTitle;
     233           8 :                             aFamily= aXNamed->getName();
     234           8 :                             break;
     235             :                         }
     236             :                         case 4 :    // standard style
     237             :                         {
     238           0 :                             pTextListStylePtr = maOtherTextStylePtr;
     239           0 :                             aStyle = sStandard;
     240           0 :                             aFamily = "graphics";
     241           0 :                             break;
     242             :                         }
     243             :                         case 5 :    // subtitle
     244             :                         {
     245           0 :                             pTextListStylePtr = maBodyTextStylePtr;
     246           0 :                             aStyle = sSubtitle;
     247           0 :                             aFamily = aXNamed->getName();
     248           0 :                             break;
     249             :                         }
     250             :                     }
     251          32 :                     Reference< container::XNameAccess > xFamilies;
     252          32 :                     if ( aXNameAccess->hasByName( aFamily ) )
     253             :                     {
     254          32 :                         if( aXNameAccess->getByName( aFamily ) >>= xFamilies )
     255             :                         {
     256          32 :                             if ( xFamilies->hasByName( aStyle ) )
     257             :                             {
     258          32 :                                 Reference< style::XStyle > aXStyle;
     259          32 :                                 if ( xFamilies->getByName( aStyle ) >>= aXStyle )
     260             :                                 {
     261          32 :                                     Reference< beans::XPropertySet > xPropSet( aXStyle, UNO_QUERY_THROW );
     262          32 :                                     setTextStyle( xPropSet, rFilterBase, maDefaultTextStylePtr, 0 );
     263          32 :                                     setTextStyle( xPropSet, rFilterBase, pTextListStylePtr, 0 );
     264          32 :                                     if ( i == 1 /* BodyStyle */ )
     265             :                                     {
     266          40 :                                         for ( int nLevel = 1; nLevel < 5; nLevel++ )
     267             :                                         {
     268             :                                             {
     269          32 :                                                 sal_Char pOutline[ 9 ] = "outline1";
     270          32 :                                                 pOutline[ 7 ] = static_cast< sal_Char >( '0' + nLevel );
     271          32 :                                                 OUString sOutlineStyle( OUString::createFromAscii( pOutline ) );
     272          32 :                                                 if ( xFamilies->hasByName( sOutlineStyle ) )
     273             :                                                 {
     274          32 :                                                     xFamilies->getByName( sOutlineStyle ) >>= aXStyle;
     275          32 :                                                     if( aXStyle.is() )
     276          32 :                                                         xPropSet = Reference< beans::XPropertySet >( aXStyle, UNO_QUERY_THROW );
     277          32 :                                                 }
     278             :                                             }
     279          32 :                                             setTextStyle( xPropSet, rFilterBase, maDefaultTextStylePtr, nLevel );
     280          32 :                                             setTextStyle( xPropSet, rFilterBase, pTextListStylePtr, nLevel );
     281             :                                         }
     282          32 :                                     }
     283          32 :                                 }
     284             :                             }
     285             :                         }
     286             :                     }
     287          40 :                 }
     288           8 :             }
     289             :         }
     290           0 :         catch( const Exception& )
     291             :         {
     292             :         }
     293             :     }
     294          19 : }
     295             : 
     296           0 : void SlidePersist::hideShapesAsMasterShapes()
     297             : {
     298           0 :     std::vector< oox::drawingml::ShapePtr >& rShapes( maShapesPtr->getChildren() );
     299           0 :     std::vector< oox::drawingml::ShapePtr >::iterator aShapesIter( rShapes.begin() );
     300           0 :     while( aShapesIter != rShapes.end() )
     301             :     {
     302           0 :         while( aShapesIter != rShapes.end() )
     303             :         {
     304           0 :             std::vector< oox::drawingml::ShapePtr >& rChildren( (*aShapesIter++)->getChildren() );
     305           0 :             std::vector< oox::drawingml::ShapePtr >::iterator aChildIter( rChildren.begin() );
     306           0 :             while( aChildIter != rChildren.end() ) {
     307           0 :                 PPTShape* pPPTShape = dynamic_cast< PPTShape* >( (*aChildIter++).get() );
     308             :                 OSL_TRACE("hide shape with id: %s", OUStringToOString(pPPTShape->getId(), RTL_TEXTENCODING_UTF8 ).getStr());
     309           0 :                 pPPTShape->setHiddenMasterShape( true );
     310             :             }
     311             :         }
     312             :     }
     313           0 : }
     314             : 
     315         141 : } }
     316             : 
     317             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10