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

Generated by: LCOV version 1.10