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

Generated by: LCOV version 1.11