LCOV - code coverage report
Current view: top level - libreoffice/oox/source/ppt - pptimport.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 56 84 66.7 %
Date: 2012-12-17 Functions: 17 23 73.9 %
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/pptimport.hxx"
      21             : #include "oox/drawingml/chart/chartconverter.hxx"
      22             : #include "oox/dump/pptxdumper.hxx"
      23             : #include "oox/drawingml/table/tablestylelistfragmenthandler.hxx"
      24             : #include "oox/helper/graphichelper.hxx"
      25             : #include "oox/ole/vbaproject.hxx"
      26             : 
      27             : using ::rtl::OUString;
      28             : using namespace ::com::sun::star;
      29             : using namespace ::com::sun::star::uno;
      30             : using namespace ::com::sun::star::xml::sax;
      31             : using namespace oox::core;
      32             : 
      33             : using ::com::sun::star::beans::PropertyValue;
      34             : using ::com::sun::star::lang::XComponent;
      35             : 
      36             : namespace oox { namespace ppt {
      37             : 
      38          28 : OUString SAL_CALL PowerPointImport_getImplementationName() throw()
      39             : {
      40          28 :     return CREATE_OUSTRING( "com.sun.star.comp.oox.ppt.PowerPointImport" );
      41             : }
      42             : 
      43           4 : uno::Sequence< OUString > SAL_CALL PowerPointImport_getSupportedServiceNames() throw()
      44             : {
      45           4 :     Sequence< OUString > aSeq( 2 );
      46           4 :     aSeq[ 0 ] = CREATE_OUSTRING( "com.sun.star.document.ImportFilter" );
      47           4 :     aSeq[ 1 ] = CREATE_OUSTRING( "com.sun.star.document.ExportFilter" );
      48           4 :     return aSeq;
      49             : }
      50             : 
      51           8 : uno::Reference< uno::XInterface > SAL_CALL PowerPointImport_createInstance( const Reference< XComponentContext >& rxContext ) throw( Exception )
      52             : {
      53           8 :     return static_cast< ::cppu::OWeakObject* >( new PowerPointImport( rxContext ) );
      54             : }
      55             : 
      56             : #if OSL_DEBUG_LEVEL > 0
      57             : XmlFilterBase* PowerPointImport::mpDebugFilterBase = NULL;
      58             : #endif
      59             : 
      60           8 : PowerPointImport::PowerPointImport( const Reference< XComponentContext >& rxContext ) throw( RuntimeException ) :
      61             :     XmlFilterBase( rxContext ),
      62           8 :     mxChartConv( new ::oox::drawingml::chart::ChartConverter )
      63             : 
      64             : {
      65             : #if OSL_DEBUG_LEVEL > 0
      66             :     mpDebugFilterBase = this;
      67             : #endif
      68           8 : }
      69             : 
      70          16 : PowerPointImport::~PowerPointImport()
      71             : {
      72          16 : }
      73             : 
      74           8 : bool PowerPointImport::importDocument() throw()
      75             : {
      76             :     /*  to activate the PPTX dumper, define the environment variable
      77             :         OOO_PPTXDUMPER and insert the full path to the file
      78             :         file:///<path-to-oox-module>/source/dump/pptxdumper.ini. */
      79             :     OOX_DUMP_FILE( ::oox::dump::pptx::Dumper );
      80             : 
      81           8 :     OUString aFragmentPath = getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "officeDocument" ) );
      82           8 :     FragmentHandlerRef xPresentationFragmentHandler( new PresentationFragmentHandler( *this, aFragmentPath ) );
      83           8 :     maTableStyleListPath = xPresentationFragmentHandler->getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "tableStyles" ) );
      84           8 :     return importFragment( xPresentationFragmentHandler );
      85             : 
      86             : 
      87             : }
      88             : 
      89           0 : bool PowerPointImport::exportDocument() throw()
      90             : {
      91           0 :     return false;
      92             : }
      93             : 
      94          96 : sal_Int32 PowerPointImport::getSchemeColor( sal_Int32 nToken ) const
      95             : {
      96          96 :     sal_Int32 nColor = 0;
      97          96 :     if ( mpActualSlidePersist )
      98             :     {
      99          96 :         sal_Bool bColorMapped = sal_False;
     100          96 :         oox::drawingml::ClrMapPtr pClrMapPtr( mpActualSlidePersist->getClrMap() );
     101          96 :         if ( pClrMapPtr )
     102          80 :             bColorMapped = pClrMapPtr->getColorMap( nToken );
     103             : 
     104          96 :         if ( !bColorMapped )    // try masterpage mapping
     105             :         {
     106          16 :             SlidePersistPtr pMasterPersist = mpActualSlidePersist->getMasterPersist();
     107          16 :             if ( pMasterPersist )
     108             :             {
     109          16 :                 pClrMapPtr = pMasterPersist->getClrMap();
     110          16 :                 if ( pClrMapPtr )
     111          16 :                     bColorMapped = pClrMapPtr->getColorMap( nToken );
     112          16 :             }
     113             :         }
     114          96 :         oox::drawingml::ClrSchemePtr pClrSchemePtr( mpActualSlidePersist->getClrScheme() );
     115          96 :         if ( pClrSchemePtr )
     116           0 :             pClrSchemePtr->getColor( nToken, nColor );
     117             :         else
     118             :         {
     119          96 :             ::oox::drawingml::ThemePtr pTheme = mpActualSlidePersist->getTheme();
     120          96 :             if( pTheme )
     121             :             {
     122          96 :                 pTheme->getClrScheme().getColor( nToken, nColor );
     123             :             }
     124             :             else
     125             :             {
     126             :                 OSL_TRACE("OOX: PowerPointImport::mpThemePtr is NULL");
     127          96 :             }
     128          96 :         }
     129             :     }
     130          96 :     return nColor;
     131             : }
     132             : 
     133         814 : const ::oox::drawingml::Theme* PowerPointImport::getCurrentTheme() const
     134             : {
     135         814 :     return mpActualSlidePersist ? mpActualSlidePersist->getTheme().get() : 0;
     136             : }
     137             : 
     138           8 : sal_Bool SAL_CALL PowerPointImport::filter( const Sequence< PropertyValue >& rDescriptor ) throw( RuntimeException )
     139             : {
     140           8 :     if( XmlFilterBase::filter( rDescriptor ) )
     141           8 :         return true;
     142             : 
     143           0 :     if( isExportFilter() ) {
     144           0 :         Reference< XExporter > xExporter( getServiceFactory()->createInstance( CREATE_OUSTRING( "com.sun.star.comp.Impress.oox.PowerPointExport" ) ), UNO_QUERY );
     145             : 
     146           0 :         if( xExporter.is() ) {
     147           0 :             Reference< XComponent > xDocument( getModel(), UNO_QUERY );
     148           0 :             Reference< XFilter > xFilter( xExporter, UNO_QUERY );
     149             : 
     150           0 :             if( xFilter.is() ) {
     151           0 :                 xExporter->setSourceDocument( xDocument );
     152           0 :                 if( xFilter->filter( rDescriptor ) )
     153           0 :                     return true;
     154           0 :             }
     155           0 :         }
     156             :     }
     157             : 
     158           0 :     return false;
     159             : }
     160             : 
     161           0 : ::oox::vml::Drawing* PowerPointImport::getVmlDrawing()
     162             : {
     163           0 :     return mpActualSlidePersist ? mpActualSlidePersist->getDrawing() : 0;
     164             : }
     165             : 
     166           0 : const oox::drawingml::table::TableStyleListPtr PowerPointImport::getTableStyles()
     167             : {
     168           0 :     if ( !mpTableStyleList && !maTableStyleListPath.isEmpty() )
     169             :     {
     170           0 :         mpTableStyleList = oox::drawingml::table::TableStyleListPtr( new oox::drawingml::table::TableStyleList() );
     171             :         importFragment( new oox::drawingml::table::TableStyleListFragmentHandler(
     172           0 :             *this, maTableStyleListPath, *mpTableStyleList ) );
     173             :     }
     174           0 :     return mpTableStyleList;
     175             : }
     176             : 
     177           0 : ::oox::drawingml::chart::ChartConverter* PowerPointImport::getChartConverter()
     178             : {
     179           0 :     return mxChartConv.get();
     180             : }
     181             : 
     182             : namespace {
     183             : 
     184          16 : class PptGraphicHelper : public GraphicHelper
     185             : {
     186             : public:
     187             :     explicit            PptGraphicHelper( const PowerPointImport& rFilter );
     188             :     virtual sal_Int32   getSchemeColor( sal_Int32 nToken ) const;
     189             : private:
     190             :     const PowerPointImport& mrFilter;
     191             : };
     192             : 
     193           8 : PptGraphicHelper::PptGraphicHelper( const PowerPointImport& rFilter ) :
     194           8 :     GraphicHelper( rFilter.getComponentContext(), rFilter.getTargetFrame(), rFilter.getStorage() ),
     195          16 :     mrFilter( rFilter )
     196             : {
     197           8 : }
     198             : 
     199          96 : sal_Int32 PptGraphicHelper::getSchemeColor( sal_Int32 nToken ) const
     200             : {
     201          96 :     return mrFilter.getSchemeColor( nToken );
     202             : }
     203             : 
     204             : } // namespace
     205             : 
     206           8 : GraphicHelper* PowerPointImport::implCreateGraphicHelper() const
     207             : {
     208           8 :     return new PptGraphicHelper( *this );
     209             : }
     210             : 
     211           0 : ::oox::ole::VbaProject* PowerPointImport::implCreateVbaProject() const
     212             : {
     213           0 :     return new ::oox::ole::VbaProject( getComponentContext(), getModel(), CREATE_OUSTRING( "Impress" ) );
     214             : }
     215             : 
     216           0 : OUString PowerPointImport::implGetImplementationName() const
     217             : {
     218           0 :     return PowerPointImport_getImplementationName();
     219             : }
     220             : 
     221         174 : }}
     222             : 
     223             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10