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