bump product version to 4.1.6.2
[LibreOffice.git] / filter / source / flash / swfexporter.cxx
blob8bc51b69b6dca0fc18e06fbd42129d85ef735124
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/awt/Rectangle.hpp>
21 #include <com/sun/star/beans/PropertyValue.hpp>
22 #include <com/sun/star/drawing/GraphicExportFilter.hpp>
23 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
24 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
25 #include <com/sun/star/container/XIndexAccess.hpp>
26 #include <com/sun/star/document/XFilter.hpp>
27 #include <com/sun/star/document/XExporter.hpp>
28 #include <com/sun/star/frame/XModel.hpp>
29 #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
30 #include <com/sun/star/lang/XServiceInfo.hpp>
31 #include <vcl/gdimtf.hxx>
32 #include <unotools/tempfile.hxx>
33 #include <osl/diagnose.h>
34 #include <osl/file.hxx>
35 #include <vcl/metaact.hxx>
36 #include <vcl/wmf.hxx>
37 #include <vcl/graphicfilter.hxx>
39 #include "swfexporter.hxx"
40 #include "swfwriter.hxx"
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::drawing;
44 using namespace ::com::sun::star::presentation;
45 using namespace ::com::sun::star::task;
46 using namespace ::std;
47 using namespace ::swf;
49 using com::sun::star::io::XOutputStream;
50 using com::sun::star::beans::PropertyValue;
51 using com::sun::star::container::XIndexAccess;
52 using com::sun::star::beans::XPropertySet;
53 using com::sun::star::lang::XComponent;
54 using com::sun::star::lang::IllegalArgumentException;
55 using com::sun::star::document::XExporter;
56 using com::sun::star::document::XFilter;
57 using com::sun::star::frame::XModel;
58 using com::sun::star::lang::XServiceInfo;
60 // -----------------------------------------------------------------------------
62 PageInfo::PageInfo()
63 : meFadeEffect( FadeEffect_NONE ),
64 meFadeSpeed( AnimationSpeed_MEDIUM ),
65 mnDuration( 0 ),
66 mnChange( 0 )
70 // -----------------------------------------------------------------------------
72 PageInfo::~PageInfo()
74 vector<ShapeInfo*>::iterator aIter( maShapesVector.begin() );
75 const vector<ShapeInfo*>::iterator aEnd( maShapesVector.end() );
76 while( aIter != aEnd )
78 delete (*aIter++);
82 #ifdef THEFUTURE
83 // -----------------------------------------------------------------------------
85 void PageInfo::addShape( ShapeInfo* pShapeInfo )
87 maShapesVector.push_back( pShapeInfo );
89 #endif
91 // -----------------------------------------------------------------------------
93 FlashExporter::FlashExporter(const Reference< XComponentContext > &rxContext, sal_Int32 nJPEGCompressMode, sal_Bool bExportOLEAsJPEG)
94 : mxContext( rxContext ),
95 mpWriter( NULL ),
96 mnJPEGcompressMode(nJPEGCompressMode),
97 mbExportOLEAsJPEG(bExportOLEAsJPEG),
98 mbPresentation(true),
99 mnPageNumber( - 1 )
103 // -----------------------------------------------------------------------------
105 FlashExporter::~FlashExporter()
107 Flush();
110 void FlashExporter::Flush()
112 delete mpWriter;
113 mpWriter = NULL;
115 maPagesMap.clear();
118 // -----------------------------------------------------------------------------
120 const sal_uInt16 cBackgroundDepth = 2;
121 const sal_uInt16 cBackgroundObjectsDepth = 3;
122 const sal_uInt16 cPageObjectsDepth = 4;
123 const sal_uInt16 cWaitButtonDepth = 10;
125 sal_Bool FlashExporter::exportAll( Reference< XComponent > xDoc, Reference< XOutputStream > &xOutputStream, Reference< XStatusIndicator> &xStatusIndicator )
127 Reference< XServiceInfo > xDocServInfo( xDoc, UNO_QUERY );
128 if( xDocServInfo.is() )
129 mbPresentation = xDocServInfo->supportsService( "com.sun.star.presentation.PresentationDocument" );
131 Reference< XDrawPagesSupplier > xDrawPagesSupplier(xDoc, UNO_QUERY);
132 if(!xDrawPagesSupplier.is())
133 return sal_False;
135 Reference< XIndexAccess > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY );
136 if(!xDrawPages.is())
137 return sal_False;
139 Reference< XDrawPage > xDrawPage;
140 xDrawPages->getByIndex(0) >>= xDrawPage;
142 Reference< XPropertySet > xProp( xDrawPage, UNO_QUERY );
145 xProp->getPropertyValue( "Width" ) >>= mnDocWidth;
146 xProp->getPropertyValue( "Height" ) >>= mnDocHeight;
148 sal_Int32 nOutputWidth = 14400;
149 sal_Int32 nOutputHeight = (nOutputWidth * mnDocHeight ) / mnDocWidth;
150 delete mpWriter;
151 mpWriter = new Writer( nOutputWidth, nOutputHeight, mnDocWidth, mnDocHeight, mnJPEGcompressMode );
153 catch( const Exception& )
155 OSL_ASSERT( false );
156 return false; // no writer, no cookies
159 const sal_Int32 nPageCount = xDrawPages->getCount();
160 sal_uInt16 nPage;
161 if ( xStatusIndicator.is() )
162 xStatusIndicator->start( "Macromedia Flash (SWF)", nPageCount);
163 for( nPage = 0; nPage < nPageCount; nPage++)
165 mnPageNumber = nPage + 1;
167 if ( xStatusIndicator.is() )
168 xStatusIndicator->setValue( nPage );
169 xDrawPages->getByIndex(nPage) >>= xDrawPage;
171 if( !xDrawPage.is())
172 continue;
174 Reference< XPropertySet > xPropSet( xDrawPage, UNO_QUERY );
175 if( mbPresentation )
177 sal_Bool bVisible = sal_False;
178 xPropSet->getPropertyValue( "Visible" ) >>= bVisible;
179 if( !bVisible )
180 continue;
183 exportBackgrounds( xDrawPage, nPage, false );
184 exportBackgrounds( xDrawPage, nPage, true );
186 maPagesMap[nPage].mnForegroundID = mpWriter->startSprite();
187 exportDrawPageContents( xDrawPage, false, false );
188 mpWriter->endSprite();
190 // AS: If the background is different than the previous slide,
191 // we have to remove the old one and place the new one.
192 if (nPage)
194 if (maPagesMap[nPage].mnBackgroundID != maPagesMap[nPage-1].mnBackgroundID)
196 mpWriter->removeShape(cBackgroundDepth);
197 mpWriter->placeShape( maPagesMap[nPage].mnBackgroundID, cBackgroundDepth, 0, 0 );
200 if (maPagesMap[nPage].mnObjectsID != maPagesMap[nPage-1].mnObjectsID)
202 mpWriter->removeShape(cBackgroundObjectsDepth);
203 mpWriter->placeShape( maPagesMap[nPage].mnObjectsID, cBackgroundObjectsDepth, 0, 0 );
206 // AS: Remove the Foreground of the previous slide.
207 mpWriter->removeShape(cPageObjectsDepth);
209 else
211 mpWriter->placeShape( maPagesMap[nPage].mnBackgroundID, cBackgroundDepth, 0, 0 );
212 mpWriter->placeShape( maPagesMap[nPage].mnObjectsID, cBackgroundObjectsDepth, 0, 0 );
215 mpWriter->placeShape( maPagesMap[nPage].mnForegroundID, cPageObjectsDepth, 0, 0 );
217 mpWriter->waitOnClick( cWaitButtonDepth );
218 mpWriter->showFrame();
221 mpWriter->removeShape( cBackgroundDepth );
222 mpWriter->removeShape( cBackgroundObjectsDepth );
223 mpWriter->removeShape( cPageObjectsDepth );
224 mpWriter->gotoFrame( 0 );
225 mpWriter->showFrame();
227 mpWriter->storeTo( xOutputStream );
229 return sal_True;
233 sal_Bool FlashExporter::exportSlides( Reference< XDrawPage > xDrawPage, Reference< XOutputStream > &xOutputStream, sal_uInt16 /* nPage */ )
235 Reference< XPropertySet > xPropSet( xDrawPage, UNO_QUERY );
236 if( !xDrawPage.is() || !xPropSet.is() )
237 return sal_False;
241 if( NULL == mpWriter )
243 xPropSet->getPropertyValue( "Width" ) >>= mnDocWidth;
244 xPropSet->getPropertyValue( "Height" ) >>= mnDocHeight;
246 mpWriter = new Writer( 14400, 10800, mnDocWidth, mnDocHeight, mnJPEGcompressMode );
249 if( mbPresentation )
251 sal_Bool bVisible = sal_False;
252 xPropSet->getPropertyValue( "Visible" ) >>= bVisible;
253 if( !bVisible )
254 return sal_False;
257 catch( const Exception& )
259 OSL_ASSERT( false );
262 exportDrawPageContents(xDrawPage, true, false);
264 mpWriter->storeTo( xOutputStream );
266 return sal_True;
269 sal_uInt16 FlashExporter::exportBackgrounds( Reference< XDrawPage > xDrawPage, Reference< XOutputStream > &xOutputStream, sal_uInt16 nPage, sal_Bool bExportObjects )
271 Reference< XPropertySet > xPropSet( xDrawPage, UNO_QUERY );
272 if( !xDrawPage.is() || !xPropSet.is() )
273 return sal_False;
275 if( NULL == mpWriter )
277 xPropSet->getPropertyValue( "Width" ) >>= mnDocWidth;
278 xPropSet->getPropertyValue( "Height" ) >>= mnDocHeight;
280 mpWriter = new Writer( 14400, 10800, mnDocWidth, mnDocHeight, mnJPEGcompressMode );
283 sal_uInt16 ret = exportBackgrounds(xDrawPage, nPage, bExportObjects);
285 if (ret != nPage)
286 return ret;
288 if (bExportObjects)
289 mpWriter->placeShape( maPagesMap[nPage].mnObjectsID, _uInt16(1), 0, 0 );
290 else
291 mpWriter->placeShape( maPagesMap[nPage].mnBackgroundID, _uInt16(0), 0, 0 );
293 mpWriter->storeTo( xOutputStream );
295 return nPage;
298 sal_uInt16 FlashExporter::exportBackgrounds( Reference< XDrawPage > xDrawPage, sal_uInt16 nPage, sal_Bool bExportObjects )
300 Reference< XPropertySet > xPropSet( xDrawPage, UNO_QUERY );
301 if( !xDrawPage.is() || !xPropSet.is() )
302 return sal_False;
304 sal_Bool bBackgroundVisible = true;
305 sal_Bool bBackgroundObjectsVisible = true;
307 if( mbPresentation )
309 xPropSet->getPropertyValue( "IsBackgroundVisible" ) >>= bBackgroundVisible;
310 xPropSet->getPropertyValue( "IsBackgroundObjectsVisible" ) >>= bBackgroundObjectsVisible;
314 if (bExportObjects)
316 if (bBackgroundObjectsVisible)
318 Reference< XMasterPageTarget > xMasterPageTarget( xDrawPage, UNO_QUERY );
319 if( !xMasterPageTarget.is() )
321 maPagesMap[nPage].mnObjectsID = 0xffff;
322 return 0xffff;
324 Reference<XDrawPage> aTemp = xMasterPageTarget->getMasterPage();
325 sal_uInt16 ret = exportMasterPageObjects(nPage, aTemp);
326 if (ret != nPage)
327 return ret;
329 else
331 maPagesMap[nPage].mnObjectsID = 0xffff;
332 return 0xffff;
335 else
337 if (bBackgroundVisible)
339 sal_uInt16 ret = exportDrawPageBackground(nPage, xDrawPage);
341 if (ret != nPage)
342 return ret;
344 else
346 maPagesMap[nPage].mnBackgroundID = 0xffff;
347 return 0xffff;
351 return nPage;
354 #ifdef AUGUSTUS
355 sal_Bool FlashExporter::exportSound( Reference< XOutputStream > &xOutputStream, const char* wavfilename )
359 delete mpWriter;
360 mpWriter = new Writer( 0, 0, 0, 0 );
362 catch( const Exception& )
364 OSL_ASSERT( false );
367 if (!mpWriter->streamSound(wavfilename))
368 return sal_False;
369 else
370 mpWriter->storeTo( xOutputStream );
372 return sal_True;
374 #endif // defined AUGUSTUS
376 // -----------------------------------------------------------------------------
378 sal_Int32 nPlaceDepth;
379 // AS: A Slide can have a private background or use its masterpage's background.
380 // We use the checksums on the metafiles to tell if backgrounds are the same and
381 // should be reused. The return value indicates which slide's background to use.
382 // If the return value != nPage, then there is no background (if == -1) or the
383 // background has already been exported.
384 sal_uInt16 FlashExporter::exportDrawPageBackground(sal_uInt16 nPage, Reference< XDrawPage >& xPage)
386 sal_uInt16 rBackgroundID;
388 GDIMetaFile aMtfPrivate, aMtfMaster;
389 Reference< XComponent > xComponent( xPage, UNO_QUERY );
391 Reference< XMasterPageTarget > xMasterPageTarget( xPage, UNO_QUERY );
392 if( !xMasterPageTarget.is() )
393 return 0xffff;
395 Reference< XDrawPage > xMasterPage = xMasterPageTarget->getMasterPage();
396 if( !xMasterPage.is())
397 return 0xffff;
399 Reference< XComponent > xCompMaster( xMasterPage, UNO_QUERY );
401 getMetaFile( xCompMaster, aMtfMaster, true );
402 getMetaFile( xComponent, aMtfPrivate, true );
404 sal_uInt32 masterchecksum = aMtfMaster.GetChecksum();
405 sal_uInt32 privatechecksum = aMtfPrivate.GetChecksum();
407 // AS: If the slide has its own background
408 if (privatechecksum)
410 ChecksumCache::iterator it = gPrivateCache.find(privatechecksum);
412 // AS: and we've previously encountered this background, just return
413 // the previous index.
414 if (gPrivateCache.end() != it)
416 maPagesMap[nPage].mnBackgroundID =
417 maPagesMap[it->second].mnBackgroundID;
418 return it->second;
420 else
422 // AS: Otherwise, cache this checksum.
423 gPrivateCache[privatechecksum] = nPage;
425 rBackgroundID = mpWriter->defineShape( aMtfPrivate );
427 maPagesMap[nPage].mnBackgroundID = rBackgroundID;
428 return nPage;
432 // AS: Ok, no private background. Use the master page's.
433 // AS: Have we already exported this master page?
434 ChecksumCache::iterator it = gMasterCache.find(masterchecksum);
436 if (gMasterCache.end() != it)
438 maPagesMap[nPage].mnBackgroundID =
439 maPagesMap[it->second].mnBackgroundID;
441 return it->second; // AS: Yes, so don't export it again.
444 gMasterCache[masterchecksum] = nPage;
446 rBackgroundID = mpWriter->defineShape( aMtfMaster );
448 maPagesMap[nPage].mnBackgroundID = rBackgroundID;
450 return nPage;
453 sal_uInt16 FlashExporter::exportMasterPageObjects(sal_uInt16 nPage, Reference< XDrawPage >& xMasterPage)
455 Reference< XShapes > xShapes( xMasterPage, UNO_QUERY );
457 sal_uInt32 shapesum = ActionSummer(xShapes);
459 ChecksumCache::iterator it = gObjectCache.find(shapesum);
461 if (gObjectCache.end() != it)
463 maPagesMap[nPage].mnObjectsID =
464 maPagesMap[it->second].mnObjectsID;
466 return it->second; // AS: Yes, so don't export it again.
469 gObjectCache[shapesum] = nPage;
471 sal_uInt16 rObjectsID = mpWriter->startSprite();
472 exportDrawPageContents( xMasterPage, false, true );
473 mpWriter->endSprite();
475 maPagesMap[nPage].mnObjectsID = rObjectsID;
477 return nPage;
480 // -----------------------------------------------------------------------------
482 /** export's the definition of the shapes inside this drawing page and adds the
483 shape infos to the current PageInfo */
484 void FlashExporter::exportDrawPageContents( Reference< XDrawPage >& xPage, bool bStream, bool bMaster )
486 Reference< XShapes > xShapes( xPage, UNO_QUERY );
487 exportShapes(xShapes, bStream, bMaster);
490 // -----------------------------------------------------------------------------
492 /** export's the definition of the shapes inside this XShapes container and adds the
493 shape infos to the current PageInfo */
494 void FlashExporter::exportShapes( Reference< XShapes >& xShapes, bool bStream, bool bMaster )
496 OSL_ENSURE( (xShapes->getCount() <= 0xffff), "overflow in FlashExporter::exportDrawPageContents()" );
498 sal_uInt16 nShapeCount = (sal_uInt16)min( xShapes->getCount(), (sal_Int32)0xffff );
499 sal_uInt16 nShape;
501 Reference< XShape > xShape;
503 for( nShape = 0; nShape < nShapeCount; nShape++ )
505 xShapes->getByIndex( nShape ) >>= xShape;
507 if( xShape.is() )
509 Reference< XShapes > xShapes2( xShape, UNO_QUERY );
510 if( xShapes2.is() && xShape->getShapeType() == "com.sun.star.drawing.GroupShape" )
511 // export the contents of group shapes, but we only ever stream at the top
512 // recursive level anyway, so pass false for streaming.
513 exportShapes( xShapes2, false, bMaster);
514 else
515 exportShape( xShape, bMaster);
518 if (bStream)
519 mpWriter->showFrame();
523 // -----------------------------------------------------------------------------
525 /** export this shape definition and adds it's info to the current PageInfo */
526 void FlashExporter::exportShape( Reference< XShape >& xShape, bool bMaster )
528 Reference< XPropertySet > xPropSet( xShape, UNO_QUERY );
529 if( !xPropSet.is() )
530 return;
532 if( mbPresentation )
536 // skip empty presentation objects
537 sal_Bool bEmpty = sal_False;
538 xPropSet->getPropertyValue( "IsEmptyPresentationObject" ) >>= bEmpty;
539 if( bEmpty )
540 return;
542 // don't export presentation placeholders on masterpage
543 // they can be non empty when user edits the default texts
544 if( bMaster )
546 OUString aShapeType( xShape->getShapeType() );
547 if( (0 == aShapeType.reverseCompareTo( "com.sun.star.presentation.TitleTextShape" )) ||
548 (0 == aShapeType.reverseCompareTo( "com.sun.star.presentation.OutlinerShape" )) ||
549 (0 == aShapeType.reverseCompareTo( "com.sun.star.presentation.HeaderShape" )) ||
550 (0 == aShapeType.reverseCompareTo( "com.sun.star.presentation.FooterShape" )) ||
551 (0 == aShapeType.reverseCompareTo( "com.sun.star.presentation.SlideNumberShape" )) ||
552 (0 == aShapeType.reverseCompareTo( "com.sun.star.presentation.DateTimeShape" )))
553 return;
556 catch( const Exception& )
558 // TODO: If we are exporting a draw, this property is not available
564 com::sun::star::awt::Rectangle aBoundRect;
565 xPropSet->getPropertyValue( "BoundRect" ) >>= aBoundRect;
567 ShapeInfo* pShapeInfo = new ShapeInfo();
568 pShapeInfo->mnX = aBoundRect.X;
569 pShapeInfo->mnY = aBoundRect.Y;
570 pShapeInfo->mnWidth = aBoundRect.Width;
571 pShapeInfo->mnHeight = aBoundRect.Height;
573 if( mbPresentation )
575 xPropSet->getPropertyValue( "Bookmark" ) >>= pShapeInfo->maBookmark;
576 xPropSet->getPropertyValue( "DimColor" ) >>= pShapeInfo->mnDimColor;
577 xPropSet->getPropertyValue( "DimHide" ) >>= pShapeInfo->mbDimHide;
578 xPropSet->getPropertyValue( "DimPrevious" ) >>= pShapeInfo->mbDimPrev;
579 xPropSet->getPropertyValue( "Effect" ) >>= pShapeInfo->meEffect;
580 xPropSet->getPropertyValue( "PlayFull" ) >>= pShapeInfo->mbPlayFull;
581 xPropSet->getPropertyValue( "PresentationOrder" ) >>= pShapeInfo->mnPresOrder;
582 xPropSet->getPropertyValue( "Sound" ) >>= pShapeInfo->maSoundURL;
583 xPropSet->getPropertyValue( "SoundOn" ) >>= pShapeInfo->mbSoundOn;
584 xPropSet->getPropertyValue( "Speed" ) >>= pShapeInfo->meEffectSpeed;
585 xPropSet->getPropertyValue( "TextEffect" ) >>= pShapeInfo->meTextEffect;
586 xPropSet->getPropertyValue( "TransparentColor" ) >>= pShapeInfo->mnBlueScreenColor;
589 GDIMetaFile aMtf;
590 Reference< XComponent > xComponent( xShape, UNO_QUERY );
592 bool bIsOleObject = xShape->getShapeType() == "com.sun.star.presentation.OLE2Shape" || xShape->getShapeType() == "com.sun.star.drawing.OLE2Shape";
594 getMetaFile( xComponent, aMtf );
596 // AS: If it's an OLE object, then export a JPEG if the user requested.
597 // In this case, we use the bounding rect info generated in the first getMetaFile
598 // call, and then clear the metafile and add a BMP action. This may be turned into
599 // a JPEG, depending on what gives the best compression.
600 if (bIsOleObject && mbExportOLEAsJPEG)
601 getMetaFile( xComponent, aMtf, false, true );
603 sal_uInt16 nID;
604 sal_uInt32 checksum = aMtf.GetChecksum();
606 ChecksumCache::iterator it = gMetafileCache.find(checksum);
608 if (gMetafileCache.end() != it)
609 nID = it->second;
610 else
612 nID = mpWriter->defineShape( aMtf );
613 gMetafileCache[checksum] = nID;
616 if (!nID)
618 delete pShapeInfo;
619 return;
622 pShapeInfo->mnID = nID;
624 // pPageInfo->addShape( pShapeInfo );
626 mpWriter->placeShape( pShapeInfo->mnID, _uInt16(nPlaceDepth++), pShapeInfo->mnX, pShapeInfo->mnY );
628 delete pShapeInfo;
630 catch( const Exception& )
632 OSL_ASSERT(false);
636 // -----------------------------------------------------------------------------
638 bool FlashExporter::getMetaFile( Reference< XComponent >&xComponent, GDIMetaFile& rMtf, bool bOnlyBackground /* = false */, bool bExportAsJPEG /* = false */)
640 if( !mxGraphicExporter.is() )
641 mxGraphicExporter = GraphicExportFilter::create( mxContext );
643 utl::TempFile aFile;
644 aFile.EnableKillingFile();
646 Sequence< PropertyValue > aFilterData(bExportAsJPEG ? 3 : 2);
647 aFilterData[0].Name = "Version";
648 aFilterData[0].Value <<= (sal_Int32)6000;
649 aFilterData[1].Name = "PageNumber";
650 aFilterData[1].Value <<= mnPageNumber;
652 if(bExportAsJPEG)
654 aFilterData[2].Name = "Translucent";
655 aFilterData[2].Value <<= (sal_Bool)sal_True;
658 Sequence< PropertyValue > aDescriptor( bOnlyBackground ? 4 : 3 );
659 aDescriptor[0].Name = "FilterName";
661 // AS: If we've been asked to export as an image, then use the BMP filter.
662 // Otherwise, use SVM. This is useful for things that don't convert well as
663 // metafiles, like the occasional OLE object.
664 aDescriptor[0].Value <<= bExportAsJPEG ? OUString("PNG") : OUString("SVM");
666 aDescriptor[1].Name = "URL";
667 aDescriptor[1].Value <<= OUString(aFile.GetURL());
668 aDescriptor[2].Name = "FilterData";
669 aDescriptor[2].Value <<= aFilterData;
670 if( bOnlyBackground )
672 aDescriptor[3].Name = "ExportOnlyBackground";
673 aDescriptor[3].Value <<= (sal_Bool)bOnlyBackground;
675 mxGraphicExporter->setSourceDocument( xComponent );
676 mxGraphicExporter->filter( aDescriptor );
678 if (bExportAsJPEG)
680 Graphic aGraphic;
681 GraphicFilter aFilter(false);
683 aFilter.ImportGraphic( aGraphic, String(aFile.GetURL()), *aFile.GetStream( STREAM_READ ) );
684 BitmapEx rBitmapEx( aGraphic.GetBitmap(), Color(255,255,255) );
686 Rectangle clipRect;
687 for( size_t i = 0, nCount = rMtf.GetActionSize(); i < nCount; i++ )
689 const MetaAction* pAction = rMtf.GetAction( i );
690 const sal_uInt16 nType = pAction->GetType();
692 switch( nType )
694 case( META_ISECTRECTCLIPREGION_ACTION ):
696 const MetaISectRectClipRegionAction* pA = (const MetaISectRectClipRegionAction*) pAction;
697 clipRect = pA->GetRect();
698 i = nCount;
699 break;
703 MetaBmpExScaleAction *pmetaAct = new MetaBmpExScaleAction(Point(clipRect.Left(), clipRect.Top()), Size(clipRect.GetWidth(), clipRect.GetHeight()), rBitmapEx);
705 rMtf.Clear();
706 rMtf.AddAction(pmetaAct);
709 else
710 rMtf.Read( *aFile.GetStream( STREAM_READ ) );
712 return rMtf.GetActionSize() != 0;
715 sal_uInt32 FlashExporter::ActionSummer(Reference< XShape >& xShape)
717 Reference< XShapes > xShapes( xShape, UNO_QUERY );
719 if( xShapes.is() )
721 return ActionSummer(xShapes);
723 else
725 Reference< XComponent > xComponentShape( xShape, UNO_QUERY );
727 GDIMetaFile aMtf;
728 getMetaFile( xComponentShape, aMtf);
730 return aMtf.GetChecksum();
734 sal_uInt32 FlashExporter::ActionSummer(Reference< XShapes >& xShapes)
736 sal_uInt32 nShapeCount = xShapes->getCount();
737 sal_uInt32 shapecount = 0;
739 Reference< XShape > xShape2;
741 for( sal_uInt16 nShape = 0; nShape < nShapeCount; nShape++ )
743 xShapes->getByIndex( nShape ) >>= xShape2;
745 shapecount += ActionSummer(xShape2);
748 return shapecount;
751 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */