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