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