LCOV - code coverage report
Current view: top level - filter/source/flash - swfexporter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 326 0.0 %
Date: 2012-08-25 Functions: 0 17 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <com/sun/star/awt/Rectangle.hpp>
      30                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      31                 :            : #include <com/sun/star/drawing/XMasterPageTarget.hpp>
      32                 :            : #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
      33                 :            : #include <com/sun/star/container/XIndexAccess.hpp>
      34                 :            : #include <com/sun/star/document/XFilter.hpp>
      35                 :            : #include <com/sun/star/document/XExporter.hpp>
      36                 :            : #include <com/sun/star/frame/XModel.hpp>
      37                 :            : #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
      38                 :            : #include <com/sun/star/lang/XServiceInfo.hpp>
      39                 :            : #include <vcl/gdimtf.hxx>
      40                 :            : #include <unotools/tempfile.hxx>
      41                 :            : #include <osl/diagnose.h>
      42                 :            : #include <osl/file.hxx>
      43                 :            : #include <vcl/metaact.hxx>
      44                 :            : #include <svtools/wmf.hxx>
      45                 :            : #include <svtools/filter.hxx>
      46                 :            : 
      47                 :            : #include "swfexporter.hxx"
      48                 :            : #include "swfwriter.hxx"
      49                 :            : 
      50                 :            : using rtl::OUString;
      51                 :            : using namespace ::com::sun::star::uno;
      52                 :            : using namespace ::com::sun::star::drawing;
      53                 :            : using namespace ::com::sun::star::presentation;
      54                 :            : using namespace ::com::sun::star::task;
      55                 :            : using namespace ::std;
      56                 :            : using namespace ::swf;
      57                 :            : 
      58                 :            : using com::sun::star::lang::XMultiServiceFactory;
      59                 :            : using com::sun::star::io::XOutputStream;
      60                 :            : using com::sun::star::beans::PropertyValue;
      61                 :            : using com::sun::star::container::XIndexAccess;
      62                 :            : using com::sun::star::beans::XPropertySet;
      63                 :            : using com::sun::star::lang::XComponent;
      64                 :            : using com::sun::star::lang::IllegalArgumentException;
      65                 :            : using com::sun::star::document::XExporter;
      66                 :            : using com::sun::star::document::XFilter;
      67                 :            : using com::sun::star::frame::XModel;
      68                 :            : using com::sun::star::lang::XServiceInfo;
      69                 :            : 
      70                 :            : // -----------------------------------------------------------------------------
      71                 :            : 
      72                 :          0 : PageInfo::PageInfo()
      73                 :            : :       meFadeEffect( FadeEffect_NONE ),
      74                 :            :         meFadeSpeed( AnimationSpeed_MEDIUM ),
      75                 :            :         mnDuration( 0 ),
      76                 :          0 :         mnChange( 0 )
      77                 :            : {
      78                 :          0 : }
      79                 :            : 
      80                 :            : // -----------------------------------------------------------------------------
      81                 :            : 
      82                 :          0 : PageInfo::~PageInfo()
      83                 :            : {
      84                 :          0 :     vector<ShapeInfo*>::iterator aIter( maShapesVector.begin() );
      85                 :          0 :     const vector<ShapeInfo*>::iterator aEnd( maShapesVector.end() );
      86                 :          0 :     while( aIter != aEnd )
      87                 :            :     {
      88                 :          0 :         delete (*aIter++);
      89                 :            :     }
      90                 :          0 : }
      91                 :            : 
      92                 :            : #ifdef THEFUTURE
      93                 :            : // -----------------------------------------------------------------------------
      94                 :            : 
      95                 :            : void PageInfo::addShape( ShapeInfo* pShapeInfo )
      96                 :            : {
      97                 :            :     maShapesVector.push_back( pShapeInfo );
      98                 :            : }
      99                 :            : #endif
     100                 :            : 
     101                 :            : // -----------------------------------------------------------------------------
     102                 :            : 
     103                 :          0 : FlashExporter::FlashExporter(const Reference< XMultiServiceFactory > &rxMSF, sal_Int32 nJPEGCompressMode, sal_Bool bExportOLEAsJPEG)
     104                 :            : :   mxMSF( rxMSF ),
     105                 :            :     mpWriter( NULL ),
     106                 :            :     mnJPEGcompressMode(nJPEGCompressMode),
     107                 :            :     mbExportOLEAsJPEG(bExportOLEAsJPEG),
     108                 :            :     mbPresentation(true),
     109                 :          0 :     mnPageNumber( - 1 )
     110                 :            : {
     111                 :          0 : }
     112                 :            : 
     113                 :            : // -----------------------------------------------------------------------------
     114                 :            : 
     115                 :          0 : FlashExporter::~FlashExporter()
     116                 :            : {
     117                 :          0 :     Flush();
     118                 :          0 : }
     119                 :            : 
     120                 :          0 : void FlashExporter::Flush()
     121                 :            : {
     122                 :          0 :     delete mpWriter;
     123                 :          0 :     mpWriter = NULL;
     124                 :            : 
     125                 :          0 :     maPagesMap.clear();
     126                 :          0 : }
     127                 :            : 
     128                 :            : // -----------------------------------------------------------------------------
     129                 :            : 
     130                 :            : const sal_uInt16 cBackgroundDepth = 2;
     131                 :            : const sal_uInt16 cBackgroundObjectsDepth = 3;
     132                 :            : const sal_uInt16 cPageObjectsDepth = 4;
     133                 :            : const sal_uInt16 cWaitButtonDepth = 10;
     134                 :            : 
     135                 :          0 : sal_Bool FlashExporter::exportAll( Reference< XComponent > xDoc, Reference< XOutputStream > &xOutputStream, Reference< XStatusIndicator> &xStatusIndicator )
     136                 :            : {
     137                 :          0 :     Reference< XServiceInfo > xDocServInfo( xDoc, UNO_QUERY );
     138                 :          0 :     if( xDocServInfo.is() )
     139                 :          0 :         mbPresentation = xDocServInfo->supportsService( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.PresentationDocument"))) ;
     140                 :            : 
     141                 :          0 :     Reference< XDrawPagesSupplier > xDrawPagesSupplier(xDoc, UNO_QUERY);
     142                 :          0 :     if(!xDrawPagesSupplier.is())
     143                 :          0 :         return sal_False;
     144                 :            : 
     145                 :          0 :     Reference< XIndexAccess > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY );
     146                 :          0 :     if(!xDrawPages.is())
     147                 :          0 :         return sal_False;
     148                 :            : 
     149                 :          0 :     Reference< XDrawPage > xDrawPage;
     150                 :          0 :     xDrawPages->getByIndex(0) >>= xDrawPage;
     151                 :            : 
     152                 :          0 :     Reference< XPropertySet > xProp( xDrawPage, UNO_QUERY );
     153                 :            :     try
     154                 :            :     {
     155                 :          0 :         xProp->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Width") ) ) >>= mnDocWidth;
     156                 :          0 :         xProp->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Height") ) ) >>= mnDocHeight;
     157                 :            : 
     158                 :          0 :         sal_Int32 nOutputWidth = 14400;
     159                 :          0 :         sal_Int32 nOutputHeight = (nOutputWidth * mnDocHeight ) / mnDocWidth;
     160                 :          0 :         delete mpWriter;
     161                 :          0 :         mpWriter = new Writer( nOutputWidth, nOutputHeight, mnDocWidth, mnDocHeight, mnJPEGcompressMode  );
     162                 :            :     }
     163                 :          0 :     catch( const Exception& )
     164                 :            :     {
     165                 :            :         OSL_ASSERT( false );
     166                 :          0 :         return false; // no writer, no cookies
     167                 :            :     }
     168                 :            : 
     169                 :          0 :     const sal_Int32 nPageCount = xDrawPages->getCount();
     170                 :            :     sal_uInt16 nPage;
     171                 :          0 :     if ( xStatusIndicator.is() )
     172                 :          0 :         xStatusIndicator->start(OUString( RTL_CONSTASCII_USTRINGPARAM( "Macromedia Flash (SWF)" )), nPageCount);
     173                 :          0 :     for( nPage = 0; nPage < nPageCount; nPage++)
     174                 :            :     {
     175                 :          0 :         mnPageNumber = nPage + 1;
     176                 :            : 
     177                 :          0 :         if ( xStatusIndicator.is() )
     178                 :          0 :             xStatusIndicator->setValue( nPage );
     179                 :          0 :         xDrawPages->getByIndex(nPage) >>= xDrawPage;
     180                 :            : 
     181                 :          0 :         if( !xDrawPage.is())
     182                 :          0 :             continue;
     183                 :            : 
     184                 :          0 :         Reference< XPropertySet > xPropSet( xDrawPage, UNO_QUERY );
     185                 :          0 :         if( mbPresentation )
     186                 :            :         {
     187                 :          0 :             sal_Bool bVisible = sal_False;
     188                 :          0 :             xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Visible") ) ) >>= bVisible;
     189                 :          0 :             if( !bVisible )
     190                 :          0 :                 continue;
     191                 :            :         }
     192                 :            : 
     193                 :          0 :         exportBackgrounds( xDrawPage, nPage, false );
     194                 :          0 :         exportBackgrounds( xDrawPage, nPage, true );
     195                 :            : 
     196                 :          0 :         maPagesMap[nPage].mnForegroundID = mpWriter->startSprite();
     197                 :          0 :         exportDrawPageContents( xDrawPage, false, false );
     198                 :          0 :         mpWriter->endSprite();
     199                 :            : 
     200                 :            :         // AS: If the background is different than the previous slide,
     201                 :            :         //  we have to remove the old one and place the new one.
     202                 :          0 :         if (nPage)
     203                 :            :         {
     204                 :          0 :             if (maPagesMap[nPage].mnBackgroundID != maPagesMap[nPage-1].mnBackgroundID)
     205                 :            :             {
     206                 :          0 :                 mpWriter->removeShape(cBackgroundDepth);
     207                 :          0 :                 mpWriter->placeShape( maPagesMap[nPage].mnBackgroundID, cBackgroundDepth, 0, 0 );
     208                 :            :             }
     209                 :            : 
     210                 :          0 :             if (maPagesMap[nPage].mnObjectsID != maPagesMap[nPage-1].mnObjectsID)
     211                 :            :             {
     212                 :          0 :                 mpWriter->removeShape(cBackgroundObjectsDepth);
     213                 :          0 :                 mpWriter->placeShape( maPagesMap[nPage].mnObjectsID, cBackgroundObjectsDepth, 0, 0 );
     214                 :            :             }
     215                 :            : 
     216                 :            :             // AS: Remove the Foreground of the previous slide.
     217                 :          0 :             mpWriter->removeShape(cPageObjectsDepth);
     218                 :            :         }
     219                 :            :         else
     220                 :            :         {
     221                 :          0 :             mpWriter->placeShape( maPagesMap[nPage].mnBackgroundID, cBackgroundDepth, 0, 0 );
     222                 :          0 :             mpWriter->placeShape( maPagesMap[nPage].mnObjectsID, cBackgroundObjectsDepth, 0, 0 );
     223                 :            :         }
     224                 :            : 
     225                 :          0 :         mpWriter->placeShape( maPagesMap[nPage].mnForegroundID, cPageObjectsDepth, 0, 0 );
     226                 :            : 
     227                 :          0 :         mpWriter->waitOnClick( cWaitButtonDepth );
     228                 :          0 :         mpWriter->showFrame();
     229                 :          0 :     }
     230                 :            : 
     231                 :          0 :     mpWriter->removeShape( cBackgroundDepth );
     232                 :          0 :     mpWriter->removeShape( cBackgroundObjectsDepth );
     233                 :          0 :     mpWriter->removeShape( cPageObjectsDepth );
     234                 :          0 :     mpWriter->gotoFrame( 0 );
     235                 :          0 :     mpWriter->showFrame();
     236                 :            : 
     237                 :          0 :     mpWriter->storeTo( xOutputStream );
     238                 :            : 
     239                 :          0 :     return sal_True;
     240                 :            : }
     241                 :            : 
     242                 :            : 
     243                 :          0 : sal_Bool FlashExporter::exportSlides( Reference< XDrawPage > xDrawPage, Reference< XOutputStream > &xOutputStream, sal_uInt16 /* nPage */ )
     244                 :            : {
     245                 :          0 :     Reference< XPropertySet > xPropSet( xDrawPage, UNO_QUERY );
     246                 :          0 :     if( !xDrawPage.is() || !xPropSet.is() )
     247                 :          0 :         return sal_False;
     248                 :            : 
     249                 :            :     try
     250                 :            :     {
     251                 :          0 :         if( NULL == mpWriter )
     252                 :            :         {
     253                 :          0 :             xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Width") ) ) >>= mnDocWidth;
     254                 :          0 :             xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Height") ) ) >>= mnDocHeight;
     255                 :            : 
     256                 :          0 :             mpWriter = new Writer( 14400, 10800, mnDocWidth, mnDocHeight, mnJPEGcompressMode );
     257                 :            :         }
     258                 :            : 
     259                 :          0 :         if( mbPresentation )
     260                 :            :         {
     261                 :          0 :             sal_Bool bVisible = sal_False;
     262                 :          0 :             xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Visible") ) ) >>= bVisible;
     263                 :          0 :             if( !bVisible )
     264                 :          0 :                 return sal_False;
     265                 :            :         }
     266                 :            :     }
     267                 :          0 :     catch( const Exception& )
     268                 :            :     {
     269                 :            :         OSL_ASSERT( false );
     270                 :            :     }
     271                 :            : 
     272                 :          0 :     exportDrawPageContents(xDrawPage, true, false);
     273                 :            : 
     274                 :          0 :     mpWriter->storeTo( xOutputStream );
     275                 :            : 
     276                 :          0 :     return sal_True;
     277                 :            : }
     278                 :            : 
     279                 :          0 : sal_uInt16 FlashExporter::exportBackgrounds( Reference< XDrawPage > xDrawPage, Reference< XOutputStream > &xOutputStream, sal_uInt16 nPage, sal_Bool bExportObjects )
     280                 :            : {
     281                 :          0 :     Reference< XPropertySet > xPropSet( xDrawPage, UNO_QUERY );
     282                 :          0 :     if( !xDrawPage.is() || !xPropSet.is() )
     283                 :          0 :         return sal_False;
     284                 :            : 
     285                 :          0 :     if( NULL == mpWriter )
     286                 :            :     {
     287                 :          0 :         xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Width") ) ) >>= mnDocWidth;
     288                 :          0 :         xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Height") ) ) >>= mnDocHeight;
     289                 :            : 
     290                 :          0 :         mpWriter = new Writer( 14400, 10800, mnDocWidth, mnDocHeight, mnJPEGcompressMode );
     291                 :            :     }
     292                 :            : 
     293                 :          0 :     sal_uInt16 ret = exportBackgrounds(xDrawPage, nPage, bExportObjects);
     294                 :            : 
     295                 :          0 :     if (ret != nPage)
     296                 :          0 :         return ret;
     297                 :            : 
     298                 :          0 :     if (bExportObjects)
     299                 :          0 :         mpWriter->placeShape( maPagesMap[nPage].mnObjectsID, _uInt16(1), 0, 0 );
     300                 :            :     else
     301                 :          0 :         mpWriter->placeShape( maPagesMap[nPage].mnBackgroundID, _uInt16(0), 0, 0 );
     302                 :            : 
     303                 :          0 :     mpWriter->storeTo( xOutputStream );
     304                 :            : 
     305                 :          0 :     return nPage;
     306                 :            : }
     307                 :            : 
     308                 :          0 : sal_uInt16 FlashExporter::exportBackgrounds( Reference< XDrawPage > xDrawPage, sal_uInt16 nPage, sal_Bool bExportObjects )
     309                 :            : {
     310                 :          0 :     Reference< XPropertySet > xPropSet( xDrawPage, UNO_QUERY );
     311                 :          0 :     if( !xDrawPage.is() || !xPropSet.is() )
     312                 :          0 :         return sal_False;
     313                 :            : 
     314                 :          0 :     sal_Bool bBackgroundVisible = true;
     315                 :          0 :     sal_Bool bBackgroundObjectsVisible = true;
     316                 :            : 
     317                 :          0 :     if( mbPresentation )
     318                 :            :     {
     319                 :          0 :         xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("IsBackgroundVisible") ) ) >>= bBackgroundVisible;
     320                 :          0 :         xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("IsBackgroundObjectsVisible") ) ) >>= bBackgroundObjectsVisible;
     321                 :            :     }
     322                 :            : 
     323                 :            : 
     324                 :          0 :     if (bExportObjects)
     325                 :            :     {
     326                 :          0 :         if (bBackgroundObjectsVisible)
     327                 :            :         {
     328                 :          0 :             Reference< XMasterPageTarget > xMasterPageTarget( xDrawPage, UNO_QUERY );
     329                 :          0 :             if( !xMasterPageTarget.is() )
     330                 :            :             {
     331                 :          0 :                 maPagesMap[nPage].mnObjectsID = 0xffff;
     332                 :          0 :                 return 0xffff;
     333                 :            :             }
     334                 :          0 :             Reference<XDrawPage> aTemp = xMasterPageTarget->getMasterPage();
     335                 :          0 :             sal_uInt16 ret = exportMasterPageObjects(nPage, aTemp);
     336                 :          0 :             if (ret != nPage)
     337                 :          0 :                 return ret;
     338                 :            :         }
     339                 :            :         else
     340                 :            :         {
     341                 :          0 :             maPagesMap[nPage].mnObjectsID = 0xffff;
     342                 :          0 :             return 0xffff;
     343                 :            :         }
     344                 :            :     }
     345                 :            :     else
     346                 :            :     {
     347                 :          0 :         if (bBackgroundVisible)
     348                 :            :         {
     349                 :          0 :             sal_uInt16 ret = exportDrawPageBackground(nPage, xDrawPage);
     350                 :            : 
     351                 :          0 :             if (ret != nPage)
     352                 :          0 :                 return ret;
     353                 :            :         }
     354                 :            :         else
     355                 :            :         {
     356                 :          0 :             maPagesMap[nPage].mnBackgroundID = 0xffff;
     357                 :          0 :             return 0xffff;
     358                 :            :         }
     359                 :            :     }
     360                 :            : 
     361                 :          0 :     return nPage;
     362                 :            : }
     363                 :            : 
     364                 :            : #ifdef AUGUSTUS
     365                 :            : sal_Bool FlashExporter::exportSound( Reference< XOutputStream > &xOutputStream, const char* wavfilename )
     366                 :            : {
     367                 :            :     try
     368                 :            :     {
     369                 :            :         delete mpWriter;
     370                 :            :         mpWriter = new Writer( 0, 0, 0, 0 );
     371                 :            :     }
     372                 :            :     catch( const Exception& )
     373                 :            :     {
     374                 :            :         OSL_ASSERT( false );
     375                 :            :     }
     376                 :            : 
     377                 :            :     if (!mpWriter->streamSound(wavfilename))
     378                 :            :         return sal_False;
     379                 :            :     else
     380                 :            :         mpWriter->storeTo( xOutputStream );
     381                 :            : 
     382                 :            :     return sal_True;
     383                 :            : }
     384                 :            : #endif // defined AUGUSTUS
     385                 :            : 
     386                 :            : // -----------------------------------------------------------------------------
     387                 :            : 
     388                 :            : sal_Int32 nPlaceDepth;
     389                 :            : // AS: A Slide can have a private background or use its masterpage's background.
     390                 :            : //  We use the checksums on the metafiles to tell if backgrounds are the same and
     391                 :            : //  should be reused.  The return value indicates which slide's background to use.
     392                 :            : //  If the return value != nPage, then there is no background (if == -1) or the
     393                 :            : //  background has already been exported.
     394                 :          0 : sal_uInt16 FlashExporter::exportDrawPageBackground(sal_uInt16 nPage, Reference< XDrawPage >& xPage)
     395                 :            : {
     396                 :            :     sal_uInt16 rBackgroundID;
     397                 :            : 
     398                 :          0 :     GDIMetaFile aMtfPrivate, aMtfMaster;
     399                 :          0 :     Reference< XComponent > xComponent( xPage, UNO_QUERY );
     400                 :            : 
     401                 :          0 :     Reference< XMasterPageTarget > xMasterPageTarget( xPage, UNO_QUERY );
     402                 :          0 :     if( !xMasterPageTarget.is() )
     403                 :          0 :         return 0xffff;
     404                 :            : 
     405                 :          0 :     Reference< XDrawPage > xMasterPage = xMasterPageTarget->getMasterPage();
     406                 :          0 :     if( !xMasterPage.is())
     407                 :          0 :         return 0xffff;
     408                 :            : 
     409                 :          0 :     Reference< XComponent > xCompMaster( xMasterPage, UNO_QUERY );
     410                 :            : 
     411                 :          0 :     getMetaFile( xCompMaster, aMtfMaster, true );
     412                 :          0 :     getMetaFile( xComponent, aMtfPrivate, true );
     413                 :            : 
     414                 :          0 :     sal_uInt32 masterchecksum = aMtfMaster.GetChecksum();
     415                 :          0 :     sal_uInt32 privatechecksum = aMtfPrivate.GetChecksum();
     416                 :            : 
     417                 :            :     // AS: If the slide has its own background
     418                 :          0 :     if (privatechecksum)
     419                 :            :     {
     420                 :          0 :         ChecksumCache::iterator it = gPrivateCache.find(privatechecksum);
     421                 :            : 
     422                 :            :         // AS: and we've previously encountered this background, just return
     423                 :            :         //  the previous index.
     424                 :          0 :         if (gPrivateCache.end() != it)
     425                 :            :         {
     426                 :          0 :             maPagesMap[nPage].mnBackgroundID =
     427                 :          0 :                 maPagesMap[it->second].mnBackgroundID;
     428                 :          0 :             return it->second;
     429                 :            :         }
     430                 :            :         else
     431                 :            :         {
     432                 :            :             // AS: Otherwise, cache this checksum.
     433                 :          0 :             gPrivateCache[privatechecksum] = nPage;
     434                 :            : 
     435                 :          0 :             rBackgroundID = mpWriter->defineShape( aMtfPrivate );
     436                 :            : 
     437                 :          0 :             maPagesMap[nPage].mnBackgroundID = rBackgroundID;
     438                 :          0 :             return nPage;
     439                 :            :         }
     440                 :            :     }
     441                 :            : 
     442                 :            :     // AS: Ok, no private background.  Use the master page's.
     443                 :            :     // AS: Have we already exported this master page?
     444                 :          0 :     ChecksumCache::iterator it = gMasterCache.find(masterchecksum);
     445                 :            : 
     446                 :          0 :     if (gMasterCache.end() != it)
     447                 :            :     {
     448                 :          0 :         maPagesMap[nPage].mnBackgroundID =
     449                 :          0 :             maPagesMap[it->second].mnBackgroundID;
     450                 :            : 
     451                 :          0 :         return it->second;                // AS: Yes, so don't export it again.
     452                 :            :     }
     453                 :            : 
     454                 :          0 :     gMasterCache[masterchecksum] = nPage;
     455                 :            : 
     456                 :          0 :     rBackgroundID = mpWriter->defineShape( aMtfMaster );
     457                 :            : 
     458                 :          0 :     maPagesMap[nPage].mnBackgroundID = rBackgroundID;
     459                 :            : 
     460                 :          0 :     return nPage;
     461                 :            : }
     462                 :            : 
     463                 :          0 : sal_uInt16 FlashExporter::exportMasterPageObjects(sal_uInt16 nPage, Reference< XDrawPage >& xMasterPage)
     464                 :            : {
     465                 :          0 :     Reference< XShapes > xShapes( xMasterPage, UNO_QUERY );
     466                 :            : 
     467                 :          0 :     sal_uInt32 shapesum = ActionSummer(xShapes);
     468                 :            : 
     469                 :          0 :     ChecksumCache::iterator it = gObjectCache.find(shapesum);
     470                 :            : 
     471                 :          0 :     if (gObjectCache.end() != it)
     472                 :            :     {
     473                 :          0 :         maPagesMap[nPage].mnObjectsID =
     474                 :          0 :             maPagesMap[it->second].mnObjectsID;
     475                 :            : 
     476                 :          0 :         return it->second;                // AS: Yes, so don't export it again.
     477                 :            :     }
     478                 :            : 
     479                 :          0 :     gObjectCache[shapesum] = nPage;
     480                 :            : 
     481                 :          0 :     sal_uInt16 rObjectsID = mpWriter->startSprite();
     482                 :          0 :     exportDrawPageContents( xMasterPage, false, true );
     483                 :          0 :     mpWriter->endSprite();
     484                 :            : 
     485                 :          0 :     maPagesMap[nPage].mnObjectsID = rObjectsID;
     486                 :            : 
     487                 :          0 :     return nPage;
     488                 :            : }
     489                 :            : 
     490                 :            : // -----------------------------------------------------------------------------
     491                 :            : 
     492                 :            : /** export's the definition of the shapes inside this drawing page and adds the
     493                 :            :     shape infos to the current PageInfo */
     494                 :          0 : void FlashExporter::exportDrawPageContents( Reference< XDrawPage >& xPage, bool bStream, bool bMaster )
     495                 :            : {
     496                 :          0 :     Reference< XShapes > xShapes( xPage, UNO_QUERY );
     497                 :          0 :     exportShapes(xShapes, bStream, bMaster);
     498                 :          0 : }
     499                 :            : 
     500                 :            : // -----------------------------------------------------------------------------
     501                 :            : 
     502                 :            : /** export's the definition of the shapes inside this XShapes container and adds the
     503                 :            :     shape infos to the current PageInfo */
     504                 :          0 : void FlashExporter::exportShapes( Reference< XShapes >& xShapes, bool bStream, bool bMaster )
     505                 :            : {
     506                 :            :     OSL_ENSURE( (xShapes->getCount() <= 0xffff), "overflow in FlashExporter::exportDrawPageContents()" );
     507                 :            : 
     508                 :          0 :     sal_uInt16 nShapeCount = (sal_uInt16)min( xShapes->getCount(), (sal_Int32)0xffff );
     509                 :            :     sal_uInt16 nShape;
     510                 :            : 
     511                 :          0 :     Reference< XShape > xShape;
     512                 :            : 
     513                 :          0 :     for( nShape = 0; nShape < nShapeCount; nShape++ )
     514                 :            :     {
     515                 :          0 :         xShapes->getByIndex( nShape ) >>= xShape;
     516                 :            : 
     517                 :          0 :         if( xShape.is() )
     518                 :            :         {
     519                 :          0 :             Reference< XShapes > xShapes2( xShape, UNO_QUERY );
     520                 :          0 :             if( xShapes2.is() && xShape->getShapeType() == "com.sun.star.drawing.GroupShape" )
     521                 :            :                 // export the contents of group shapes, but we only ever stream at the top
     522                 :            :                 // recursive level anyway, so pass false for streaming.
     523                 :          0 :                 exportShapes( xShapes2, false, bMaster);
     524                 :            :             else
     525                 :          0 :                 exportShape( xShape, bMaster);
     526                 :            :         }
     527                 :            : 
     528                 :          0 :         if (bStream)
     529                 :          0 :             mpWriter->showFrame();
     530                 :          0 :     }
     531                 :          0 : }
     532                 :            : 
     533                 :            : // -----------------------------------------------------------------------------
     534                 :            : 
     535                 :            : /** export this shape definition and adds it's info to the current PageInfo */
     536                 :          0 : void FlashExporter::exportShape( Reference< XShape >& xShape, bool bMaster )
     537                 :            : {
     538                 :          0 :     Reference< XPropertySet > xPropSet( xShape, UNO_QUERY );
     539                 :          0 :     if( !xPropSet.is() )
     540                 :            :         return;
     541                 :            : 
     542                 :          0 :     if( mbPresentation )
     543                 :            :     {
     544                 :            :         try
     545                 :            :         {
     546                 :            :             // skip empty presentation objects
     547                 :          0 :             sal_Bool bEmpty = sal_False;
     548                 :          0 :             xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") ) ) >>= bEmpty;
     549                 :          0 :             if( bEmpty )
     550                 :            :                 return;
     551                 :            : 
     552                 :            :             // don't export presentation placeholders on masterpage
     553                 :            :             // they can be non empty when user edits the default texts
     554                 :          0 :             if( bMaster )
     555                 :            :             {
     556                 :          0 :                 OUString aShapeType( xShape->getShapeType() );
     557                 :          0 :                 if( (0 == aShapeType.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.presentation.TitleTextShape" ))) ||
     558                 :          0 :                     (0 == aShapeType.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.presentation.OutlinerShape" ))) ||
     559                 :          0 :                     (0 == aShapeType.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.presentation.HeaderShape" ))) ||
     560                 :          0 :                     (0 == aShapeType.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.presentation.FooterShape" ))) ||
     561                 :          0 :                     (0 == aShapeType.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.presentation.SlideNumberShape" ))) ||
     562                 :          0 :                     (0 == aShapeType.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.presentation.DateTimeShape" ))))
     563                 :          0 :                     return;
     564                 :            :             }
     565                 :            :         }
     566                 :          0 :         catch( const Exception& )
     567                 :            :         {
     568                 :            :             // TODO: If we are exporting a draw, this property is not available
     569                 :            :         }
     570                 :            :     }
     571                 :            : 
     572                 :            :     try
     573                 :            :     {
     574                 :          0 :             com::sun::star::awt::Rectangle aBoundRect;
     575                 :          0 :             xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("BoundRect") ) ) >>= aBoundRect;
     576                 :            : 
     577                 :          0 :             ShapeInfo* pShapeInfo = new ShapeInfo();
     578                 :          0 :             pShapeInfo->mnX = aBoundRect.X;
     579                 :          0 :             pShapeInfo->mnY = aBoundRect.Y;
     580                 :          0 :             pShapeInfo->mnWidth = aBoundRect.Width;
     581                 :          0 :             pShapeInfo->mnHeight = aBoundRect.Height;
     582                 :            : 
     583                 :          0 :             if( mbPresentation )
     584                 :            :             {
     585                 :          0 :                 xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Bookmark") ) ) >>= pShapeInfo->maBookmark;
     586                 :          0 :                 xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("DimColor") ) ) >>= pShapeInfo->mnDimColor;
     587                 :          0 :                 xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("DimHide") ) ) >>= pShapeInfo->mbDimHide;
     588                 :          0 :                 xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("DimPrevious") ) ) >>= pShapeInfo->mbDimPrev;
     589                 :          0 :                 xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Effect") ) ) >>= pShapeInfo->meEffect;
     590                 :          0 :                 xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("PlayFull") ) ) >>= pShapeInfo->mbPlayFull;
     591                 :          0 :                 xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("PresentationOrder") ) ) >>= pShapeInfo->mnPresOrder;
     592                 :          0 :                 xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Sound") ) ) >>= pShapeInfo->maSoundURL;
     593                 :          0 :                 xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("SoundOn") ) ) >>= pShapeInfo->mbSoundOn;
     594                 :          0 :                 xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Speed") ) ) >>= pShapeInfo->meEffectSpeed;
     595                 :          0 :                 xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("TextEffect") ) ) >>= pShapeInfo->meTextEffect;
     596                 :          0 :                 xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("TransparentColor") ) ) >>= pShapeInfo->mnBlueScreenColor;
     597                 :            :             }
     598                 :            : 
     599                 :            : //          long ZOrder;
     600                 :            : //          xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("ZOrder") ) ) >>= ZOrder;
     601                 :            : 
     602                 :          0 :             GDIMetaFile     aMtf;
     603                 :          0 :             Reference< XComponent > xComponent( xShape, UNO_QUERY );
     604                 :            : 
     605                 :          0 :             bool bIsOleObject = xShape->getShapeType() == "com.sun.star.presentation.OLE2Shape" || xShape->getShapeType() == "com.sun.star.drawing.OLE2Shape";
     606                 :            : 
     607                 :          0 :             getMetaFile( xComponent, aMtf );
     608                 :            : 
     609                 :            :             // AS: If it's an OLE object, then export a JPEG if the user requested.
     610                 :            :             //  In this case, we use the bounding rect info generated in the first getMetaFile
     611                 :            :             //  call, and then clear the metafile and add a BMP action.  This may be turned into
     612                 :            :             //  a JPEG, depending on what gives the best compression.
     613                 :          0 :             if (bIsOleObject && mbExportOLEAsJPEG)
     614                 :          0 :                 getMetaFile( xComponent, aMtf, false, true );
     615                 :            : 
     616                 :            :             sal_uInt16 nID;
     617                 :          0 :             sal_uInt32 checksum = aMtf.GetChecksum();
     618                 :            : 
     619                 :          0 :             ChecksumCache::iterator it = gMetafileCache.find(checksum);
     620                 :            : 
     621                 :          0 :             if (gMetafileCache.end() != it)
     622                 :          0 :                 nID = it->second;
     623                 :            :             else
     624                 :            :             {
     625                 :          0 :                 nID = mpWriter->defineShape( aMtf );
     626                 :          0 :                 gMetafileCache[checksum] = nID;
     627                 :            :             }
     628                 :            : 
     629                 :          0 :             if (!nID)
     630                 :            :                 return;
     631                 :            : 
     632                 :          0 :             pShapeInfo->mnID = nID;
     633                 :            : 
     634                 :            : //          pPageInfo->addShape( pShapeInfo );
     635                 :            : 
     636                 :          0 :             mpWriter->placeShape( pShapeInfo->mnID, _uInt16(nPlaceDepth++), pShapeInfo->mnX, pShapeInfo->mnY );
     637                 :            : 
     638                 :          0 :             delete pShapeInfo;
     639                 :            :     }
     640                 :          0 :     catch( const Exception& )
     641                 :            :     {
     642                 :            :         OSL_ASSERT(false);
     643                 :          0 :     }
     644                 :            : }
     645                 :            : 
     646                 :            : // -----------------------------------------------------------------------------
     647                 :            : 
     648                 :          0 : bool FlashExporter::getMetaFile( Reference< XComponent >&xComponent, GDIMetaFile& rMtf, bool bOnlyBackground /* = false */, bool bExportAsJPEG /* = false */)
     649                 :            : {
     650                 :          0 :     if( !mxGraphicExporter.is() )
     651                 :          0 :         mxGraphicExporter = Reference< XExporter >::query( mxMSF->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.GraphicExportFilter") ) ) );
     652                 :            : 
     653                 :          0 :     Reference< XFilter > xFilter( mxGraphicExporter, UNO_QUERY );
     654                 :            : 
     655                 :          0 :     utl::TempFile aFile;
     656                 :          0 :     aFile.EnableKillingFile();
     657                 :            : 
     658                 :          0 :     Sequence< PropertyValue > aFilterData(bExportAsJPEG ? 3 : 2);
     659                 :          0 :     aFilterData[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("Version") );
     660                 :          0 :     aFilterData[0].Value <<= (sal_Int32)6000;
     661                 :          0 :     aFilterData[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("PageNumber") );
     662                 :          0 :     aFilterData[1].Value <<= mnPageNumber;
     663                 :            : 
     664                 :          0 :     if(bExportAsJPEG)
     665                 :            :     {
     666                 :          0 :         aFilterData[2].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("Translucent") );
     667                 :          0 :         aFilterData[2].Value <<= (sal_Bool)sal_True;
     668                 :            :     }
     669                 :            : 
     670                 :          0 :     Sequence< PropertyValue > aDescriptor( bOnlyBackground ? 4 : 3 );
     671                 :          0 :     aDescriptor[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("FilterName") );
     672                 :            : 
     673                 :            :     // AS: If we've been asked to export as an image, then use the BMP filter.
     674                 :            :     //  Otherwise, use SVM.  This is useful for things that don't convert well as
     675                 :            :     //  metafiles, like the occasional OLE object.
     676                 :          0 :     aDescriptor[0].Value <<= OUString( RTL_CONSTASCII_USTRINGPARAM(bExportAsJPEG ? "PNG" : "SVM") );
     677                 :            : 
     678                 :          0 :     aDescriptor[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("URL") );
     679                 :          0 :     aDescriptor[1].Value <<= OUString( aFile.GetURL() );
     680                 :          0 :     aDescriptor[2].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("FilterData") );
     681                 :          0 :     aDescriptor[2].Value <<= aFilterData;
     682                 :          0 :     if( bOnlyBackground )
     683                 :            :     {
     684                 :          0 :         aDescriptor[3].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("ExportOnlyBackground") );
     685                 :          0 :         aDescriptor[3].Value <<= (sal_Bool)bOnlyBackground;
     686                 :            :     }
     687                 :          0 :     mxGraphicExporter->setSourceDocument( xComponent );
     688                 :          0 :     xFilter->filter( aDescriptor );
     689                 :            : 
     690                 :          0 :     if (bExportAsJPEG)
     691                 :            :     {
     692                 :          0 :         Graphic aGraphic;
     693                 :          0 :         GraphicFilter aFilter(false);
     694                 :            : 
     695                 :          0 :         aFilter.ImportGraphic( aGraphic, String(aFile.GetURL()), *aFile.GetStream( STREAM_READ ) );
     696                 :          0 :         BitmapEx rBitmapEx( aGraphic.GetBitmap(), Color(255,255,255) );
     697                 :            : 
     698                 :          0 :         Rectangle clipRect;
     699                 :          0 :         for( size_t i = 0, nCount = rMtf.GetActionSize(); i < nCount; i++ )
     700                 :            :         {
     701                 :          0 :             const MetaAction*   pAction = rMtf.GetAction( i );
     702                 :          0 :             const sal_uInt16    nType = pAction->GetType();
     703                 :            : 
     704                 :          0 :             switch( nType )
     705                 :            :             {
     706                 :            :                 case( META_ISECTRECTCLIPREGION_ACTION ):
     707                 :            :                 {
     708                 :          0 :                     const MetaISectRectClipRegionAction* pA = (const MetaISectRectClipRegionAction*) pAction;
     709                 :          0 :                     clipRect = pA->GetRect();
     710                 :          0 :                     i = nCount;
     711                 :          0 :                     break;
     712                 :            :                 }
     713                 :            :             }
     714                 :            :         }
     715                 :          0 :         MetaBmpExScaleAction *pmetaAct = new MetaBmpExScaleAction(Point(clipRect.Left(), clipRect.Top()), Size(clipRect.GetWidth(), clipRect.GetHeight()), rBitmapEx);
     716                 :            : 
     717                 :          0 :         rMtf.Clear();
     718                 :          0 :         rMtf.AddAction(pmetaAct);
     719                 :            : 
     720                 :            :     }
     721                 :            :     else
     722                 :          0 :         rMtf.Read( *aFile.GetStream( STREAM_READ ) );
     723                 :            : 
     724                 :          0 :     return rMtf.GetActionSize() != 0;
     725                 :            : }
     726                 :            : 
     727                 :          0 : sal_uInt32 FlashExporter::ActionSummer(Reference< XShape >& xShape)
     728                 :            : {
     729                 :          0 :     Reference< XShapes > xShapes( xShape, UNO_QUERY );
     730                 :            : 
     731                 :          0 :     if( xShapes.is() )
     732                 :            :     {
     733                 :          0 :         return ActionSummer(xShapes);
     734                 :            :     }
     735                 :            :     else
     736                 :            :     {
     737                 :          0 :         Reference< XComponent > xComponentShape( xShape, UNO_QUERY );
     738                 :            : 
     739                 :          0 :         GDIMetaFile aMtf;
     740                 :          0 :         getMetaFile( xComponentShape, aMtf);
     741                 :            : 
     742                 :          0 :         return aMtf.GetChecksum();
     743                 :          0 :     }
     744                 :            : }
     745                 :            : 
     746                 :          0 : sal_uInt32 FlashExporter::ActionSummer(Reference< XShapes >& xShapes)
     747                 :            : {
     748                 :          0 :     sal_uInt32 nShapeCount = xShapes->getCount();
     749                 :          0 :     sal_uInt32 shapecount = 0;
     750                 :            : 
     751                 :          0 :     Reference< XShape > xShape2;
     752                 :            : 
     753                 :          0 :     for( sal_uInt16 nShape = 0; nShape < nShapeCount; nShape++ )
     754                 :            :     {
     755                 :          0 :         xShapes->getByIndex( nShape ) >>= xShape2;
     756                 :            : 
     757                 :          0 :         shapecount += ActionSummer(xShape2);
     758                 :            :     }
     759                 :            : 
     760                 :          0 :     return shapecount;
     761                 :            : }
     762                 :            : 
     763                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10