1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: swfexporter.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_filter.hxx"
33 #include <com/sun/star/awt/Rectangle.hpp>
34 #include <com/sun/star/beans/PropertyValue.hpp>
35 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
36 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
37 #include <com/sun/star/container/XIndexAccess.hpp>
38 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
39 #include <com/sun/star/document/XFilter.hpp>
40 #include <com/sun/star/document/XExporter.hpp>
41 #include <com/sun/star/frame/XModel.hpp>
42 #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
43 #include <com/sun/star/lang/XServiceInfo.hpp>
44 #include <vcl/gdimtf.hxx>
45 #include <unotools/tempfile.hxx>
46 #include <osl/diagnose.h>
47 #include <osl/file.hxx>
48 #include <vcl/metaact.hxx>
49 #include <svtools/wmf.hxx>
50 #include <svtools/filter.hxx>
52 #include "swfexporter.hxx"
53 #include "swfwriter.hxx"
56 using namespace ::com::sun::star::uno
;
57 using namespace ::com::sun::star::drawing
;
58 using namespace ::com::sun::star::presentation
;
59 using namespace ::com::sun::star::task
;
60 using namespace ::std
;
61 using namespace ::swf
;
63 using com::sun::star::lang::XMultiServiceFactory
;
64 using com::sun::star::io::XOutputStream
;
65 using com::sun::star::beans::PropertyValue
;
66 using com::sun::star::container::XIndexAccess
;
67 using com::sun::star::beans::XPropertySet
;
68 using com::sun::star::lang::XComponent
;
69 using com::sun::star::lang::IllegalArgumentException
;
70 using com::sun::star::document::XExporter
;
71 using com::sun::star::document::XFilter
;
72 using com::sun::star::frame::XModel
;
73 using com::sun::star::lang::XServiceInfo
;
75 // -----------------------------------------------------------------------------
78 : meFadeEffect( FadeEffect_NONE
),
79 meFadeSpeed( AnimationSpeed_MEDIUM
),
85 // -----------------------------------------------------------------------------
89 vector
<ShapeInfo
*>::iterator
aIter( maShapesVector
.begin() );
90 const vector
<ShapeInfo
*>::iterator
aEnd( maShapesVector
.end() );
91 while( aIter
!= aEnd
)
97 // -----------------------------------------------------------------------------
99 void PageInfo::addShape( ShapeInfo
* pShapeInfo
)
101 maShapesVector
.push_back( pShapeInfo
);
105 // -----------------------------------------------------------------------------
107 FlashExporter::FlashExporter(const Reference
< XMultiServiceFactory
> &rxMSF
, sal_Int32 nJPEGCompressMode
, sal_Bool bExportOLEAsJPEG
)
110 mnJPEGcompressMode(nJPEGCompressMode
),
111 mbExportOLEAsJPEG(bExportOLEAsJPEG
),
112 mbPresentation(true),
117 // -----------------------------------------------------------------------------
119 FlashExporter::~FlashExporter()
124 void FlashExporter::Flush()
132 // -----------------------------------------------------------------------------
134 const sal_uInt16 cBackgroundDepth
= 2;
135 const sal_uInt16 cBackgroundObjectsDepth
= 3;
136 const sal_uInt16 cPageObjectsDepth
= 4;
137 const sal_uInt16 cWaitButtonDepth
= 10;
139 sal_Bool
FlashExporter::exportAll( Reference
< XComponent
> xDoc
, Reference
< XOutputStream
> &xOutputStream
, Reference
< XStatusIndicator
> &xStatusIndicator
)
141 Reference
< XServiceInfo
> xDocServInfo( xDoc
, UNO_QUERY
);
142 if( xDocServInfo
.is() )
143 mbPresentation
= xDocServInfo
->supportsService( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.PresentationDocument"))) ;
145 Reference
< XDrawPagesSupplier
> xDrawPagesSupplier(xDoc
, UNO_QUERY
);
146 if(!xDrawPagesSupplier
.is())
149 Reference
< XIndexAccess
> xDrawPages( xDrawPagesSupplier
->getDrawPages(), UNO_QUERY
);
153 Reference
< XDrawPage
> xDrawPage
;
154 xDrawPages
->getByIndex(0) >>= xDrawPage
;
156 Reference
< XPropertySet
> xProp( xDrawPage
, UNO_QUERY
);
159 xProp
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Width") ) ) >>= mnDocWidth
;
160 xProp
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Height") ) ) >>= mnDocHeight
;
162 sal_Int32 nOutputWidth
= 14400;
163 sal_Int32 nOutputHeight
= (nOutputWidth
* mnDocHeight
) / mnDocWidth
;
165 mpWriter
= new Writer( nOutputWidth
, nOutputHeight
, mnDocWidth
, mnDocHeight
, mnJPEGcompressMode
);
170 return false; // no writer, no cookies
173 const sal_Int32 nPageCount
= xDrawPages
->getCount();
175 if ( xStatusIndicator
.is() )
176 xStatusIndicator
->start(OUString( RTL_CONSTASCII_USTRINGPARAM( "Macromedia Flash (SWF)" )), nPageCount
);
177 for( nPage
= 0; nPage
< nPageCount
; nPage
++)
179 mnPageNumber
= nPage
+ 1;
181 if ( xStatusIndicator
.is() )
182 xStatusIndicator
->setValue( nPage
);
183 xDrawPages
->getByIndex(nPage
) >>= xDrawPage
;
188 Reference
< XPropertySet
> xPropSet( xDrawPage
, UNO_QUERY
);
191 sal_Bool bVisible
= sal_False
;
192 xPropSet
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Visible") ) ) >>= bVisible
;
197 exportBackgrounds( xDrawPage
, nPage
, false );
198 exportBackgrounds( xDrawPage
, nPage
, true );
200 maPagesMap
[nPage
].mnForegroundID
= mpWriter
->startSprite();
201 exportDrawPageContents( xDrawPage
, false, false );
202 mpWriter
->endSprite();
204 // AS: If the background is different than the previous slide,
205 // we have to remove the old one and place the new one.
208 if (maPagesMap
[nPage
].mnBackgroundID
!= maPagesMap
[nPage
-1].mnBackgroundID
)
210 mpWriter
->removeShape(cBackgroundDepth
);
211 mpWriter
->placeShape( maPagesMap
[nPage
].mnBackgroundID
, cBackgroundDepth
, 0, 0 );
214 if (maPagesMap
[nPage
].mnObjectsID
!= maPagesMap
[nPage
-1].mnObjectsID
)
216 mpWriter
->removeShape(cBackgroundObjectsDepth
);
217 mpWriter
->placeShape( maPagesMap
[nPage
].mnObjectsID
, cBackgroundObjectsDepth
, 0, 0 );
220 // AS: Remove the Foreground of the previous slide.
221 mpWriter
->removeShape(cPageObjectsDepth
);
225 mpWriter
->placeShape( maPagesMap
[nPage
].mnBackgroundID
, cBackgroundDepth
, 0, 0 );
226 mpWriter
->placeShape( maPagesMap
[nPage
].mnObjectsID
, cBackgroundObjectsDepth
, 0, 0 );
229 mpWriter
->placeShape( maPagesMap
[nPage
].mnForegroundID
, cPageObjectsDepth
, 0, 0 );
231 mpWriter
->waitOnClick( cWaitButtonDepth
);
232 mpWriter
->showFrame();
235 mpWriter
->removeShape( cBackgroundDepth
);
236 mpWriter
->removeShape( cBackgroundObjectsDepth
);
237 mpWriter
->removeShape( cPageObjectsDepth
);
238 mpWriter
->gotoFrame( 0 );
239 mpWriter
->showFrame();
241 mpWriter
->storeTo( xOutputStream
);
247 sal_Bool
FlashExporter::exportSlides( Reference
< XDrawPage
> xDrawPage
, Reference
< XOutputStream
> &xOutputStream
, sal_uInt16
/* nPage */ )
249 Reference
< XPropertySet
> xPropSet( xDrawPage
, UNO_QUERY
);
250 if( !xDrawPage
.is() || !xPropSet
.is() )
255 if( NULL
== mpWriter
)
257 xPropSet
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Width") ) ) >>= mnDocWidth
;
258 xPropSet
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Height") ) ) >>= mnDocHeight
;
260 mpWriter
= new Writer( 14400, 10800, mnDocWidth
, mnDocHeight
, mnJPEGcompressMode
);
265 sal_Bool bVisible
= sal_False
;
266 xPropSet
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Visible") ) ) >>= bVisible
;
276 exportDrawPageContents(xDrawPage
, true, false);
278 mpWriter
->storeTo( xOutputStream
);
283 sal_uInt16
FlashExporter::exportBackgrounds( Reference
< XDrawPage
> xDrawPage
, Reference
< XOutputStream
> &xOutputStream
, sal_uInt16 nPage
, sal_Bool bExportObjects
)
285 Reference
< XPropertySet
> xPropSet( xDrawPage
, UNO_QUERY
);
286 if( !xDrawPage
.is() || !xPropSet
.is() )
289 if( NULL
== mpWriter
)
291 xPropSet
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Width") ) ) >>= mnDocWidth
;
292 xPropSet
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Height") ) ) >>= mnDocHeight
;
294 mpWriter
= new Writer( 14400, 10800, mnDocWidth
, mnDocHeight
, mnJPEGcompressMode
);
297 sal_uInt16 ret
= exportBackgrounds(xDrawPage
, nPage
, bExportObjects
);
303 mpWriter
->placeShape( maPagesMap
[nPage
].mnObjectsID
, _uInt16(1), 0, 0 );
305 mpWriter
->placeShape( maPagesMap
[nPage
].mnBackgroundID
, _uInt16(0), 0, 0 );
307 mpWriter
->storeTo( xOutputStream
);
312 sal_uInt16
FlashExporter::exportBackgrounds( Reference
< XDrawPage
> xDrawPage
, sal_uInt16 nPage
, sal_Bool bExportObjects
)
314 Reference
< XPropertySet
> xPropSet( xDrawPage
, UNO_QUERY
);
315 if( !xDrawPage
.is() || !xPropSet
.is() )
318 sal_Bool bBackgroundVisible
= true;
319 sal_Bool bBackgroundObjectsVisible
= true;
323 xPropSet
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("IsBackgroundVisible") ) ) >>= bBackgroundVisible
;
324 xPropSet
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("IsBackgroundObjectsVisible") ) ) >>= bBackgroundObjectsVisible
;
330 if (bBackgroundObjectsVisible
)
332 Reference
< XMasterPageTarget
> xMasterPageTarget( xDrawPage
, UNO_QUERY
);
333 if( !xMasterPageTarget
.is() )
335 maPagesMap
[nPage
].mnObjectsID
= 0xffff;
338 Reference
<XDrawPage
> aTemp
= xMasterPageTarget
->getMasterPage();
339 sal_uInt16 ret
= exportMasterPageObjects(nPage
, aTemp
);
345 maPagesMap
[nPage
].mnObjectsID
= 0xffff;
351 if (bBackgroundVisible
)
353 sal_uInt16 ret
= exportDrawPageBackground(nPage
, xDrawPage
);
360 maPagesMap
[nPage
].mnBackgroundID
= 0xffff;
369 sal_Bool
FlashExporter::exportSound( Reference
< XOutputStream
> &xOutputStream
, const char* wavfilename
)
374 mpWriter
= new Writer( 0, 0, 0, 0 );
381 if (!mpWriter
->streamSound(wavfilename
))
384 mpWriter
->storeTo( xOutputStream
);
388 #endif // defined AUGUSTUS
390 // -----------------------------------------------------------------------------
392 sal_Int32 nPlaceDepth
;
393 // AS: A Slide can have a private background or use its masterpage's background.
394 // We use the checksums on the metafiles to tell if backgrounds are the same and
395 // should be reused. The return value indicates which slide's background to use.
396 // If the return value != nPage, then there is no background (if == -1) or the
397 // background has already been exported.
398 sal_uInt16
FlashExporter::exportDrawPageBackground(sal_uInt16 nPage
, Reference
< XDrawPage
>& xPage
)
400 sal_uInt16 rBackgroundID
;
402 GDIMetaFile aMtfPrivate
, aMtfMaster
;
403 Reference
< XComponent
> xComponent( xPage
, UNO_QUERY
);
405 Reference
< XMasterPageTarget
> xMasterPageTarget( xPage
, UNO_QUERY
);
406 if( !xMasterPageTarget
.is() )
409 Reference
< XDrawPage
> xMasterPage
= xMasterPageTarget
->getMasterPage();
410 if( !xMasterPage
.is())
413 Reference
< XComponent
> xCompMaster( xMasterPage
, UNO_QUERY
);
415 getMetaFile( xCompMaster
, aMtfMaster
, true );
416 getMetaFile( xComponent
, aMtfPrivate
, true );
418 sal_uInt32 masterchecksum
= aMtfMaster
.GetChecksum();
419 sal_uInt32 privatechecksum
= aMtfPrivate
.GetChecksum();
421 // AS: If the slide has its own background
424 ChecksumCache::iterator it
= gPrivateCache
.find(privatechecksum
);
426 // AS: and we've previously encountered this background, just return
427 // the previous index.
428 if (gPrivateCache
.end() != it
)
430 maPagesMap
[nPage
].mnBackgroundID
=
431 maPagesMap
[it
->second
].mnBackgroundID
;
436 // AS: Otherwise, cache this checksum.
437 gPrivateCache
[privatechecksum
] = nPage
;
439 rBackgroundID
= mpWriter
->defineShape( aMtfPrivate
);
441 maPagesMap
[nPage
].mnBackgroundID
= rBackgroundID
;
446 // AS: Ok, no private background. Use the master page's.
447 // AS: Have we already exported this master page?
448 ChecksumCache::iterator it
= gMasterCache
.find(masterchecksum
);
450 if (gMasterCache
.end() != it
)
452 maPagesMap
[nPage
].mnBackgroundID
=
453 maPagesMap
[it
->second
].mnBackgroundID
;
455 return it
->second
; // AS: Yes, so don't export it again.
458 gMasterCache
[masterchecksum
] = nPage
;
460 rBackgroundID
= mpWriter
->defineShape( aMtfMaster
);
462 maPagesMap
[nPage
].mnBackgroundID
= rBackgroundID
;
467 sal_uInt16
FlashExporter::exportMasterPageObjects(sal_uInt16 nPage
, Reference
< XDrawPage
>& xMasterPage
)
469 Reference
< XShapes
> xShapes( xMasterPage
, UNO_QUERY
);
471 sal_uInt32 shapesum
= ActionSummer(xShapes
);
473 ChecksumCache::iterator it
= gObjectCache
.find(shapesum
);
475 if (gObjectCache
.end() != it
)
477 maPagesMap
[nPage
].mnObjectsID
=
478 maPagesMap
[it
->second
].mnObjectsID
;
480 return it
->second
; // AS: Yes, so don't export it again.
483 gObjectCache
[shapesum
] = nPage
;
485 sal_uInt16 rObjectsID
= mpWriter
->startSprite();
486 exportDrawPageContents( xMasterPage
, false, true );
487 mpWriter
->endSprite();
489 maPagesMap
[nPage
].mnObjectsID
= rObjectsID
;
494 // -----------------------------------------------------------------------------
496 /** export's the definition of the shapes inside this drawing page and adds the
497 shape infos to the current PageInfo */
498 void FlashExporter::exportDrawPageContents( Reference
< XDrawPage
>& xPage
, bool bStream
, bool bMaster
)
500 Reference
< XShapes
> xShapes( xPage
, UNO_QUERY
);
501 exportShapes(xShapes
, bStream
, bMaster
);
504 // -----------------------------------------------------------------------------
506 /** export's the definition of the shapes inside this XShapes container and adds the
507 shape infos to the current PageInfo */
508 void FlashExporter::exportShapes( Reference
< XShapes
>& xShapes
, bool bStream
, bool bMaster
)
510 OSL_ENSURE( (xShapes
->getCount() <= 0xffff), "overflow in FlashExporter::exportDrawPageContents()" );
512 sal_uInt16 nShapeCount
= (sal_uInt16
)min( xShapes
->getCount(), (sal_Int32
)0xffff );
515 Reference
< XShape
> xShape
;
517 for( nShape
= 0; nShape
< nShapeCount
; nShape
++ )
519 xShapes
->getByIndex( nShape
) >>= xShape
;
523 Reference
< XShapes
> xShapes2( xShape
, UNO_QUERY
);
524 if( xShapes2
.is() && xShape
->getShapeType().equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.GroupShape")))
525 // export the contents of group shapes, but we only ever stream at the top
526 // recursive level anyway, so pass false for streaming.
527 exportShapes( xShapes2
, false, bMaster
);
529 exportShape( xShape
, bMaster
);
533 mpWriter
->showFrame();
537 // -----------------------------------------------------------------------------
539 /** export this shape definition and adds it's info to the current PageInfo */
540 void FlashExporter::exportShape( Reference
< XShape
>& xShape
, bool bMaster
)
542 Reference
< XPropertySet
> xPropSet( xShape
, UNO_QUERY
);
550 // skip empty presentation objects
551 sal_Bool bEmpty
= sal_False
;
552 xPropSet
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") ) ) >>= bEmpty
;
556 // don't export presentation placeholders on masterpage
557 // they can be non empty when user edits the default texts
560 OUString
aShapeType( xShape
->getShapeType() );
561 if( (0 == aShapeType
.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.presentation.TitleTextShape" ))) ||
562 (0 == aShapeType
.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.presentation.OutlinerShape" ))) ||
563 (0 == aShapeType
.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.presentation.HeaderShape" ))) ||
564 (0 == aShapeType
.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.presentation.FooterShape" ))) ||
565 (0 == aShapeType
.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.presentation.SlideNumberShape" ))) ||
566 (0 == aShapeType
.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.presentation.DateTimeShape" ))))
572 // TODO: If we are exporting a draw, this property is not available
578 com::sun::star::awt::Point
aPosition( xShape
->getPosition() );
579 com::sun::star::awt::Size
aSize( xShape
->getSize() );
581 com::sun::star::awt::Rectangle aBoundRect
;//(aPosition.X, aPosition.Y, aSize.Width, aSize.Height);
582 xPropSet
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("BoundRect") ) ) >>= aBoundRect
;
584 ShapeInfo
* pShapeInfo
= new ShapeInfo();
585 pShapeInfo
->mnX
= aBoundRect
.X
;
586 pShapeInfo
->mnY
= aBoundRect
.Y
;
587 pShapeInfo
->mnWidth
= aBoundRect
.Width
;
588 pShapeInfo
->mnHeight
= aBoundRect
.Height
;
592 xPropSet
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Bookmark") ) ) >>= pShapeInfo
->maBookmark
;
593 xPropSet
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("DimColor") ) ) >>= pShapeInfo
->mnDimColor
;
594 xPropSet
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("DimHide") ) ) >>= pShapeInfo
->mbDimHide
;
595 xPropSet
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("DimPrevious") ) ) >>= pShapeInfo
->mbDimPrev
;
596 xPropSet
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Effect") ) ) >>= pShapeInfo
->meEffect
;
597 xPropSet
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("PlayFull") ) ) >>= pShapeInfo
->mbPlayFull
;
598 xPropSet
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("PresentationOrder") ) ) >>= pShapeInfo
->mnPresOrder
;
599 xPropSet
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Sound") ) ) >>= pShapeInfo
->maSoundURL
;
600 xPropSet
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("SoundOn") ) ) >>= pShapeInfo
->mbSoundOn
;
601 xPropSet
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Speed") ) ) >>= pShapeInfo
->meEffectSpeed
;
602 xPropSet
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("TextEffect") ) ) >>= pShapeInfo
->meTextEffect
;
603 xPropSet
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("TransparentColor") ) ) >>= pShapeInfo
->mnBlueScreenColor
;
607 // xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("ZOrder") ) ) >>= ZOrder;
610 Reference
< XComponent
> xComponent( xShape
, UNO_QUERY
);
612 bool bIsOleObject
= xShape
->getShapeType().equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.presentation.OLE2Shape"))
613 || xShape
->getShapeType().equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.OLE2Shape"));
615 getMetaFile( xComponent
, aMtf
);
617 // AS: If it's an OLE object, then export a JPEG if the user requested.
618 // In this case, we use the bounding rect info generated in the first getMetaFile
619 // call, and then clear the metafile and add a BMP action. This may be turned into
620 // a JPEG, depending on what gives the best compression.
621 if (bIsOleObject
&& mbExportOLEAsJPEG
)
622 getMetaFile( xComponent
, aMtf
, false, true );
625 sal_uInt32 checksum
= aMtf
.GetChecksum();
627 ChecksumCache::iterator it
= gMetafileCache
.find(checksum
);
629 if (gMetafileCache
.end() != it
)
633 nID
= mpWriter
->defineShape( aMtf
);
634 gMetafileCache
[checksum
] = nID
;
640 pShapeInfo
->mnID
= nID
;
642 // pPageInfo->addShape( pShapeInfo );
644 mpWriter
->placeShape( pShapeInfo
->mnID
, _uInt16(nPlaceDepth
++), pShapeInfo
->mnX
, pShapeInfo
->mnY
);
654 // -----------------------------------------------------------------------------
656 bool FlashExporter::getMetaFile( Reference
< XComponent
>&xComponent
, GDIMetaFile
& rMtf
, bool bOnlyBackground
/* = false */, bool bExportAsJPEG
/* = false */)
658 if( !mxGraphicExporter
.is() )
659 mxGraphicExporter
= Reference
< XExporter
>::query( mxMSF
->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.GraphicExportFilter") ) ) );
661 Reference
< XFilter
> xFilter( mxGraphicExporter
, UNO_QUERY
);
664 aFile
.EnableKillingFile();
666 Sequence
< PropertyValue
> aFilterData(bExportAsJPEG
? 3 : 2);
667 aFilterData
[0].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM("Version") );
668 aFilterData
[0].Value
<<= (sal_Int32
)6000;
669 aFilterData
[1].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM("PageNumber") );
670 aFilterData
[1].Value
<<= mnPageNumber
;
674 aFilterData
[2].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM("Translucent") );
675 aFilterData
[2].Value
<<= (sal_Bool
)sal_True
;
678 Sequence
< PropertyValue
> aDescriptor( bOnlyBackground
? 4 : 3 );
679 aDescriptor
[0].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM("FilterName") );
681 // AS: If we've been asked to export as an image, then use the BMP filter.
682 // Otherwise, use SVM. This is useful for things that don't convert well as
683 // metafiles, like the occasional OLE object.
684 aDescriptor
[0].Value
<<= OUString( RTL_CONSTASCII_USTRINGPARAM(bExportAsJPEG
? "PNG" : "SVM") );
686 aDescriptor
[1].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM("URL") );
687 aDescriptor
[1].Value
<<= OUString( aFile
.GetURL() );
688 aDescriptor
[2].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM("FilterData") );
689 aDescriptor
[2].Value
<<= aFilterData
;
690 if( bOnlyBackground
)
692 aDescriptor
[3].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM("ExportOnlyBackground") );
693 aDescriptor
[3].Value
<<= (sal_Bool
)bOnlyBackground
;
695 mxGraphicExporter
->setSourceDocument( xComponent
);
696 xFilter
->filter( aDescriptor
);
701 GraphicFilter
aFilter(false);
703 aFilter
.ImportGraphic( aGraphic
, String(aFile
.GetURL()), *aFile
.GetStream( STREAM_READ
) );
704 BitmapEx
rBitmapEx( aGraphic
.GetBitmap(), Color(255,255,255) );
707 for( ULONG i
= 0, nCount
= rMtf
.GetActionCount(); i
< nCount
; i
++ )
709 const MetaAction
* pAction
= rMtf
.GetAction( i
);
710 const USHORT nType
= pAction
->GetType();
714 case( META_ISECTRECTCLIPREGION_ACTION
):
716 const MetaISectRectClipRegionAction
* pA
= (const MetaISectRectClipRegionAction
*) pAction
;
717 clipRect
= pA
->GetRect();
723 MetaBmpExScaleAction
*pmetaAct
= new MetaBmpExScaleAction(Point(clipRect
.Left(), clipRect
.Top()), Size(clipRect
.GetWidth(), clipRect
.GetHeight()), rBitmapEx
);
726 rMtf
.AddAction(pmetaAct
);
730 rMtf
.Read( *aFile
.GetStream( STREAM_READ
) );
732 int icount
= rMtf
.GetActionCount();
736 sal_uInt32
FlashExporter::ActionSummer(Reference
< XShape
>& xShape
)
738 Reference
< XShapes
> xShapes( xShape
, UNO_QUERY
);
742 return ActionSummer(xShapes
);
746 Reference
< XComponent
> xComponentShape( xShape
, UNO_QUERY
);
749 getMetaFile( xComponentShape
, aMtf
);
751 return aMtf
.GetChecksum();
755 sal_uInt32
FlashExporter::ActionSummer(Reference
< XShapes
>& xShapes
)
757 sal_uInt32 nShapeCount
= xShapes
->getCount();
758 sal_uInt32 shapecount
= 0;
760 Reference
< XShape
> xShape2
;
762 for( sal_uInt16 nShape
= 0; nShape
< nShapeCount
; nShape
++ )
764 xShapes
->getByIndex( nShape
) >>= xShape2
;
766 shapecount
+= ActionSummer(xShape2
);