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

Generated by: LCOV version 1.10