LCOV - code coverage report
Current view: top level - libreoffice/filter/source/svg - svgfilter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 125 0.0 %
Date: 2012-12-27 Functions: 0 11 0.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             : 
      21             : #include <cstdio>
      22             : 
      23             : #include <comphelper/servicedecl.hxx>
      24             : #include <uno/environment.h>
      25             : #include <com/sun/star/drawing/XDrawPage.hpp>
      26             : #include <com/sun/star/drawing/XDrawView.hpp>
      27             : #include <com/sun/star/frame/Desktop.hpp>
      28             : #include <com/sun/star/frame/XController.hpp>
      29             : #include <com/sun/star/view/XSelectionSupplier.hpp>
      30             : #include <com/sun/star/drawing/XDrawSubController.hpp>
      31             : #include <com/sun/star/container/XNamed.hpp>
      32             : #include <com/sun/star/uno/XComponentContext.hpp>
      33             : #include <com/sun/star/drawing/framework/XControllerManager.hpp>
      34             : #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
      35             : #include <com/sun/star/drawing/framework/XConfiguration.hpp>
      36             : #include <com/sun/star/drawing/framework/AnchorBindingMode.hpp>
      37             : #include <com/sun/star/drawing/framework/XResourceId.hpp>
      38             : #include <com/sun/star/drawing/framework/XResource.hpp>
      39             : #include <com/sun/star/drawing/framework/XView.hpp>
      40             : #include <com/sun/star/drawing/framework/ResourceId.hpp>
      41             : #include <comphelper/processfactory.hxx>
      42             : 
      43             : #include <osl/mutex.hxx>
      44             : 
      45             : #include "svgfilter.hxx"
      46             : 
      47             : using ::rtl::OUString;
      48             : using namespace ::com::sun::star;
      49             : 
      50             : // -------------
      51             : // - SVGFilter -
      52             : // -------------
      53             : 
      54           0 : SVGFilter::SVGFilter( const Reference< XComponentContext >& rxCtx ) :
      55             :     mxContext( rxCtx ),
      56             :     mpSVGDoc( NULL ),
      57             :     mpSVGExport( NULL ),
      58             :     mpSVGFontExport( NULL ),
      59             :     mpSVGWriter( NULL ),
      60             :     mpDefaultSdrPage( NULL ),
      61             :     mpSdrModel( NULL ),
      62             :     mbPresentation( sal_False ),
      63             :     mbExportAll( sal_False ),
      64           0 :     mpObjects( NULL )
      65             : 
      66             : {
      67           0 : }
      68             : 
      69             : // -----------------------------------------------------------------------------
      70             : 
      71           0 : SVGFilter::~SVGFilter()
      72             : {
      73             :     DBG_ASSERT( mpSVGDoc == NULL, "mpSVGDoc not destroyed" );
      74             :     DBG_ASSERT( mpSVGExport == NULL, "mpSVGExport not destroyed" );
      75             :     DBG_ASSERT( mpSVGFontExport == NULL, "mpSVGFontExport not destroyed" );
      76             :     DBG_ASSERT( mpSVGWriter == NULL, "mpSVGWriter not destroyed" );
      77             :     DBG_ASSERT( mpObjects == NULL, "mpObjects not destroyed" );
      78           0 : }
      79             : 
      80             : // -----------------------------------------------------------------------------
      81             : 
      82           0 : sal_Bool SAL_CALL SVGFilter::filter( const Sequence< PropertyValue >& rDescriptor )
      83             :     throw (RuntimeException)
      84             : {
      85           0 :     SolarMutexGuard aGuard;
      86           0 :     Window*     pFocusWindow = Application::GetFocusWindow();
      87             :     sal_Bool    bRet;
      88             : 
      89           0 :     if( pFocusWindow )
      90           0 :         pFocusWindow->EnterWait();
      91             : 
      92           0 :     if( mxDstDoc.is() )
      93           0 :         bRet = implImport( rDescriptor );
      94             : #ifndef DISABLE_EXPORT
      95           0 :     else if( mxSrcDoc.is() )
      96             :     {
      97           0 :         if( !mbExportAll && !mSelectedPages.hasElements() )
      98             :         {
      99           0 :             uno::Reference< frame::XDesktop2 >                           xDesktop(frame::Desktop::create(mxContext));
     100           0 :             uno::Reference< frame::XFrame >                              xFrame(xDesktop->getCurrentFrame(),
     101           0 :                                                                                 uno::UNO_QUERY_THROW);
     102           0 :             uno::Reference<frame::XController >                          xController(xFrame->getController(),
     103           0 :                                                                                      uno::UNO_QUERY_THROW);
     104             :             uno::Reference<drawing::XDrawView >                          xDrawView(xController,
     105           0 :                                                                                    uno::UNO_QUERY_THROW);
     106             :             uno::Reference<drawing::framework::XControllerManager>       xManager(xController,
     107           0 :                                                                                   uno::UNO_QUERY_THROW);
     108           0 :             uno::Reference<drawing::framework::XConfigurationController> xConfigController(xManager->getConfigurationController());
     109             : 
     110             :             // which view configuration are we in?
     111             :             //
     112             :             // * traverse Impress resources to find slide preview pane, grab selection from there
     113             :             // * otherwise, fallback to current slide
     114             :             //
     115             :             uno::Sequence<uno::Reference<drawing::framework::XResourceId> > aResIds(
     116           0 :                 xConfigController->getCurrentConfiguration()->getResources(
     117             :                     uno::Reference<drawing::framework::XResourceId>(),
     118             :                     "",
     119           0 :                     drawing::framework::AnchorBindingMode_INDIRECT));
     120             : 
     121           0 :             for( sal_Int32 i=0; i<aResIds.getLength(); ++i )
     122             :             {
     123             :                 // can we somehow obtain the slidesorter from the Impress framework?
     124           0 :                 if( aResIds[i]->getResourceURL() == "private:resource/view/SlideSorter" )
     125             :                 {
     126             :                     // got it, grab current selection from there
     127             :                     uno::Reference<drawing::framework::XResource> xRes(
     128           0 :                         xConfigController->getResource(aResIds[i]));
     129             : 
     130             :                     uno::Reference< view::XSelectionSupplier > xSelectionSupplier(
     131             :                         xRes,
     132           0 :                         uno::UNO_QUERY );
     133           0 :                     if( xSelectionSupplier.is() )
     134             :                     {
     135           0 :                         uno::Any aSelection = xSelectionSupplier->getSelection();
     136           0 :                         if( aSelection.hasValue() )
     137             :                         {
     138           0 :                             ObjectSequence aSelectedPageSequence;
     139           0 :                             aSelection >>= aSelectedPageSequence;
     140           0 :                             mSelectedPages.realloc( aSelectedPageSequence.getLength() );
     141           0 :                             for( sal_Int32 j=0; j<mSelectedPages.getLength(); ++j )
     142             :                             {
     143           0 :                                 uno::Reference< drawing::XDrawPage > xDrawPage( aSelectedPageSequence[j],
     144           0 :                                                                                 uno::UNO_QUERY );
     145           0 :                                 mSelectedPages[j] = xDrawPage;
     146           0 :                             }
     147             : 
     148             :                             // and stop looping. it is likely not getting better
     149           0 :                             break;
     150           0 :                         }
     151           0 :                     }
     152             :                 }
     153             :             }
     154             : 
     155           0 :             if( !mSelectedPages.hasElements() )
     156             :             {
     157             :                 // apparently failed to glean selection - fallback to current page
     158           0 :                 mSelectedPages.realloc( 1 );
     159           0 :                 mSelectedPages[0] = xDrawView->getCurrentPage();
     160           0 :             }
     161             :         }
     162             : 
     163             :         /*
     164             :          * Export all slides, or requested "PagePos"
     165             :          */
     166           0 :         if( !mSelectedPages.hasElements() )
     167             :         {
     168           0 :             sal_Int32            nLength = rDescriptor.getLength();
     169           0 :             const PropertyValue* pValue = rDescriptor.getConstArray();
     170           0 :             sal_Int32            nPageToExport = -1;
     171             : 
     172           0 :             for ( sal_Int32 i = 0 ; i < nLength; ++i)
     173             :             {
     174           0 :                 if ( pValue[ i ].Name == "PagePos" )
     175             :                 {
     176           0 :                     pValue[ i ].Value >>= nPageToExport;
     177             :                 }
     178             :             }
     179             : 
     180           0 :             uno::Reference< drawing::XMasterPagesSupplier > xMasterPagesSupplier( mxSrcDoc, uno::UNO_QUERY );
     181           0 :             uno::Reference< drawing::XDrawPagesSupplier >   xDrawPagesSupplier( mxSrcDoc, uno::UNO_QUERY );
     182             : 
     183           0 :             if( xMasterPagesSupplier.is() && xDrawPagesSupplier.is() )
     184             :             {
     185           0 :                 uno::Reference< drawing::XDrawPages >   xMasterPages( xMasterPagesSupplier->getMasterPages(), uno::UNO_QUERY );
     186           0 :                 uno::Reference< drawing::XDrawPages >   xDrawPages( xDrawPagesSupplier->getDrawPages(), uno::UNO_QUERY );
     187           0 :                 if( xMasterPages.is() && xMasterPages->getCount() &&
     188           0 :                     xDrawPages.is() && xDrawPages->getCount() )
     189             :                 {
     190           0 :                     sal_Int32 nDPCount = xDrawPages->getCount();
     191             : 
     192           0 :                     mSelectedPages.realloc( nPageToExport != -1 ? 1 : nDPCount );
     193             :                     sal_Int32 i;
     194           0 :                     for( i = 0; i < nDPCount; ++i )
     195             :                     {
     196           0 :                         if( nPageToExport != -1 && nPageToExport == i )
     197             :                         {
     198           0 :                             uno::Reference< drawing::XDrawPage > xDrawPage( xDrawPages->getByIndex( i ), uno::UNO_QUERY );
     199           0 :                             mSelectedPages[0] = xDrawPage;
     200             :                         }
     201             :                         else
     202             :                         {
     203           0 :                             uno::Reference< drawing::XDrawPage > xDrawPage( xDrawPages->getByIndex( i ), uno::UNO_QUERY );
     204           0 :                             mSelectedPages[i] = xDrawPage;
     205             :                         }
     206             :                     }
     207           0 :                 }
     208           0 :             }
     209             :         }
     210             : 
     211             :         /*
     212             :          *  We get all master page that are targeted by at least one draw page.
     213             :          *  The master page are put in an unordered set.
     214             :          */
     215           0 :         ObjectSet aMasterPageTargetSet;
     216           0 :         for( sal_Int32 i = 0; i < mSelectedPages.getLength(); ++i )
     217             :         {
     218           0 :             uno::Reference< drawing::XMasterPageTarget > xMasterPageTarget( mSelectedPages[i], uno::UNO_QUERY );
     219           0 :             if( xMasterPageTarget.is() )
     220             :             {
     221           0 :                 aMasterPageTargetSet.insert( xMasterPageTarget->getMasterPage() );
     222             :             }
     223           0 :         }
     224             :         // Later we move them to a uno::Sequence so we can get them by index
     225           0 :         mMasterPageTargets.realloc( aMasterPageTargetSet.size() );
     226           0 :         ObjectSet::const_iterator aElem = aMasterPageTargetSet.begin();
     227           0 :         for( sal_Int32 i = 0; aElem != aMasterPageTargetSet.end(); ++aElem, ++i)
     228             :         {
     229           0 :             uno::Reference< drawing::XDrawPage > xMasterPage( *aElem,  uno::UNO_QUERY );
     230           0 :             mMasterPageTargets[i] = xMasterPage;
     231           0 :         }
     232             : 
     233           0 :         bRet = implExport( rDescriptor );
     234             :     }
     235             : #endif
     236             :     else
     237           0 :         bRet = sal_False;
     238             : 
     239           0 :     if( pFocusWindow )
     240           0 :         pFocusWindow->LeaveWait();
     241             : 
     242           0 :     return bRet;
     243             : }
     244             : 
     245             : // -----------------------------------------------------------------------------
     246             : 
     247           0 : void SAL_CALL SVGFilter::cancel( ) throw (RuntimeException)
     248             : {
     249           0 : }
     250             : 
     251             : // -----------------------------------------------------------------------------
     252             : 
     253           0 : void SAL_CALL SVGFilter::setSourceDocument( const Reference< XComponent >& xDoc )
     254             :     throw (IllegalArgumentException, RuntimeException)
     255             : {
     256           0 :     mxSrcDoc = xDoc;
     257           0 : }
     258             : 
     259             : // -----------------------------------------------------------------------------
     260             : 
     261           0 : void SAL_CALL SVGFilter::setTargetDocument( const Reference< XComponent >& xDoc )
     262             :     throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException)
     263             : {
     264           0 :     mxDstDoc = xDoc;
     265           0 : }
     266             : 
     267             : // -----------------------------------------------------------------------------
     268             : 
     269           0 : rtl::OUString SAL_CALL SVGFilter::detect( Sequence< PropertyValue >& io_rDescriptor ) throw (RuntimeException)
     270             : {
     271           0 :     uno::Reference< io::XInputStream > xInput;
     272             : 
     273           0 :     const beans::PropertyValue* pAttribs = io_rDescriptor.getConstArray();
     274           0 :     const sal_Int32 nAttribs = io_rDescriptor.getLength();
     275           0 :     for( sal_Int32 i = 0; i < nAttribs; i++ )
     276             :     {
     277           0 :         if ( pAttribs[i].Name == "InputStream" )
     278           0 :             pAttribs[i].Value >>= xInput;
     279             :     }
     280             : 
     281           0 :     if( !xInput.is() )
     282           0 :         return rtl::OUString();
     283             : 
     284           0 :     uno::Reference< io::XSeekable > xSeek( xInput, uno::UNO_QUERY );
     285           0 :     if( xSeek.is() )
     286           0 :         xSeek->seek( 0 );
     287             : 
     288             :     // read the first 1024 bytes & check a few magic string
     289             :     // constants (heuristically)
     290           0 :     const sal_Int32 nLookAhead = 1024;
     291           0 :     uno::Sequence< sal_Int8 > aBuf( nLookAhead );
     292           0 :     const sal_uInt64 nBytes=xInput->readBytes(aBuf, nLookAhead);
     293           0 :     const sal_Int8* const pBuf=aBuf.getConstArray();
     294             : 
     295           0 :     sal_Int8 aMagic1[] = {'<', 's', 'v', 'g'};
     296           0 :     if( std::search(pBuf, pBuf+nBytes,
     297           0 :                     aMagic1, aMagic1+sizeof(aMagic1)/sizeof(*aMagic1)) != pBuf+nBytes )
     298           0 :         return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("svg_Scalable_Vector_Graphics") );
     299             : 
     300           0 :     sal_Int8 aMagic2[] = {'D', 'O', 'C', 'T', 'Y', 'P', 'E', ' ', 's', 'v', 'g'};
     301           0 :     if( std::search(pBuf, pBuf+nBytes,
     302           0 :                     aMagic2, aMagic2+sizeof(aMagic2)/sizeof(*aMagic2)) != pBuf+nBytes )
     303           0 :         return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("svg_Scalable_Vector_Graphics") );
     304             : 
     305           0 :     return rtl::OUString();
     306             : }
     307             : 
     308             : // -----------------------------------------------------------------------------
     309             : 
     310             : namespace sdecl = comphelper::service_decl;
     311           0 :  sdecl::class_<SVGFilter> serviceImpl;
     312           0 :  const sdecl::ServiceDecl svgFilter(
     313             :      serviceImpl,
     314             :      "com.sun.star.comp.Draw.SVGFilter",
     315             :      "com.sun.star.document.ImportFilter;"
     316             :      "com.sun.star.document.ExportFilter;"
     317             :      "com.sun.star.document.ExtendedTypeDetection" );
     318             : 
     319             : // The C shared lib entry points
     320           0 : extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL svgfilter_component_getFactory(
     321             :     sal_Char const* pImplName,
     322             :     ::com::sun::star::lang::XMultiServiceFactory* pServiceManager,
     323             :     ::com::sun::star::registry::XRegistryKey* pRegistryKey )
     324             : {
     325             :     return component_getFactoryHelper( pImplName, pServiceManager,
     326           0 :         pRegistryKey, svgFilter );
     327           0 : }
     328             : 
     329             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10