impoptimizer.cxx (880c69c6) impoptimizer.cxx (597a4c59)
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

--- 16 unchanged lines hidden (view full) ---

25#include "precompiled_sdext.hxx"
26
27#include "impoptimizer.hxx"
28#include "pppoptimizer.hxx"
29#include "graphiccollector.hxx"
30#include "pagecollector.hxx"
31#include "informationdialog.hxx"
32
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

--- 16 unchanged lines hidden (view full) ---

25#include "precompiled_sdext.hxx"
26
27#include "impoptimizer.hxx"
28#include "pppoptimizer.hxx"
29#include "graphiccollector.hxx"
30#include "pagecollector.hxx"
31#include "informationdialog.hxx"
32
33#include <unotools/localfilehelper.hxx>
34#include <unotools/processfactory.hxx>
33#include "minimizer.hrc"
34
35#include <vector>
36#include "com/sun/star/util/URL.hpp"
37#include "com/sun/star/util/XURLTransformer.hpp"
38#include <com/sun/star/beans/XPropertySet.hpp>
39#include <com/sun/star/awt/Rectangle.hpp>
40#include <com/sun/star/awt/Size.hpp>
41#include <com/sun/star/util/MeasureUnit.hpp>
42#include <com/sun/star/frame/XModel.hpp>
43#include <com/sun/star/frame/XDesktop.hpp>
44#include <com/sun/star/awt/XWindow.hpp>
45#include <com/sun/star/frame/XStorable.hpp>
35#include <vector>
36#include "com/sun/star/util/URL.hpp"
37#include "com/sun/star/util/XURLTransformer.hpp"
38#include <com/sun/star/beans/XPropertySet.hpp>
39#include <com/sun/star/awt/Rectangle.hpp>
40#include <com/sun/star/awt/Size.hpp>
41#include <com/sun/star/util/MeasureUnit.hpp>
42#include <com/sun/star/frame/XModel.hpp>
43#include <com/sun/star/frame/XDesktop.hpp>
44#include <com/sun/star/awt/XWindow.hpp>
45#include <com/sun/star/frame/XStorable.hpp>
46#ifndef _COM_SUN_STAR_FRAME_FrameSearchFlag_HPP_
47#include <com/sun/star/frame/FrameSearchFlag.hpp>
46#include <com/sun/star/frame/FrameSearchFlag.hpp>
48#endif
49#include <com/sun/star/frame/XDispatchProvider.hpp>
50#include <com/sun/star/graphic/XGraphicProvider.hpp>
47#include <com/sun/star/frame/XDispatchProvider.hpp>
48#include <com/sun/star/graphic/XGraphicProvider.hpp>
51#include <unotools/configmgr.hxx>
52#include <com/sun/star/lang/XServiceInfo.hpp>
53#include <com/sun/star/container/XNamed.hpp>
54#include <com/sun/star/drawing/XShapes.hpp>
55#include <com/sun/star/drawing/XMasterPageTarget.hpp>
56#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
57#include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
58#include <com/sun/star/presentation/XPresentationSupplier.hpp>
59#include <com/sun/star/container/XNameAccess.hpp>
60#include <com/sun/star/presentation/XPresentation.hpp>
61#include <com/sun/star/presentation/XPresentationPage.hpp>
62#include <com/sun/star/document/XFilter.hpp>
63#include <com/sun/star/document/XExporter.hpp>
49#include <com/sun/star/lang/XServiceInfo.hpp>
50#include <com/sun/star/container/XNamed.hpp>
51#include <com/sun/star/drawing/XShapes.hpp>
52#include <com/sun/star/drawing/XMasterPageTarget.hpp>
53#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
54#include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
55#include <com/sun/star/presentation/XPresentationSupplier.hpp>
56#include <com/sun/star/container/XNameAccess.hpp>
57#include <com/sun/star/presentation/XPresentation.hpp>
58#include <com/sun/star/presentation/XPresentationPage.hpp>
59#include <com/sun/star/document/XFilter.hpp>
60#include <com/sun/star/document/XExporter.hpp>
64#ifndef _COM_SUN_STAR_UNO_RUNTIME_EXCEPTION_HPP_
65#include <com/sun/star/uno/RuntimeException.hpp>
61#include <com/sun/star/uno/RuntimeException.hpp>
66#endif
67#include <com/sun/star/lang/XMultiServiceFactory.hpp>
68#include <com/sun/star/graphic/XGraphicProvider.hpp>
69#include <com/sun/star/graphic/GraphicType.hpp>
70#include <com/sun/star/io/XStream.hpp>
71#include <com/sun/star/io/XSeekable.hpp>
72#include <com/sun/star/frame/XComponentLoader.hpp>
73#include <com/sun/star/util/URL.hpp>
74
75using namespace ::std;
62#include <com/sun/star/lang/XMultiServiceFactory.hpp>
63#include <com/sun/star/graphic/XGraphicProvider.hpp>
64#include <com/sun/star/graphic/GraphicType.hpp>
65#include <com/sun/star/io/XStream.hpp>
66#include <com/sun/star/io/XSeekable.hpp>
67#include <com/sun/star/frame/XComponentLoader.hpp>
68#include <com/sun/star/util/URL.hpp>
69
70using namespace ::std;
76using namespace ::rtl;
77using namespace ::com::sun::star;
78using namespace ::com::sun::star::io;
79using namespace ::com::sun::star::awt;
80using namespace ::com::sun::star::uno;
81using namespace ::com::sun::star::lang;
82using namespace ::com::sun::star::util;
83using namespace ::com::sun::star::frame;
84using namespace ::com::sun::star::beans;
85using namespace ::com::sun::star::drawing;
86using namespace ::com::sun::star::graphic;
87using namespace ::com::sun::star::document;
88using namespace ::com::sun::star::container;
89using namespace ::com::sun::star::presentation;
90
71using namespace ::com::sun::star;
72using namespace ::com::sun::star::io;
73using namespace ::com::sun::star::awt;
74using namespace ::com::sun::star::uno;
75using namespace ::com::sun::star::lang;
76using namespace ::com::sun::star::util;
77using namespace ::com::sun::star::frame;
78using namespace ::com::sun::star::beans;
79using namespace ::com::sun::star::drawing;
80using namespace ::com::sun::star::graphic;
81using namespace ::com::sun::star::document;
82using namespace ::com::sun::star::container;
83using namespace ::com::sun::star::presentation;
84
85using ::rtl::OUString;
86
91void ImpExtractCustomShow( const Reference< XModel >& rxModel, const OUString& rCustomShowName )
92{
93 vector< Reference< XDrawPage > > vNonUsedPageList;
94 try
95 {
96 PageCollector::CollectNonCustomShowPages( rxModel, rCustomShowName, vNonUsedPageList );
97 Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW );
98 Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW );

--- 162 unchanged lines hidden (view full) ---

261 rxGraphicProvider->storeGraphic( rxGraphic, aArgs );
262 }
263 }
264 catch( Exception& )
265 {
266 }
267}
268
87void ImpExtractCustomShow( const Reference< XModel >& rxModel, const OUString& rCustomShowName )
88{
89 vector< Reference< XDrawPage > > vNonUsedPageList;
90 try
91 {
92 PageCollector::CollectNonCustomShowPages( rxModel, rCustomShowName, vNonUsedPageList );
93 Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW );
94 Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW );

--- 162 unchanged lines hidden (view full) ---

257 rxGraphicProvider->storeGraphic( rxGraphic, aArgs );
258 }
259 }
260 catch( Exception& )
261 {
262 }
263}
264
269Reference< XGraphic > ImpCompressGraphic( const Reference< XComponentContext >& rxMSF,
265Reference< XGraphic > ImpCompressGraphic( const Reference< XComponentContext >& rxContext,
270 const Reference< XGraphic >& xGraphic, const awt::Size& aLogicalSize, const text::GraphicCrop& aGraphicCropLogic,
271 const GraphicSettings& rGraphicSettings )
272{
273 Reference< XGraphic > xNewGraphic;
274 try
275 {
276 OUString aSourceMimeType;
277 Reference< XPropertySet > xGraphicPropertySet( xGraphic, UNO_QUERY_THROW );

--- 18 unchanged lines hidden (view full) ---

296 if ( !bAnimated )
297 {
298 sal_Bool bNeedsOptimizing = sal_False;
299 sal_Bool bRemoveCropArea( rGraphicSettings.mbRemoveCropArea );
300
301 // cropping has to be removed from SourceSizePixel
302 if ( aGraphicCropLogic.Left || aGraphicCropLogic.Top || aGraphicCropLogic.Right || aGraphicCropLogic.Bottom )
303 {
266 const Reference< XGraphic >& xGraphic, const awt::Size& aLogicalSize, const text::GraphicCrop& aGraphicCropLogic,
267 const GraphicSettings& rGraphicSettings )
268{
269 Reference< XGraphic > xNewGraphic;
270 try
271 {
272 OUString aSourceMimeType;
273 Reference< XPropertySet > xGraphicPropertySet( xGraphic, UNO_QUERY_THROW );

--- 18 unchanged lines hidden (view full) ---

292 if ( !bAnimated )
293 {
294 sal_Bool bNeedsOptimizing = sal_False;
295 sal_Bool bRemoveCropArea( rGraphicSettings.mbRemoveCropArea );
296
297 // cropping has to be removed from SourceSizePixel
298 if ( aGraphicCropLogic.Left || aGraphicCropLogic.Top || aGraphicCropLogic.Right || aGraphicCropLogic.Bottom )
299 {
304 const awt::Size aSize100thMM( GraphicCollector::GetOriginalSize( rxMSF, xGraphic ) );
300 const awt::Size aSize100thMM( GraphicCollector::GetOriginalSize( rxContext, xGraphic ) );
305
306 if ( bRemoveCropArea )
307 bNeedsOptimizing = sal_True;
308
309 if ( aSize100thMM.Width && aSize100thMM.Height )
310 {
311 aGraphicCropPixel.Left = static_cast< sal_Int32 >( ( (double)aSourceSizePixel.Width * aGraphicCropLogic.Left ) / aSize100thMM.Width );
312 aGraphicCropPixel.Top = static_cast< sal_Int32 >( ( (double)aSourceSizePixel.Height* aGraphicCropLogic.Top ) / aSize100thMM.Height );

--- 32 unchanged lines hidden (view full) ---

345 const double fNewSizePixelY = ((double)aDestSizePixel.Height* rGraphicSettings.mnImageResolution ) / fSourceDPIY;
346
347 aDestSizePixel = awt::Size( (sal_Int32)fNewSizePixelX, (sal_Int32)fNewSizePixelY );
348 bNeedsOptimizing = sal_True;
349 }
350 }
351 if ( bNeedsOptimizing && aDestSizePixel.Width && aDestSizePixel.Height )
352 {
301
302 if ( bRemoveCropArea )
303 bNeedsOptimizing = sal_True;
304
305 if ( aSize100thMM.Width && aSize100thMM.Height )
306 {
307 aGraphicCropPixel.Left = static_cast< sal_Int32 >( ( (double)aSourceSizePixel.Width * aGraphicCropLogic.Left ) / aSize100thMM.Width );
308 aGraphicCropPixel.Top = static_cast< sal_Int32 >( ( (double)aSourceSizePixel.Height* aGraphicCropLogic.Top ) / aSize100thMM.Height );

--- 32 unchanged lines hidden (view full) ---

341 const double fNewSizePixelY = ((double)aDestSizePixel.Height* rGraphicSettings.mnImageResolution ) / fSourceDPIY;
342
343 aDestSizePixel = awt::Size( (sal_Int32)fNewSizePixelX, (sal_Int32)fNewSizePixelY );
344 bNeedsOptimizing = sal_True;
345 }
346 }
347 if ( bNeedsOptimizing && aDestSizePixel.Width && aDestSizePixel.Height )
348 {
353 Reference< XStream > xTempFile( rxMSF->getServiceManager()->createInstanceWithContext( OUString::createFromAscii( "com.sun.star.io.TempFile" ), rxMSF ), UNO_QUERY_THROW );
349 Reference< XStream > xTempFile( rxContext->getServiceManager()->createInstanceWithContext( OUString::createFromAscii( "com.sun.star.io.TempFile" ), rxContext ), UNO_QUERY_THROW );
354 Reference< XOutputStream > xOutputStream( xTempFile->getOutputStream() );
350 Reference< XOutputStream > xOutputStream( xTempFile->getOutputStream() );
355 Reference< XGraphicProvider > xGraphicProvider( rxMSF->getServiceManager()->createInstanceWithContext( OUString::createFromAscii( "com.sun.star.graphic.GraphicProvider" ), rxMSF ), UNO_QUERY_THROW );
351 Reference< XGraphicProvider > xGraphicProvider( rxContext->getServiceManager()->createInstanceWithContext( OUString::createFromAscii( "com.sun.star.graphic.GraphicProvider" ), rxContext ), UNO_QUERY_THROW );
356
357 ImpCompressGraphic( xGraphicProvider, xGraphic, xOutputStream, aDestMimeType, aLogicalSize, rGraphicSettings.mnJPEGQuality, rGraphicSettings.mnImageResolution, bRemoveCropArea, aGraphicCropLogic );
358 Reference< XInputStream > xInputStream( xTempFile->getInputStream() );
359 Reference< XSeekable > xSeekable( xInputStream, UNO_QUERY_THROW );
360 xSeekable->seek( 0 );
361 Sequence< PropertyValue > aArgs( 1 );
362 aArgs[ 0 ].Name = TKGet( TK_InputStream );
363 aArgs[ 0 ].Value <<= xInputStream;
364 xNewGraphic = xGraphicProvider->queryGraphic( aArgs );
365 }
366 }
367 }
368 }
369 }
370 else // this is a metafile
371 {
372 rtl::OUString aDestMimeType( aSourceMimeType );
352
353 ImpCompressGraphic( xGraphicProvider, xGraphic, xOutputStream, aDestMimeType, aLogicalSize, rGraphicSettings.mnJPEGQuality, rGraphicSettings.mnImageResolution, bRemoveCropArea, aGraphicCropLogic );
354 Reference< XInputStream > xInputStream( xTempFile->getInputStream() );
355 Reference< XSeekable > xSeekable( xInputStream, UNO_QUERY_THROW );
356 xSeekable->seek( 0 );
357 Sequence< PropertyValue > aArgs( 1 );
358 aArgs[ 0 ].Name = TKGet( TK_InputStream );
359 aArgs[ 0 ].Value <<= xInputStream;
360 xNewGraphic = xGraphicProvider->queryGraphic( aArgs );
361 }
362 }
363 }
364 }
365 }
366 else // this is a metafile
367 {
368 rtl::OUString aDestMimeType( aSourceMimeType );
373 Reference< XStream > xTempFile( rxMSF->getServiceManager()->createInstanceWithContext( OUString::createFromAscii( "com.sun.star.io.TempFile" ), rxMSF ), UNO_QUERY_THROW );
369 Reference< XStream > xTempFile( rxContext->getServiceManager()->createInstanceWithContext( OUString::createFromAscii( "com.sun.star.io.TempFile" ), rxContext ), UNO_QUERY_THROW );
374 Reference< XOutputStream > xOutputStream( xTempFile->getOutputStream() );
370 Reference< XOutputStream > xOutputStream( xTempFile->getOutputStream() );
375 Reference< XGraphicProvider > xGraphicProvider( rxMSF->getServiceManager()->createInstanceWithContext( OUString::createFromAscii( "com.sun.star.graphic.GraphicProvider" ), rxMSF ), UNO_QUERY_THROW );
371 Reference< XGraphicProvider > xGraphicProvider( rxContext->getServiceManager()->createInstanceWithContext( OUString::createFromAscii( "com.sun.star.graphic.GraphicProvider" ), rxContext ), UNO_QUERY_THROW );
376 ImpCompressGraphic( xGraphicProvider, xGraphic, xOutputStream, aDestMimeType, aLogicalSize, rGraphicSettings.mnJPEGQuality, rGraphicSettings.mnImageResolution, sal_False, aGraphicCropLogic );
377 Reference< XInputStream > xInputStream( xTempFile->getInputStream() );
378 Reference< XSeekable > xSeekable( xInputStream, UNO_QUERY_THROW );
379 xSeekable->seek( 0 );
380 Sequence< PropertyValue > aArgs( 1 );
381 aArgs[ 0 ].Name = TKGet( TK_InputStream );
382 aArgs[ 0 ].Value <<= xInputStream;
383 xNewGraphic = xGraphicProvider->queryGraphic( aArgs );
384 }
385 }
386 }
387 catch( Exception& )
388 {
389 }
390 return xNewGraphic;
391}
392
372 ImpCompressGraphic( xGraphicProvider, xGraphic, xOutputStream, aDestMimeType, aLogicalSize, rGraphicSettings.mnJPEGQuality, rGraphicSettings.mnImageResolution, sal_False, aGraphicCropLogic );
373 Reference< XInputStream > xInputStream( xTempFile->getInputStream() );
374 Reference< XSeekable > xSeekable( xInputStream, UNO_QUERY_THROW );
375 xSeekable->seek( 0 );
376 Sequence< PropertyValue > aArgs( 1 );
377 aArgs[ 0 ].Name = TKGet( TK_InputStream );
378 aArgs[ 0 ].Value <<= xInputStream;
379 xNewGraphic = xGraphicProvider->queryGraphic( aArgs );
380 }
381 }
382 }
383 catch( Exception& )
384 {
385 }
386 return xNewGraphic;
387}
388
393void CompressGraphics( ImpOptimizer& rOptimizer, const Reference< XComponentContext >& rxMSF, const GraphicSettings& rGraphicSettings,
389void CompressGraphics( ImpOptimizer& rOptimizer, const Reference< XComponentContext >& rxContext, const GraphicSettings& rGraphicSettings,
394 std::vector< GraphicCollector::GraphicEntity >& rGraphicList )
395{
396 try
397 {
398 std::vector< GraphicCollector::GraphicEntity >::iterator aGraphicIter( rGraphicList.begin() );
399 std::vector< GraphicCollector::GraphicEntity >::iterator aGraphicIEnd( rGraphicList.end() );
400 double i = 0;
401 while( aGraphicIter != aGraphicIEnd )

--- 18 unchanged lines hidden (view full) ---

420 else if ( aGraphicIter->maUser[ 0 ].mxShape.is() )
421 {
422 Reference< XPropertySet > xShapePropertySet( aGraphicIter->maUser[ 0 ].mxShape, UNO_QUERY_THROW );
423 xShapePropertySet->getPropertyValue( TKGet( TK_Graphic ) ) >>= xGraphic;
424 }
425 if ( xGraphic.is() )
426 {
427 Reference< XPropertySet > xNewGraphicPropertySet( xGraphic, UNO_QUERY_THROW );
390 std::vector< GraphicCollector::GraphicEntity >& rGraphicList )
391{
392 try
393 {
394 std::vector< GraphicCollector::GraphicEntity >::iterator aGraphicIter( rGraphicList.begin() );
395 std::vector< GraphicCollector::GraphicEntity >::iterator aGraphicIEnd( rGraphicList.end() );
396 double i = 0;
397 while( aGraphicIter != aGraphicIEnd )

--- 18 unchanged lines hidden (view full) ---

416 else if ( aGraphicIter->maUser[ 0 ].mxShape.is() )
417 {
418 Reference< XPropertySet > xShapePropertySet( aGraphicIter->maUser[ 0 ].mxShape, UNO_QUERY_THROW );
419 xShapePropertySet->getPropertyValue( TKGet( TK_Graphic ) ) >>= xGraphic;
420 }
421 if ( xGraphic.is() )
422 {
423 Reference< XPropertySet > xNewGraphicPropertySet( xGraphic, UNO_QUERY_THROW );
428 awt::Size aSize100thMM( GraphicCollector::GetOriginalSize( rxMSF, xGraphic ) );
429 Reference< XGraphic > xNewGraphic( ImpCompressGraphic( rxMSF, xGraphic, aGraphicIter->maLogicalSize, aGraphicIter->maGraphicCropLogic, aGraphicSettings ) );
424 awt::Size aSize100thMM( GraphicCollector::GetOriginalSize( rxContext, xGraphic ) );
425 Reference< XGraphic > xNewGraphic( ImpCompressGraphic( rxContext, xGraphic, aGraphicIter->maLogicalSize, aGraphicIter->maGraphicCropLogic, aGraphicSettings ) );
430 if ( xNewGraphic.is() )
431 {
432 // applying graphic to each user
433 std::vector< GraphicCollector::GraphicUser >::iterator aGraphicUserIter( aGraphicIter->maUser.begin() );
434 while( aGraphicUserIter != aGraphicIter->maUser.end() )
435 {
436 if ( aGraphicUserIter->mxShape.is() )
437 {
438 rtl::OUString sEmptyGraphicURL;
439 Reference< XPropertySet > xShapePropertySet( aGraphicUserIter->mxShape, UNO_QUERY_THROW );
440 xShapePropertySet->setPropertyValue( TKGet( TK_GraphicURL ), Any( sEmptyGraphicURL ) );
441 xShapePropertySet->setPropertyValue( TKGet( TK_Graphic ), Any( xNewGraphic ) );
442
443 if ( aGraphicUserIter->maGraphicCropLogic.Left || aGraphicUserIter->maGraphicCropLogic.Top
444 || aGraphicUserIter->maGraphicCropLogic.Right || aGraphicUserIter->maGraphicCropLogic.Bottom )
445 { // removing crop area was not possible or should't been applied
446 text::GraphicCrop aGraphicCropLogic( 0, 0, 0, 0 );
447 if ( !aGraphicSettings.mbRemoveCropArea )
448 {
426 if ( xNewGraphic.is() )
427 {
428 // applying graphic to each user
429 std::vector< GraphicCollector::GraphicUser >::iterator aGraphicUserIter( aGraphicIter->maUser.begin() );
430 while( aGraphicUserIter != aGraphicIter->maUser.end() )
431 {
432 if ( aGraphicUserIter->mxShape.is() )
433 {
434 rtl::OUString sEmptyGraphicURL;
435 Reference< XPropertySet > xShapePropertySet( aGraphicUserIter->mxShape, UNO_QUERY_THROW );
436 xShapePropertySet->setPropertyValue( TKGet( TK_GraphicURL ), Any( sEmptyGraphicURL ) );
437 xShapePropertySet->setPropertyValue( TKGet( TK_Graphic ), Any( xNewGraphic ) );
438
439 if ( aGraphicUserIter->maGraphicCropLogic.Left || aGraphicUserIter->maGraphicCropLogic.Top
440 || aGraphicUserIter->maGraphicCropLogic.Right || aGraphicUserIter->maGraphicCropLogic.Bottom )
441 { // removing crop area was not possible or should't been applied
442 text::GraphicCrop aGraphicCropLogic( 0, 0, 0, 0 );
443 if ( !aGraphicSettings.mbRemoveCropArea )
444 {
449 awt::Size aNewSize( GraphicCollector::GetOriginalSize( rxMSF, xNewGraphic ) );
445 awt::Size aNewSize( GraphicCollector::GetOriginalSize( rxContext, xNewGraphic ) );
450 aGraphicCropLogic.Left = (sal_Int32)((double)aGraphicUserIter->maGraphicCropLogic.Left * ((double)aNewSize.Width / (double)aSize100thMM.Width));
451 aGraphicCropLogic.Top = (sal_Int32)((double)aGraphicUserIter->maGraphicCropLogic.Top * ((double)aNewSize.Height / (double)aSize100thMM.Height));
452 aGraphicCropLogic.Right = (sal_Int32)((double)aGraphicUserIter->maGraphicCropLogic.Right * ((double)aNewSize.Width / (double)aSize100thMM.Width));
453 aGraphicCropLogic.Bottom = (sal_Int32)((double)aGraphicUserIter->maGraphicCropLogic.Bottom * ((double)aNewSize.Height / (double)aSize100thMM.Height));
454 }
455 xShapePropertySet->setPropertyValue( TKGet( TK_GraphicCrop ), Any( aGraphicCropLogic ) );
456 }
457 }

--- 34 unchanged lines hidden (view full) ---

492 {
493 }
494}
495
496// ----------------
497// - ImpOptimizer -
498// ----------------
499
446 aGraphicCropLogic.Left = (sal_Int32)((double)aGraphicUserIter->maGraphicCropLogic.Left * ((double)aNewSize.Width / (double)aSize100thMM.Width));
447 aGraphicCropLogic.Top = (sal_Int32)((double)aGraphicUserIter->maGraphicCropLogic.Top * ((double)aNewSize.Height / (double)aSize100thMM.Height));
448 aGraphicCropLogic.Right = (sal_Int32)((double)aGraphicUserIter->maGraphicCropLogic.Right * ((double)aNewSize.Width / (double)aSize100thMM.Width));
449 aGraphicCropLogic.Bottom = (sal_Int32)((double)aGraphicUserIter->maGraphicCropLogic.Bottom * ((double)aNewSize.Height / (double)aSize100thMM.Height));
450 }
451 xShapePropertySet->setPropertyValue( TKGet( TK_GraphicCrop ), Any( aGraphicCropLogic ) );
452 }
453 }

--- 34 unchanged lines hidden (view full) ---

488 {
489 }
490}
491
492// ----------------
493// - ImpOptimizer -
494// ----------------
495
500ImpOptimizer::ImpOptimizer( const Reference< XComponentContext >& rxMSF, const Reference< XModel >& rxModel ) :
501 mxMSF ( rxMSF ),
496ImpOptimizer::ImpOptimizer( const Reference< XComponentContext >& rxContext, const Reference< XModel >& rxModel ) :
497 mxContext ( rxContext ),
502 mxModel ( rxModel ),
503 mbJPEGCompression ( sal_False ),
504 mnJPEGQuality ( 90 ),
505 mbRemoveCropArea ( sal_False ),
506 mnImageResolution ( 0 ),
507 mbEmbedLinkedGraphics ( sal_True ),
508 mbOLEOptimization ( sal_False ),
509 mnOLEOptimizationType ( 0 ),
510 mbDeleteUnusedMasterPages ( sal_False ),
511 mbDeleteHiddenSlides ( sal_False ),
512 mbDeleteNotesPages ( sal_False ),
513 mbOpenNewDocument ( sal_True )
514{
498 mxModel ( rxModel ),
499 mbJPEGCompression ( sal_False ),
500 mnJPEGQuality ( 90 ),
501 mbRemoveCropArea ( sal_False ),
502 mnImageResolution ( 0 ),
503 mbEmbedLinkedGraphics ( sal_True ),
504 mbOLEOptimization ( sal_False ),
505 mnOLEOptimizationType ( 0 ),
506 mbDeleteUnusedMasterPages ( sal_False ),
507 mbDeleteHiddenSlides ( sal_False ),
508 mbDeleteNotesPages ( sal_False ),
509 mbOpenNewDocument ( sal_True )
510{
511 OSL_TRACE("ImpOptimizer::ImpOptimizer");
512 Reference< XController > xController( mxModel->getCurrentController() );
513 if (xController.is() )
514 mxFrame.set( xController->getFrame() );
515}
516
517// -----------------------------------------------------------------------------
518
519ImpOptimizer::~ImpOptimizer()
520{
515}
516
517// -----------------------------------------------------------------------------
518
519ImpOptimizer::~ImpOptimizer()
520{
521 OSL_TRACE("ImpOptimizer::~ImpOptimizer");
521}
522
523// -----------------------------------------------------------------------------
524
525void ImpOptimizer::DispatchStatus()
526{
522}
523
524// -----------------------------------------------------------------------------
525
526void ImpOptimizer::DispatchStatus()
527{
527 if ( mxStatusDispatcher.is() )
528 if ( mxStatusListener.is() )
528 {
529 {
529 URL aURL;
530 aURL.Protocol = OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.com.sun.star.comp.SunPresentationMinimizer:" ) );
531 aURL.Path = OUString( RTL_CONSTASCII_USTRINGPARAM( "statusupdate" ) );
532 mxStatusDispatcher->dispatch( aURL, GetStatusSequence() );
530 FeatureStateEvent aState;
531 aState.IsEnabled = sal_True;
532 aState.State <<= GetStatusSequence();
533 mxStatusListener->statusChanged( aState );
533 }
534}
535
536// -----------------------------------------------------------------------------
537
534 }
535}
536
537// -----------------------------------------------------------------------------
538
538sal_Bool ImpOptimizer::Optimize()
539sal_Bool ImpOptimizer::ImplOptimize()
539{
540
541 if ( maCustomShowName.getLength() )
542 ImpExtractCustomShow( mxModel, maCustomShowName );
543
544 if ( mbDeleteUnusedMasterPages )
545 {
546 SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( 40 ) ) );
540{
541
542 if ( maCustomShowName.getLength() )
543 ImpExtractCustomShow( mxModel, maCustomShowName );
544
545 if ( mbDeleteUnusedMasterPages )
546 {
547 SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( 40 ) ) );
547 SetStatusValue( TK_Status, Any( TKGet( STR_DELETING_SLIDES ) ) );
548 SetStatusValue( TK_Status, Any( ConfigurationAccess::getString( STR_DELETING_SLIDES ) ) );
548 DispatchStatus();
549 ImpDeleteUnusedMasterPages( mxModel );
550 }
551
552 if ( mbDeleteHiddenSlides )
553 {
554 SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( 40 ) ) );
549 DispatchStatus();
550 ImpDeleteUnusedMasterPages( mxModel );
551 }
552
553 if ( mbDeleteHiddenSlides )
554 {
555 SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( 40 ) ) );
555 SetStatusValue( TK_Status, Any( TKGet( STR_DELETING_SLIDES ) ) );
556 SetStatusValue( TK_Status, Any( ConfigurationAccess::getString( STR_DELETING_SLIDES ) ) );
556 DispatchStatus();
557 ImpDeleteHiddenSlides( mxModel );
558 }
559
560 if ( mbDeleteNotesPages )
561 {
557 DispatchStatus();
558 ImpDeleteHiddenSlides( mxModel );
559 }
560
561 if ( mbDeleteNotesPages )
562 {
562 SetStatusValue( TK_Status, Any( TKGet( STR_DELETING_SLIDES ) ) );
563 SetStatusValue( TK_Status, Any( ConfigurationAccess::getString( STR_DELETING_SLIDES ) ) );
563 DispatchStatus();
564 ImpDeleteNotesPages( mxModel );
565 }
566
567 if ( mbOLEOptimization )
568 {
569 SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( 45 ) ) );
564 DispatchStatus();
565 ImpDeleteNotesPages( mxModel );
566 }
567
568 if ( mbOLEOptimization )
569 {
570 SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( 45 ) ) );
570 SetStatusValue( TK_Status, Any( TKGet( STR_CREATING_OLE_REPLACEMENTS ) ) );
571 SetStatusValue( TK_Status, Any( ConfigurationAccess::getString( STR_CREATING_OLE_REPLACEMENTS ) ) );
571 DispatchStatus();
572 ImpConvertOLE( mxModel, mnOLEOptimizationType );
573 }
574
575 if ( mbJPEGCompression || mbRemoveCropArea || mnImageResolution )
576 {
577 SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( 50 ) ) );
572 DispatchStatus();
573 ImpConvertOLE( mxModel, mnOLEOptimizationType );
574 }
575
576 if ( mbJPEGCompression || mbRemoveCropArea || mnImageResolution )
577 {
578 SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( 50 ) ) );
578 SetStatusValue( TK_Status, Any( TKGet( STR_OPTIMIZING_GRAPHICS ) ) );
579 SetStatusValue( TK_Status, Any( ConfigurationAccess::getString( STR_OPTIMIZING_GRAPHICS ) ) );
579 DispatchStatus();
580
581 std::vector< GraphicCollector::GraphicEntity > aGraphicList;
582 GraphicSettings aGraphicSettings( mbJPEGCompression, mnJPEGQuality, mbRemoveCropArea, mnImageResolution, mbEmbedLinkedGraphics );
580 DispatchStatus();
581
582 std::vector< GraphicCollector::GraphicEntity > aGraphicList;
583 GraphicSettings aGraphicSettings( mbJPEGCompression, mnJPEGQuality, mbRemoveCropArea, mnImageResolution, mbEmbedLinkedGraphics );
583 GraphicCollector::CollectGraphics( mxMSF, mxModel, aGraphicSettings, aGraphicList );
584 CompressGraphics( *this, mxMSF, aGraphicSettings, aGraphicList );
584 GraphicCollector::CollectGraphics( mxContext, mxModel, aGraphicSettings, aGraphicList );
585 CompressGraphics( *this, mxContext, aGraphicSettings, aGraphicList );
585 }
586 SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( 100 ) ) );
587 DispatchStatus();
588 return sal_True;
589}
590
591static void DispatchURL( Reference< XComponentContext > xMSF, OUString sURL, Reference< XFrame > xFrame )
592{

--- 14 unchanged lines hidden (view full) ---

607 {
608 }
609}
610
611// -----------------------------------------------------------------------------
612
613sal_Bool ImpOptimizer::Optimize( const Sequence< PropertyValue >& rArguments )
614{
586 }
587 SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( 100 ) ) );
588 DispatchStatus();
589 return sal_True;
590}
591
592static void DispatchURL( Reference< XComponentContext > xMSF, OUString sURL, Reference< XFrame > xFrame )
593{

--- 14 unchanged lines hidden (view full) ---

608 {
609 }
610}
611
612// -----------------------------------------------------------------------------
613
614sal_Bool ImpOptimizer::Optimize( const Sequence< PropertyValue >& rArguments )
615{
616 OSL_TRACE("ImpOptimizer::Optimize");
615 sal_Bool bRet = sal_True;
616
617 if ( mxModel.is() )
618 {
617 sal_Bool bRet = sal_True;
618
619 if ( mxModel.is() )
620 {
621 Reference< XWindowPeer > xParentWindow;
619 sal_Int64 nEstimatedFileSize = 0;
620 SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( 0 ) ) );
621 DispatchStatus();
622
623 int i, nICount;
624 for ( i = 0, nICount = rArguments.getLength(); i < nICount; i++ )
625 {
626 switch( TKGet( rArguments[ i ].Name ) )
627 {
622 sal_Int64 nEstimatedFileSize = 0;
623 SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( 0 ) ) );
624 DispatchStatus();
625
626 int i, nICount;
627 for ( i = 0, nICount = rArguments.getLength(); i < nICount; i++ )
628 {
629 switch( TKGet( rArguments[ i ].Name ) )
630 {
628 case TK_StatusDispatcher : rArguments[ i ].Value >>= mxStatusDispatcher; break;
629 case TK_InformationDialog: rArguments[ i ].Value >>= mxInformationDialog; break;
631 case TK_StatusListener : rArguments[ i ].Value >>= mxStatusListener; break;
632 case TK_ParentWindow: rArguments[ i ].Value >>= xParentWindow; break;
630 case TK_Settings :
631 {
632 com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > aSettings;
633 int j, nJCount;
634 rArguments[ i ].Value >>= aSettings;
635 for ( j = 0, nJCount = aSettings.getLength(); j < nJCount; j++ )
636 {
637 switch( TKGet( aSettings[ j ].Name ) )

--- 25 unchanged lines hidden (view full) ---

663 sal_Int64 nSourceSize = 0;
664 sal_Int64 nDestSize = 0;
665
666 Reference< XFrame > xSelf;
667 if ( maSaveAsURL.getLength() )
668 {
669
670 SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( 10 ) ) );
633 case TK_Settings :
634 {
635 com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > aSettings;
636 int j, nJCount;
637 rArguments[ i ].Value >>= aSettings;
638 for ( j = 0, nJCount = aSettings.getLength(); j < nJCount; j++ )
639 {
640 switch( TKGet( aSettings[ j ].Name ) )

--- 25 unchanged lines hidden (view full) ---

666 sal_Int64 nSourceSize = 0;
667 sal_Int64 nDestSize = 0;
668
669 Reference< XFrame > xSelf;
670 if ( maSaveAsURL.getLength() )
671 {
672
673 SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( 10 ) ) );
671 SetStatusValue( TK_Status, Any( TKGet( STR_DUPLICATING_PRESENTATION ) ) );
674 SetStatusValue( TK_Status, Any( ConfigurationAccess::getString( STR_DUPLICATING_PRESENTATION ) ) );
672 DispatchStatus();
673
674 Reference< XStorable >xStorable( mxModel, UNO_QUERY );
675 if ( xStorable.is() )
676 {
677 if ( xStorable->hasLocation() )
678 nSourceSize = PPPOptimizer::GetFileSize( xStorable->getLocation() );
679

--- 5 unchanged lines hidden (view full) ---

685 aArguments[ nLength ].Name = TKGet( TK_FilterName );
686 aArguments[ nLength ].Value <<= maFilterName;
687 }
688 xStorable->storeToURL( maSaveAsURL, aArguments );
689 if ( !nSourceSize )
690 nSourceSize = PPPOptimizer::GetFileSize( maSaveAsURL );
691
692 SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( 30 ) ) );
675 DispatchStatus();
676
677 Reference< XStorable >xStorable( mxModel, UNO_QUERY );
678 if ( xStorable.is() )
679 {
680 if ( xStorable->hasLocation() )
681 nSourceSize = PPPOptimizer::GetFileSize( xStorable->getLocation() );
682

--- 5 unchanged lines hidden (view full) ---

688 aArguments[ nLength ].Name = TKGet( TK_FilterName );
689 aArguments[ nLength ].Value <<= maFilterName;
690 }
691 xStorable->storeToURL( maSaveAsURL, aArguments );
692 if ( !nSourceSize )
693 nSourceSize = PPPOptimizer::GetFileSize( maSaveAsURL );
694
695 SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( 30 ) ) );
693 SetStatusValue( TK_Status, Any( TKGet( STR_DUPLICATING_PRESENTATION ) ) );
696 SetStatusValue( TK_Status, Any( ConfigurationAccess::getString( STR_DUPLICATING_PRESENTATION ) ) );
694 DispatchStatus();
695
697 DispatchStatus();
698
696 Reference< XDesktop > xDesktop( mxMSF->getServiceManager()->createInstanceWithContext(
697 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ), mxMSF ), UNO_QUERY );
699 Reference< XDesktop > xDesktop( mxContext->getServiceManager()->createInstanceWithContext(
700 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ), mxContext ), UNO_QUERY );
698 Reference< XFrame > xFrame( xDesktop, UNO_QUERY );
699 xSelf = xFrame->findFrame( TKGet( TK__blank ), FrameSearchFlag::CREATE );
700 Reference< XComponentLoader > xComponentLoader( xSelf, UNO_QUERY );
701
702 Sequence< PropertyValue > aLoadProps( 1 );
703 aLoadProps[ 0 ].Name = TKGet( TK_Hidden );
704 aLoadProps[ 0 ].Value <<= (sal_Bool)( sal_True );
705 mxModel = Reference< XModel >( xComponentLoader->loadComponentFromURL(
706 maSaveAsURL, TKGet( TK__self ), 0, aLoadProps ), UNO_QUERY );
707 }
708 }
709
710 // check if the document is ReadOnly -> error
711 Reference< XStorable > xStorable( mxModel, UNO_QUERY );
712 if ( xStorable.is() && !xStorable->isReadonly() )
713 {
714 mxModel->lockControllers();
701 Reference< XFrame > xFrame( xDesktop, UNO_QUERY );
702 xSelf = xFrame->findFrame( TKGet( TK__blank ), FrameSearchFlag::CREATE );
703 Reference< XComponentLoader > xComponentLoader( xSelf, UNO_QUERY );
704
705 Sequence< PropertyValue > aLoadProps( 1 );
706 aLoadProps[ 0 ].Name = TKGet( TK_Hidden );
707 aLoadProps[ 0 ].Value <<= (sal_Bool)( sal_True );
708 mxModel = Reference< XModel >( xComponentLoader->loadComponentFromURL(
709 maSaveAsURL, TKGet( TK__self ), 0, aLoadProps ), UNO_QUERY );
710 }
711 }
712
713 // check if the document is ReadOnly -> error
714 Reference< XStorable > xStorable( mxModel, UNO_QUERY );
715 if ( xStorable.is() && !xStorable->isReadonly() )
716 {
717 mxModel->lockControllers();
715 bRet = Optimize();
718 bRet = ImplOptimize();
716 mxModel->unlockControllers();
717
718 // clearing undo stack:
719 mxModel->unlockControllers();
720
721 // clearing undo stack:
719 Reference< XFrame > xFrame( xSelf.is() ? xSelf : mxInformationDialog );
722 Reference< XFrame > xFrame( mxFrame );
720 if ( xFrame.is() )
721 {
722 const OUString sSlot( RTL_CONSTASCII_USTRINGPARAM( "slot:27115" ) );
723 if ( xFrame.is() )
724 {
725 const OUString sSlot( RTL_CONSTASCII_USTRINGPARAM( "slot:27115" ) );
723 DispatchURL( mxMSF, sSlot, xFrame );
726 DispatchURL( mxContext, sSlot, xFrame );
724 }
725 }
726
727 if ( maSaveAsURL.getLength() )
728 {
729 if ( xStorable.is() )
730 {
731 xStorable->store();
732 nDestSize = PPPOptimizer::GetFileSize( maSaveAsURL );
733 }
734 }
735
727 }
728 }
729
730 if ( maSaveAsURL.getLength() )
731 {
732 if ( xStorable.is() )
733 {
734 xStorable->store();
735 nDestSize = PPPOptimizer::GetFileSize( maSaveAsURL );
736 }
737 }
738
736 if ( mxInformationDialog.is() )
739 if ( xParentWindow.is() )
737 {
740 {
738 InformationDialog aInformationDialog( mxMSF, mxInformationDialog, maSaveAsURL, mbOpenNewDocument, nSourceSize, nDestSize, nEstimatedFileSize );
741 InformationDialog aInformationDialog(
742 mxContext, xParentWindow, maSaveAsURL, mbOpenNewDocument,
743 nSourceSize, nDestSize, nEstimatedFileSize );
739 aInformationDialog.execute();
740 SetStatusValue( TK_OpenNewDocument, Any( mbOpenNewDocument ) );
741 DispatchStatus();
742 }
743
744 if ( maSaveAsURL.getLength() )
745 {
746 if ( mbOpenNewDocument && xSelf.is() )

--- 22 unchanged lines hidden ---
744 aInformationDialog.execute();
745 SetStatusValue( TK_OpenNewDocument, Any( mbOpenNewDocument ) );
746 DispatchStatus();
747 }
748
749 if ( maSaveAsURL.getLength() )
750 {
751 if ( mbOpenNewDocument && xSelf.is() )

--- 22 unchanged lines hidden ---