1*c142477cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*c142477cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*c142477cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*c142477cSAndrew Rist * distributed with this work for additional information 6*c142477cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*c142477cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*c142477cSAndrew Rist * "License"); you may not use this file except in compliance 9*c142477cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*c142477cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*c142477cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*c142477cSAndrew Rist * software distributed under the License is distributed on an 15*c142477cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*c142477cSAndrew Rist * KIND, either express or implied. See the License for the 17*c142477cSAndrew Rist * specific language governing permissions and limitations 18*c142477cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*c142477cSAndrew Rist *************************************************************/ 21*c142477cSAndrew Rist 22*c142477cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sdext.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "impoptimizer.hxx" 28cdf0e10cSrcweir #include "pppoptimizer.hxx" 29cdf0e10cSrcweir #include "graphiccollector.hxx" 30cdf0e10cSrcweir #include "pagecollector.hxx" 31cdf0e10cSrcweir #include "informationdialog.hxx" 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <unotools/localfilehelper.hxx> 34cdf0e10cSrcweir #include <unotools/processfactory.hxx> 35cdf0e10cSrcweir #include <vector> 36cdf0e10cSrcweir #include "com/sun/star/util/URL.hpp" 37cdf0e10cSrcweir #include "com/sun/star/util/XURLTransformer.hpp" 38cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 39cdf0e10cSrcweir #include <com/sun/star/awt/Rectangle.hpp> 40cdf0e10cSrcweir #include <com/sun/star/awt/Size.hpp> 41cdf0e10cSrcweir #include <com/sun/star/util/MeasureUnit.hpp> 42cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp> 43cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp> 44cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp> 45cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp> 46cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FRAME_FrameSearchFlag_HPP_ 47cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp> 48cdf0e10cSrcweir #endif 49cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp> 50cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphicProvider.hpp> 51cdf0e10cSrcweir #include <unotools/configmgr.hxx> 52cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 53cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp> 54cdf0e10cSrcweir #include <com/sun/star/drawing/XShapes.hpp> 55cdf0e10cSrcweir #include <com/sun/star/drawing/XMasterPageTarget.hpp> 56cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPagesSupplier.hpp> 57cdf0e10cSrcweir #include <com/sun/star/drawing/XMasterPagesSupplier.hpp> 58cdf0e10cSrcweir #include <com/sun/star/presentation/XPresentationSupplier.hpp> 59cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 60cdf0e10cSrcweir #include <com/sun/star/presentation/XPresentation.hpp> 61cdf0e10cSrcweir #include <com/sun/star/presentation/XPresentationPage.hpp> 62cdf0e10cSrcweir #include <com/sun/star/document/XFilter.hpp> 63cdf0e10cSrcweir #include <com/sun/star/document/XExporter.hpp> 64cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UNO_RUNTIME_EXCEPTION_HPP_ 65cdf0e10cSrcweir #include <com/sun/star/uno/RuntimeException.hpp> 66cdf0e10cSrcweir #endif 67cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 68cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphicProvider.hpp> 69cdf0e10cSrcweir #include <com/sun/star/graphic/GraphicType.hpp> 70cdf0e10cSrcweir #include <com/sun/star/io/XStream.hpp> 71cdf0e10cSrcweir #include <com/sun/star/io/XSeekable.hpp> 72cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp> 73cdf0e10cSrcweir #include <com/sun/star/util/URL.hpp> 74cdf0e10cSrcweir 75cdf0e10cSrcweir using namespace ::std; 76cdf0e10cSrcweir using namespace ::rtl; 77cdf0e10cSrcweir using namespace ::com::sun::star; 78cdf0e10cSrcweir using namespace ::com::sun::star::io; 79cdf0e10cSrcweir using namespace ::com::sun::star::awt; 80cdf0e10cSrcweir using namespace ::com::sun::star::uno; 81cdf0e10cSrcweir using namespace ::com::sun::star::lang; 82cdf0e10cSrcweir using namespace ::com::sun::star::util; 83cdf0e10cSrcweir using namespace ::com::sun::star::frame; 84cdf0e10cSrcweir using namespace ::com::sun::star::beans; 85cdf0e10cSrcweir using namespace ::com::sun::star::drawing; 86cdf0e10cSrcweir using namespace ::com::sun::star::graphic; 87cdf0e10cSrcweir using namespace ::com::sun::star::document; 88cdf0e10cSrcweir using namespace ::com::sun::star::container; 89cdf0e10cSrcweir using namespace ::com::sun::star::presentation; 90cdf0e10cSrcweir 91cdf0e10cSrcweir void ImpExtractCustomShow( const Reference< XModel >& rxModel, const OUString& rCustomShowName ) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir vector< Reference< XDrawPage > > vNonUsedPageList; 94cdf0e10cSrcweir try 95cdf0e10cSrcweir { 96cdf0e10cSrcweir PageCollector::CollectNonCustomShowPages( rxModel, rCustomShowName, vNonUsedPageList ); 97cdf0e10cSrcweir Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW ); 98cdf0e10cSrcweir Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW ); 99cdf0e10cSrcweir vector< Reference< XDrawPage > >::iterator aIter( vNonUsedPageList.begin() ); 100cdf0e10cSrcweir while( aIter != vNonUsedPageList.end() ) 101cdf0e10cSrcweir xDrawPages->remove( *aIter++ ); 102cdf0e10cSrcweir } 103cdf0e10cSrcweir catch( Exception& ) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir 106cdf0e10cSrcweir } 107cdf0e10cSrcweir } 108cdf0e10cSrcweir 109cdf0e10cSrcweir void ImpDeleteUnusedMasterPages( const Reference< XModel >& rxModel ) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir vector< PageCollector::MasterPageEntity > aMasterPageList; 112cdf0e10cSrcweir PageCollector::CollectMasterPages( rxModel, aMasterPageList ); 113cdf0e10cSrcweir 114cdf0e10cSrcweir // now master pages that are not marked can be deleted 115cdf0e10cSrcweir Reference< XMasterPagesSupplier > xMasterPagesSupplier( rxModel, UNO_QUERY_THROW ); 116cdf0e10cSrcweir Reference< XDrawPages > xMasterPages( xMasterPagesSupplier->getMasterPages(), UNO_QUERY_THROW ); 117cdf0e10cSrcweir vector< PageCollector::MasterPageEntity >::iterator aIter( aMasterPageList.begin() ); 118cdf0e10cSrcweir while( aIter != aMasterPageList.end() ) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir if ( !aIter->bUsed ) 121cdf0e10cSrcweir xMasterPages->remove( aIter->xMasterPage ); 122cdf0e10cSrcweir aIter++; 123cdf0e10cSrcweir } 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir void ImpDeleteHiddenSlides( const Reference< XModel >& rxModel ) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir try 129cdf0e10cSrcweir { 130cdf0e10cSrcweir Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW ); 131cdf0e10cSrcweir Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW ); 132cdf0e10cSrcweir for( sal_Int32 i = 0; i < xDrawPages->getCount(); i++ ) 133cdf0e10cSrcweir { 134cdf0e10cSrcweir Reference< XDrawPage > xDrawPage( xDrawPages->getByIndex( i ), UNO_QUERY_THROW ); 135cdf0e10cSrcweir Reference< XPropertySet > xPropSet( xDrawPage, UNO_QUERY_THROW ); 136cdf0e10cSrcweir 137cdf0e10cSrcweir sal_Bool bVisible = sal_True; 138cdf0e10cSrcweir const OUString sVisible( RTL_CONSTASCII_USTRINGPARAM( "Visible" ) ); 139cdf0e10cSrcweir if ( xPropSet->getPropertyValue( sVisible ) >>= bVisible ) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir if (!bVisible ) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir xDrawPages->remove( xDrawPage ); 144cdf0e10cSrcweir i--; 145cdf0e10cSrcweir } 146cdf0e10cSrcweir } 147cdf0e10cSrcweir } 148cdf0e10cSrcweir } 149cdf0e10cSrcweir catch( Exception& ) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir } 152cdf0e10cSrcweir } 153cdf0e10cSrcweir 154cdf0e10cSrcweir void ImpDeleteNotesPages( const Reference< XModel >& rxModel ) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir try 157cdf0e10cSrcweir { 158cdf0e10cSrcweir Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW ); 159cdf0e10cSrcweir Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW ); 160cdf0e10cSrcweir sal_Int32 i, nPages = xDrawPages->getCount(); 161cdf0e10cSrcweir for( i = 0; i < nPages; i++ ) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir Reference< XPresentationPage > xPresentationPage( xDrawPages->getByIndex( i ), UNO_QUERY_THROW ); 164cdf0e10cSrcweir Reference< XPropertySet > xPropSet( xPresentationPage->getNotesPage(), UNO_QUERY_THROW ); 165cdf0e10cSrcweir Reference< XShapes > xShapes( xPropSet, UNO_QUERY_THROW ); 166cdf0e10cSrcweir while( xShapes->getCount() ) 167cdf0e10cSrcweir xShapes->remove( Reference< XShape >( xShapes->getByIndex( xShapes->getCount() - 1 ), UNO_QUERY_THROW ) ); 168cdf0e10cSrcweir 169cdf0e10cSrcweir const OUString sLayout( RTL_CONSTASCII_USTRINGPARAM( "Layout" ) ); 170cdf0e10cSrcweir xPropSet->setPropertyValue( sLayout, Any( (sal_Int16)21 ) ); 171cdf0e10cSrcweir } 172cdf0e10cSrcweir } 173cdf0e10cSrcweir catch( Exception& ) 174cdf0e10cSrcweir { 175cdf0e10cSrcweir } 176cdf0e10cSrcweir } 177cdf0e10cSrcweir 178cdf0e10cSrcweir void ImpConvertOLE( const Reference< XModel >& rxModel, sal_Int32 nOLEOptimizationType ) 179cdf0e10cSrcweir { 180cdf0e10cSrcweir try 181cdf0e10cSrcweir { 182cdf0e10cSrcweir Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW ); 183cdf0e10cSrcweir Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW ); 184cdf0e10cSrcweir for ( sal_Int32 i = 0; i < xDrawPages->getCount(); i++ ) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir Reference< XShapes > xShapes( xDrawPages->getByIndex( i ), UNO_QUERY_THROW ); 187cdf0e10cSrcweir for ( sal_Int32 j = 0; j < xShapes->getCount(); j++ ) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir const OUString sOLE2Shape( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.OLE2Shape" ) ); 190cdf0e10cSrcweir Reference< XShape > xShape( xShapes->getByIndex( j ), UNO_QUERY_THROW ); 191cdf0e10cSrcweir if ( xShape->getShapeType() == sOLE2Shape ) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir Reference< XPropertySet > xPropSet( xShape, UNO_QUERY_THROW ); 194cdf0e10cSrcweir 195cdf0e10cSrcweir sal_Bool bConvertOLE = nOLEOptimizationType == 0; 196cdf0e10cSrcweir if ( nOLEOptimizationType == 1 ) 197cdf0e10cSrcweir { 198cdf0e10cSrcweir sal_Bool bIsInternal = sal_True; 199cdf0e10cSrcweir xPropSet->getPropertyValue( TKGet( TK_IsInternal ) ) >>= bIsInternal; 200cdf0e10cSrcweir bConvertOLE = !bIsInternal; 201cdf0e10cSrcweir } 202cdf0e10cSrcweir if ( bConvertOLE ) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir Reference< XGraphic > xGraphic; 205cdf0e10cSrcweir if ( xPropSet->getPropertyValue( TKGet( TK_Graphic ) ) >>= xGraphic ) 206cdf0e10cSrcweir { 207cdf0e10cSrcweir const OUString sGraphicShape( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.GraphicObjectShape" ) ); 208cdf0e10cSrcweir Reference< XMultiServiceFactory > xFact( rxModel, UNO_QUERY_THROW ); 209cdf0e10cSrcweir Reference< XShape > xShape2( xFact->createInstance( sGraphicShape ), UNO_QUERY_THROW ); 210cdf0e10cSrcweir xShapes->add( xShape2 ); 211cdf0e10cSrcweir xShape2->setPosition( xShape->getPosition() ); 212cdf0e10cSrcweir xShape2->setSize( xShape->getSize() ); 213cdf0e10cSrcweir Reference< XPropertySet > xPropSet2( xShape2, UNO_QUERY_THROW ); 214cdf0e10cSrcweir xPropSet2->setPropertyValue( TKGet( TK_Graphic ), Any( xGraphic ) ); 215cdf0e10cSrcweir xShapes->remove( xShape ); 216cdf0e10cSrcweir xPropSet2->setPropertyValue( TKGet( TK_ZOrder ), Any( j ) ); 217cdf0e10cSrcweir } 218cdf0e10cSrcweir } 219cdf0e10cSrcweir } 220cdf0e10cSrcweir } 221cdf0e10cSrcweir } 222cdf0e10cSrcweir } 223cdf0e10cSrcweir catch( Exception& ) 224cdf0e10cSrcweir { 225cdf0e10cSrcweir } 226cdf0e10cSrcweir } 227cdf0e10cSrcweir 228cdf0e10cSrcweir void ImpCompressGraphic( Reference< XGraphicProvider >& rxGraphicProvider, const Reference< XGraphic >& rxGraphic, Reference< XOutputStream >& rxOutputStream, 229cdf0e10cSrcweir const OUString& rDestMimeType, const awt::Size& rLogicalSize, sal_Int32 nJPEGQuality, sal_Int32 nImageResolution, sal_Bool bRemoveCropping, const text::GraphicCrop& rGraphicCropLogic ) 230cdf0e10cSrcweir { 231cdf0e10cSrcweir try 232cdf0e10cSrcweir { 233cdf0e10cSrcweir if ( rxGraphicProvider.is() && rxOutputStream.is() ) 234cdf0e10cSrcweir { 235cdf0e10cSrcweir Sequence< PropertyValue > aFilterData( 8 ); 236cdf0e10cSrcweir aFilterData[ 0 ].Name = TKGet( TK_ImageResolution ); 237cdf0e10cSrcweir aFilterData[ 0 ].Value <<= nImageResolution; 238cdf0e10cSrcweir aFilterData[ 1 ].Name = TKGet( TK_ColorMode ); // todo: jpeg color mode (0->true color, 1->greyscale) 239cdf0e10cSrcweir aFilterData[ 1 ].Value <<= (sal_Int32)0; 240cdf0e10cSrcweir aFilterData[ 2 ].Name = TKGet( TK_Quality ); // quality that is used if we export to jpeg 241cdf0e10cSrcweir aFilterData[ 2 ].Value <<= nJPEGQuality; 242cdf0e10cSrcweir aFilterData[ 3 ].Name = TKGet( TK_Compression ); // compression that is used if we export to png 243cdf0e10cSrcweir aFilterData[ 3 ].Value <<= (sal_Int32)6; 244cdf0e10cSrcweir aFilterData[ 4 ].Name = TKGet( TK_Interlaced ); // interlaced is turned off if we export to png 245cdf0e10cSrcweir aFilterData[ 4 ].Value <<= (sal_Int32)0; 246cdf0e10cSrcweir aFilterData[ 5 ].Name = TKGet( TK_LogicalSize ); 247cdf0e10cSrcweir aFilterData[ 5 ].Value <<= rLogicalSize; 248cdf0e10cSrcweir aFilterData[ 6 ].Name = TKGet( TK_RemoveCropArea ); 249cdf0e10cSrcweir aFilterData[ 6 ].Value <<= bRemoveCropping; 250cdf0e10cSrcweir aFilterData[ 7 ].Name = TKGet( TK_GraphicCropLogic ); 251cdf0e10cSrcweir aFilterData[ 7 ].Value <<= rGraphicCropLogic; 252cdf0e10cSrcweir 253cdf0e10cSrcweir Sequence< PropertyValue > aArgs( 3 ); 254cdf0e10cSrcweir aArgs[ 0 ].Name = TKGet( TK_MimeType ); // the GraphicProvider is using "MimeType", the GraphicExporter "MediaType"... 255cdf0e10cSrcweir aArgs[ 0 ].Value <<= rDestMimeType; 256cdf0e10cSrcweir aArgs[ 1 ].Name = TKGet( TK_OutputStream ); 257cdf0e10cSrcweir aArgs[ 1 ].Value <<= rxOutputStream; 258cdf0e10cSrcweir aArgs[ 2 ].Name = TKGet( TK_FilterData ); 259cdf0e10cSrcweir aArgs[ 2 ].Value <<= aFilterData; 260cdf0e10cSrcweir 261cdf0e10cSrcweir rxGraphicProvider->storeGraphic( rxGraphic, aArgs ); 262cdf0e10cSrcweir } 263cdf0e10cSrcweir } 264cdf0e10cSrcweir catch( Exception& ) 265cdf0e10cSrcweir { 266cdf0e10cSrcweir } 267cdf0e10cSrcweir } 268cdf0e10cSrcweir 269cdf0e10cSrcweir Reference< XGraphic > ImpCompressGraphic( const Reference< XComponentContext >& rxMSF, 270cdf0e10cSrcweir const Reference< XGraphic >& xGraphic, const awt::Size& aLogicalSize, const text::GraphicCrop& aGraphicCropLogic, 271cdf0e10cSrcweir const GraphicSettings& rGraphicSettings ) 272cdf0e10cSrcweir { 273cdf0e10cSrcweir Reference< XGraphic > xNewGraphic; 274cdf0e10cSrcweir try 275cdf0e10cSrcweir { 276cdf0e10cSrcweir OUString aSourceMimeType; 277cdf0e10cSrcweir Reference< XPropertySet > xGraphicPropertySet( xGraphic, UNO_QUERY_THROW ); 278cdf0e10cSrcweir if ( xGraphicPropertySet->getPropertyValue( TKGet( TK_MimeType ) ) >>= aSourceMimeType ) 279cdf0e10cSrcweir { 280cdf0e10cSrcweir sal_Int8 nGraphicType( xGraphic->getType() ); 281cdf0e10cSrcweir if ( nGraphicType == com::sun::star::graphic::GraphicType::PIXEL ) 282cdf0e10cSrcweir { 283cdf0e10cSrcweir sal_Bool bTransparent = sal_False; 284cdf0e10cSrcweir sal_Bool bAlpha = sal_False; 285cdf0e10cSrcweir sal_Bool bAnimated = sal_False; 286cdf0e10cSrcweir 287cdf0e10cSrcweir awt::Size aSourceSizePixel( 0, 0 ); 288cdf0e10cSrcweir text::GraphicCrop aGraphicCropPixel( 0, 0, 0, 0 ); 289cdf0e10cSrcweir 290cdf0e10cSrcweir if ( ( xGraphicPropertySet->getPropertyValue( TKGet( TK_SizePixel ) ) >>= aSourceSizePixel ) && 291cdf0e10cSrcweir ( xGraphicPropertySet->getPropertyValue( TKGet( TK_Transparent ) ) >>= bTransparent ) && 292cdf0e10cSrcweir ( xGraphicPropertySet->getPropertyValue( TKGet( TK_Alpha ) ) >>= bAlpha ) && 293cdf0e10cSrcweir ( xGraphicPropertySet->getPropertyValue( TKGet( TK_Animated ) ) >>= bAnimated ) ) 294cdf0e10cSrcweir { 295cdf0e10cSrcweir awt::Size aDestSizePixel( aSourceSizePixel ); 296cdf0e10cSrcweir if ( !bAnimated ) 297cdf0e10cSrcweir { 298cdf0e10cSrcweir sal_Bool bNeedsOptimizing = sal_False; 299cdf0e10cSrcweir sal_Bool bRemoveCropArea( rGraphicSettings.mbRemoveCropArea ); 300cdf0e10cSrcweir 301cdf0e10cSrcweir // cropping has to be removed from SourceSizePixel 302cdf0e10cSrcweir if ( aGraphicCropLogic.Left || aGraphicCropLogic.Top || aGraphicCropLogic.Right || aGraphicCropLogic.Bottom ) 303cdf0e10cSrcweir { 304cdf0e10cSrcweir const awt::Size aSize100thMM( GraphicCollector::GetOriginalSize( rxMSF, xGraphic ) ); 305cdf0e10cSrcweir 306cdf0e10cSrcweir if ( bRemoveCropArea ) 307cdf0e10cSrcweir bNeedsOptimizing = sal_True; 308cdf0e10cSrcweir 309cdf0e10cSrcweir if ( aSize100thMM.Width && aSize100thMM.Height ) 310cdf0e10cSrcweir { 311cdf0e10cSrcweir aGraphicCropPixel.Left = static_cast< sal_Int32 >( ( (double)aSourceSizePixel.Width * aGraphicCropLogic.Left ) / aSize100thMM.Width ); 312cdf0e10cSrcweir aGraphicCropPixel.Top = static_cast< sal_Int32 >( ( (double)aSourceSizePixel.Height* aGraphicCropLogic.Top ) / aSize100thMM.Height ); 313cdf0e10cSrcweir aGraphicCropPixel.Right = static_cast< sal_Int32 >( ( (double)aSourceSizePixel.Width * ( aSize100thMM.Width - aGraphicCropLogic.Right ) ) / aSize100thMM.Width ); 314cdf0e10cSrcweir aGraphicCropPixel.Bottom = static_cast< sal_Int32 >( ( (double)aSourceSizePixel.Height* ( aSize100thMM.Height - aGraphicCropLogic.Bottom ) ) / aSize100thMM.Height ); 315cdf0e10cSrcweir 316cdf0e10cSrcweir // first calculating new SourceSizePixel by removing the cropped area 317cdf0e10cSrcweir aSourceSizePixel.Width = aGraphicCropPixel.Right - aGraphicCropPixel.Left; 318cdf0e10cSrcweir aSourceSizePixel.Height= aGraphicCropPixel.Bottom - aGraphicCropPixel.Top; 319cdf0e10cSrcweir } 320cdf0e10cSrcweir else 321cdf0e10cSrcweir { 322cdf0e10cSrcweir bRemoveCropArea = sal_False; 323cdf0e10cSrcweir } 324cdf0e10cSrcweir } 325cdf0e10cSrcweir if ( ( aSourceSizePixel.Width > 0 ) && ( aSourceSizePixel.Height > 0 ) ) 326cdf0e10cSrcweir { 327cdf0e10cSrcweir OUString aDestMimeType( RTL_CONSTASCII_USTRINGPARAM( "image/png" ) ); 328cdf0e10cSrcweir if ( rGraphicSettings.mbJPEGCompression && !bTransparent && !bAlpha && !bAnimated ) 329cdf0e10cSrcweir { 330cdf0e10cSrcweir aDestMimeType = OUString( RTL_CONSTASCII_USTRINGPARAM( "image/jpeg" ) ); 331cdf0e10cSrcweir // if( aSourceMimeType != aDestMimeType ) 332cdf0e10cSrcweir bNeedsOptimizing = sal_True; 333cdf0e10cSrcweir } 334cdf0e10cSrcweir if ( bRemoveCropArea ) 335cdf0e10cSrcweir aDestSizePixel = aSourceSizePixel; 336cdf0e10cSrcweir if ( rGraphicSettings.mnImageResolution && aLogicalSize.Width && aLogicalSize.Height ) 337cdf0e10cSrcweir { 338cdf0e10cSrcweir const double fSourceDPIX = ((double)aSourceSizePixel.Width / ((double)aLogicalSize.Width / 2540.0 )); 339cdf0e10cSrcweir const double fSourceDPIY = ((double)aSourceSizePixel.Height/ ((double)aLogicalSize.Height/ 2540.0 )); 340cdf0e10cSrcweir 341cdf0e10cSrcweir // check, if the bitmap DPI exceeds the maximum DPI 342cdf0e10cSrcweir if( ( fSourceDPIX > rGraphicSettings.mnImageResolution ) || ( fSourceDPIY > rGraphicSettings.mnImageResolution ) ) 343cdf0e10cSrcweir { 344cdf0e10cSrcweir const double fNewSizePixelX = ((double)aDestSizePixel.Width * rGraphicSettings.mnImageResolution ) / fSourceDPIX; 345cdf0e10cSrcweir const double fNewSizePixelY = ((double)aDestSizePixel.Height* rGraphicSettings.mnImageResolution ) / fSourceDPIY; 346cdf0e10cSrcweir 347cdf0e10cSrcweir aDestSizePixel = awt::Size( (sal_Int32)fNewSizePixelX, (sal_Int32)fNewSizePixelY ); 348cdf0e10cSrcweir bNeedsOptimizing = sal_True; 349cdf0e10cSrcweir } 350cdf0e10cSrcweir } 351cdf0e10cSrcweir if ( bNeedsOptimizing && aDestSizePixel.Width && aDestSizePixel.Height ) 352cdf0e10cSrcweir { 353cdf0e10cSrcweir Reference< XStream > xTempFile( rxMSF->getServiceManager()->createInstanceWithContext( OUString::createFromAscii( "com.sun.star.io.TempFile" ), rxMSF ), UNO_QUERY_THROW ); 354cdf0e10cSrcweir Reference< XOutputStream > xOutputStream( xTempFile->getOutputStream() ); 355cdf0e10cSrcweir Reference< XGraphicProvider > xGraphicProvider( rxMSF->getServiceManager()->createInstanceWithContext( OUString::createFromAscii( "com.sun.star.graphic.GraphicProvider" ), rxMSF ), UNO_QUERY_THROW ); 356cdf0e10cSrcweir 357cdf0e10cSrcweir ImpCompressGraphic( xGraphicProvider, xGraphic, xOutputStream, aDestMimeType, aLogicalSize, rGraphicSettings.mnJPEGQuality, rGraphicSettings.mnImageResolution, bRemoveCropArea, aGraphicCropLogic ); 358cdf0e10cSrcweir Reference< XInputStream > xInputStream( xTempFile->getInputStream() ); 359cdf0e10cSrcweir Reference< XSeekable > xSeekable( xInputStream, UNO_QUERY_THROW ); 360cdf0e10cSrcweir xSeekable->seek( 0 ); 361cdf0e10cSrcweir Sequence< PropertyValue > aArgs( 1 ); 362cdf0e10cSrcweir aArgs[ 0 ].Name = TKGet( TK_InputStream ); 363cdf0e10cSrcweir aArgs[ 0 ].Value <<= xInputStream; 364cdf0e10cSrcweir xNewGraphic = xGraphicProvider->queryGraphic( aArgs ); 365cdf0e10cSrcweir } 366cdf0e10cSrcweir } 367cdf0e10cSrcweir } 368cdf0e10cSrcweir } 369cdf0e10cSrcweir } 370cdf0e10cSrcweir else // this is a metafile 371cdf0e10cSrcweir { 372cdf0e10cSrcweir rtl::OUString aDestMimeType( aSourceMimeType ); 373cdf0e10cSrcweir Reference< XStream > xTempFile( rxMSF->getServiceManager()->createInstanceWithContext( OUString::createFromAscii( "com.sun.star.io.TempFile" ), rxMSF ), UNO_QUERY_THROW ); 374cdf0e10cSrcweir Reference< XOutputStream > xOutputStream( xTempFile->getOutputStream() ); 375cdf0e10cSrcweir Reference< XGraphicProvider > xGraphicProvider( rxMSF->getServiceManager()->createInstanceWithContext( OUString::createFromAscii( "com.sun.star.graphic.GraphicProvider" ), rxMSF ), UNO_QUERY_THROW ); 376cdf0e10cSrcweir ImpCompressGraphic( xGraphicProvider, xGraphic, xOutputStream, aDestMimeType, aLogicalSize, rGraphicSettings.mnJPEGQuality, rGraphicSettings.mnImageResolution, sal_False, aGraphicCropLogic ); 377cdf0e10cSrcweir Reference< XInputStream > xInputStream( xTempFile->getInputStream() ); 378cdf0e10cSrcweir Reference< XSeekable > xSeekable( xInputStream, UNO_QUERY_THROW ); 379cdf0e10cSrcweir xSeekable->seek( 0 ); 380cdf0e10cSrcweir Sequence< PropertyValue > aArgs( 1 ); 381cdf0e10cSrcweir aArgs[ 0 ].Name = TKGet( TK_InputStream ); 382cdf0e10cSrcweir aArgs[ 0 ].Value <<= xInputStream; 383cdf0e10cSrcweir xNewGraphic = xGraphicProvider->queryGraphic( aArgs ); 384cdf0e10cSrcweir } 385cdf0e10cSrcweir } 386cdf0e10cSrcweir } 387cdf0e10cSrcweir catch( Exception& ) 388cdf0e10cSrcweir { 389cdf0e10cSrcweir } 390cdf0e10cSrcweir return xNewGraphic; 391cdf0e10cSrcweir } 392cdf0e10cSrcweir 393cdf0e10cSrcweir void CompressGraphics( ImpOptimizer& rOptimizer, const Reference< XComponentContext >& rxMSF, const GraphicSettings& rGraphicSettings, 394cdf0e10cSrcweir std::vector< GraphicCollector::GraphicEntity >& rGraphicList ) 395cdf0e10cSrcweir { 396cdf0e10cSrcweir try 397cdf0e10cSrcweir { 398cdf0e10cSrcweir std::vector< GraphicCollector::GraphicEntity >::iterator aGraphicIter( rGraphicList.begin() ); 399cdf0e10cSrcweir std::vector< GraphicCollector::GraphicEntity >::iterator aGraphicIEnd( rGraphicList.end() ); 400cdf0e10cSrcweir double i = 0; 401cdf0e10cSrcweir while( aGraphicIter != aGraphicIEnd ) 402cdf0e10cSrcweir { 403cdf0e10cSrcweir i++; 404cdf0e10cSrcweir sal_Int32 nProgress = static_cast< sal_Int32 >( 40.0 * ( i / static_cast< double >( rGraphicList.size() ) ) ) + 50; 405cdf0e10cSrcweir rOptimizer.SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( nProgress ) ) ); 406cdf0e10cSrcweir rOptimizer.DispatchStatus(); 407cdf0e10cSrcweir 408cdf0e10cSrcweir if ( aGraphicIter->maUser.size() ) 409cdf0e10cSrcweir { 410cdf0e10cSrcweir GraphicSettings aGraphicSettings( rGraphicSettings ); 411cdf0e10cSrcweir aGraphicSettings.mbRemoveCropArea = aGraphicIter->mbRemoveCropArea; 412cdf0e10cSrcweir 413cdf0e10cSrcweir Reference< XGraphic > xGraphic; 414cdf0e10cSrcweir if ( aGraphicIter->maUser[ 0 ].mbFillBitmap && aGraphicIter->maUser[ 0 ].mxPropertySet.is() ) 415cdf0e10cSrcweir { 416cdf0e10cSrcweir Reference< XBitmap > xFillBitmap; 417cdf0e10cSrcweir if ( aGraphicIter->maUser[ 0 ].mxPropertySet->getPropertyValue( TKGet( TK_FillBitmap ) ) >>= xFillBitmap ) 418cdf0e10cSrcweir xGraphic = Reference< XGraphic >( xFillBitmap, UNO_QUERY_THROW ); 419cdf0e10cSrcweir } 420cdf0e10cSrcweir else if ( aGraphicIter->maUser[ 0 ].mxShape.is() ) 421cdf0e10cSrcweir { 422cdf0e10cSrcweir Reference< XPropertySet > xShapePropertySet( aGraphicIter->maUser[ 0 ].mxShape, UNO_QUERY_THROW ); 423cdf0e10cSrcweir xShapePropertySet->getPropertyValue( TKGet( TK_Graphic ) ) >>= xGraphic; 424cdf0e10cSrcweir } 425cdf0e10cSrcweir if ( xGraphic.is() ) 426cdf0e10cSrcweir { 427cdf0e10cSrcweir Reference< XPropertySet > xNewGraphicPropertySet( xGraphic, UNO_QUERY_THROW ); 428cdf0e10cSrcweir awt::Size aSize100thMM( GraphicCollector::GetOriginalSize( rxMSF, xGraphic ) ); 429cdf0e10cSrcweir Reference< XGraphic > xNewGraphic( ImpCompressGraphic( rxMSF, xGraphic, aGraphicIter->maLogicalSize, aGraphicIter->maGraphicCropLogic, aGraphicSettings ) ); 430cdf0e10cSrcweir if ( xNewGraphic.is() ) 431cdf0e10cSrcweir { 432cdf0e10cSrcweir // applying graphic to each user 433cdf0e10cSrcweir std::vector< GraphicCollector::GraphicUser >::iterator aGraphicUserIter( aGraphicIter->maUser.begin() ); 434cdf0e10cSrcweir while( aGraphicUserIter != aGraphicIter->maUser.end() ) 435cdf0e10cSrcweir { 436cdf0e10cSrcweir if ( aGraphicUserIter->mxShape.is() ) 437cdf0e10cSrcweir { 438cdf0e10cSrcweir rtl::OUString sEmptyGraphicURL; 439cdf0e10cSrcweir Reference< XPropertySet > xShapePropertySet( aGraphicUserIter->mxShape, UNO_QUERY_THROW ); 440cdf0e10cSrcweir xShapePropertySet->setPropertyValue( TKGet( TK_GraphicURL ), Any( sEmptyGraphicURL ) ); 441cdf0e10cSrcweir xShapePropertySet->setPropertyValue( TKGet( TK_Graphic ), Any( xNewGraphic ) ); 442cdf0e10cSrcweir 443cdf0e10cSrcweir if ( aGraphicUserIter->maGraphicCropLogic.Left || aGraphicUserIter->maGraphicCropLogic.Top 444cdf0e10cSrcweir || aGraphicUserIter->maGraphicCropLogic.Right || aGraphicUserIter->maGraphicCropLogic.Bottom ) 445cdf0e10cSrcweir { // removing crop area was not possible or should't been applied 446cdf0e10cSrcweir text::GraphicCrop aGraphicCropLogic( 0, 0, 0, 0 ); 447cdf0e10cSrcweir if ( !aGraphicSettings.mbRemoveCropArea ) 448cdf0e10cSrcweir { 449cdf0e10cSrcweir awt::Size aNewSize( GraphicCollector::GetOriginalSize( rxMSF, xNewGraphic ) ); 450cdf0e10cSrcweir aGraphicCropLogic.Left = (sal_Int32)((double)aGraphicUserIter->maGraphicCropLogic.Left * ((double)aNewSize.Width / (double)aSize100thMM.Width)); 451cdf0e10cSrcweir aGraphicCropLogic.Top = (sal_Int32)((double)aGraphicUserIter->maGraphicCropLogic.Top * ((double)aNewSize.Height / (double)aSize100thMM.Height)); 452cdf0e10cSrcweir aGraphicCropLogic.Right = (sal_Int32)((double)aGraphicUserIter->maGraphicCropLogic.Right * ((double)aNewSize.Width / (double)aSize100thMM.Width)); 453cdf0e10cSrcweir aGraphicCropLogic.Bottom = (sal_Int32)((double)aGraphicUserIter->maGraphicCropLogic.Bottom * ((double)aNewSize.Height / (double)aSize100thMM.Height)); 454cdf0e10cSrcweir } 455cdf0e10cSrcweir xShapePropertySet->setPropertyValue( TKGet( TK_GraphicCrop ), Any( aGraphicCropLogic ) ); 456cdf0e10cSrcweir } 457cdf0e10cSrcweir } 458cdf0e10cSrcweir else if ( aGraphicUserIter->mxPropertySet.is() ) 459cdf0e10cSrcweir { 460cdf0e10cSrcweir Reference< XBitmap > xFillBitmap( xNewGraphic, UNO_QUERY ); 461cdf0e10cSrcweir if ( xFillBitmap.is() ) 462cdf0e10cSrcweir { 463cdf0e10cSrcweir awt::Size aSize; 464cdf0e10cSrcweir sal_Bool bLogicalSize; 465cdf0e10cSrcweir 466cdf0e10cSrcweir Reference< XPropertySet >& rxPropertySet( aGraphicUserIter->mxPropertySet ); 467cdf0e10cSrcweir rxPropertySet->setPropertyValue( TKGet( TK_FillBitmap ), Any( xFillBitmap ) ); 468cdf0e10cSrcweir if ( ( rxPropertySet->getPropertyValue( TKGet( TK_FillBitmapLogicalSize ) ) >>= bLogicalSize ) 469cdf0e10cSrcweir && ( rxPropertySet->getPropertyValue( TKGet( TK_FillBitmapSizeX ) ) >>= aSize.Width ) 470cdf0e10cSrcweir && ( rxPropertySet->getPropertyValue( TKGet( TK_FillBitmapSizeY ) ) >>= aSize.Height ) ) 471cdf0e10cSrcweir { 472cdf0e10cSrcweir if ( !aSize.Width || !aSize.Height ) 473cdf0e10cSrcweir { 474cdf0e10cSrcweir rxPropertySet->setPropertyValue( TKGet( TK_FillBitmapLogicalSize ), Any( sal_True ) ); 475cdf0e10cSrcweir rxPropertySet->setPropertyValue( TKGet( TK_FillBitmapSizeX ), Any( aGraphicUserIter->maLogicalSize.Width ) ); 476cdf0e10cSrcweir rxPropertySet->setPropertyValue( TKGet( TK_FillBitmapSizeY ), Any( aGraphicUserIter->maLogicalSize.Height ) ); 477cdf0e10cSrcweir } 478cdf0e10cSrcweir } 479cdf0e10cSrcweir if ( aGraphicUserIter->mxPagePropertySet.is() ) 480cdf0e10cSrcweir aGraphicUserIter->mxPagePropertySet->setPropertyValue( TKGet( TK_Background ), Any( rxPropertySet ) ); 481cdf0e10cSrcweir } 482cdf0e10cSrcweir } 483cdf0e10cSrcweir aGraphicUserIter++; 484cdf0e10cSrcweir } 485cdf0e10cSrcweir } 486cdf0e10cSrcweir } 487cdf0e10cSrcweir } 488cdf0e10cSrcweir aGraphicIter++; 489cdf0e10cSrcweir } 490cdf0e10cSrcweir } 491cdf0e10cSrcweir catch ( Exception& ) 492cdf0e10cSrcweir { 493cdf0e10cSrcweir } 494cdf0e10cSrcweir } 495cdf0e10cSrcweir 496cdf0e10cSrcweir // ---------------- 497cdf0e10cSrcweir // - ImpOptimizer - 498cdf0e10cSrcweir // ---------------- 499cdf0e10cSrcweir 500cdf0e10cSrcweir ImpOptimizer::ImpOptimizer( const Reference< XComponentContext >& rxMSF, const Reference< XModel >& rxModel ) : 501cdf0e10cSrcweir mxMSF ( rxMSF ), 502cdf0e10cSrcweir mxModel ( rxModel ), 503cdf0e10cSrcweir mbJPEGCompression ( sal_False ), 504cdf0e10cSrcweir mnJPEGQuality ( 90 ), 505cdf0e10cSrcweir mbRemoveCropArea ( sal_False ), 506cdf0e10cSrcweir mnImageResolution ( 0 ), 507cdf0e10cSrcweir mbEmbedLinkedGraphics ( sal_True ), 508cdf0e10cSrcweir mbOLEOptimization ( sal_False ), 509cdf0e10cSrcweir mnOLEOptimizationType ( 0 ), 510cdf0e10cSrcweir mbDeleteUnusedMasterPages ( sal_False ), 511cdf0e10cSrcweir mbDeleteHiddenSlides ( sal_False ), 512cdf0e10cSrcweir mbDeleteNotesPages ( sal_False ), 513cdf0e10cSrcweir mbOpenNewDocument ( sal_True ) 514cdf0e10cSrcweir { 515cdf0e10cSrcweir } 516cdf0e10cSrcweir 517cdf0e10cSrcweir // ----------------------------------------------------------------------------- 518cdf0e10cSrcweir 519cdf0e10cSrcweir ImpOptimizer::~ImpOptimizer() 520cdf0e10cSrcweir { 521cdf0e10cSrcweir } 522cdf0e10cSrcweir 523cdf0e10cSrcweir // ----------------------------------------------------------------------------- 524cdf0e10cSrcweir 525cdf0e10cSrcweir void ImpOptimizer::DispatchStatus() 526cdf0e10cSrcweir { 527cdf0e10cSrcweir if ( mxStatusDispatcher.is() ) 528cdf0e10cSrcweir { 529cdf0e10cSrcweir URL aURL; 530cdf0e10cSrcweir aURL.Protocol = OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.com.sun.star.comp.SunPresentationMinimizer:" ) ); 531cdf0e10cSrcweir aURL.Path = OUString( RTL_CONSTASCII_USTRINGPARAM( "statusupdate" ) ); 532cdf0e10cSrcweir mxStatusDispatcher->dispatch( aURL, GetStatusSequence() ); 533cdf0e10cSrcweir } 534cdf0e10cSrcweir } 535cdf0e10cSrcweir 536cdf0e10cSrcweir // ----------------------------------------------------------------------------- 537cdf0e10cSrcweir 538cdf0e10cSrcweir sal_Bool ImpOptimizer::Optimize() 539cdf0e10cSrcweir { 540cdf0e10cSrcweir 541cdf0e10cSrcweir if ( maCustomShowName.getLength() ) 542cdf0e10cSrcweir ImpExtractCustomShow( mxModel, maCustomShowName ); 543cdf0e10cSrcweir 544cdf0e10cSrcweir if ( mbDeleteUnusedMasterPages ) 545cdf0e10cSrcweir { 546cdf0e10cSrcweir SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( 40 ) ) ); 547cdf0e10cSrcweir SetStatusValue( TK_Status, Any( TKGet( STR_DELETING_SLIDES ) ) ); 548cdf0e10cSrcweir DispatchStatus(); 549cdf0e10cSrcweir ImpDeleteUnusedMasterPages( mxModel ); 550cdf0e10cSrcweir } 551cdf0e10cSrcweir 552cdf0e10cSrcweir if ( mbDeleteHiddenSlides ) 553cdf0e10cSrcweir { 554cdf0e10cSrcweir SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( 40 ) ) ); 555cdf0e10cSrcweir SetStatusValue( TK_Status, Any( TKGet( STR_DELETING_SLIDES ) ) ); 556cdf0e10cSrcweir DispatchStatus(); 557cdf0e10cSrcweir ImpDeleteHiddenSlides( mxModel ); 558cdf0e10cSrcweir } 559cdf0e10cSrcweir 560cdf0e10cSrcweir if ( mbDeleteNotesPages ) 561cdf0e10cSrcweir { 562cdf0e10cSrcweir SetStatusValue( TK_Status, Any( TKGet( STR_DELETING_SLIDES ) ) ); 563cdf0e10cSrcweir DispatchStatus(); 564cdf0e10cSrcweir ImpDeleteNotesPages( mxModel ); 565cdf0e10cSrcweir } 566cdf0e10cSrcweir 567cdf0e10cSrcweir if ( mbOLEOptimization ) 568cdf0e10cSrcweir { 569cdf0e10cSrcweir SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( 45 ) ) ); 570cdf0e10cSrcweir SetStatusValue( TK_Status, Any( TKGet( STR_CREATING_OLE_REPLACEMENTS ) ) ); 571cdf0e10cSrcweir DispatchStatus(); 572cdf0e10cSrcweir ImpConvertOLE( mxModel, mnOLEOptimizationType ); 573cdf0e10cSrcweir } 574cdf0e10cSrcweir 575cdf0e10cSrcweir if ( mbJPEGCompression || mbRemoveCropArea || mnImageResolution ) 576cdf0e10cSrcweir { 577cdf0e10cSrcweir SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( 50 ) ) ); 578cdf0e10cSrcweir SetStatusValue( TK_Status, Any( TKGet( STR_OPTIMIZING_GRAPHICS ) ) ); 579cdf0e10cSrcweir DispatchStatus(); 580cdf0e10cSrcweir 581cdf0e10cSrcweir std::vector< GraphicCollector::GraphicEntity > aGraphicList; 582cdf0e10cSrcweir GraphicSettings aGraphicSettings( mbJPEGCompression, mnJPEGQuality, mbRemoveCropArea, mnImageResolution, mbEmbedLinkedGraphics ); 583cdf0e10cSrcweir GraphicCollector::CollectGraphics( mxMSF, mxModel, aGraphicSettings, aGraphicList ); 584cdf0e10cSrcweir CompressGraphics( *this, mxMSF, aGraphicSettings, aGraphicList ); 585cdf0e10cSrcweir } 586cdf0e10cSrcweir SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( 100 ) ) ); 587cdf0e10cSrcweir DispatchStatus(); 588cdf0e10cSrcweir return sal_True; 589cdf0e10cSrcweir } 590cdf0e10cSrcweir 591cdf0e10cSrcweir static void DispatchURL( Reference< XComponentContext > xMSF, OUString sURL, Reference< XFrame > xFrame ) 592cdf0e10cSrcweir { 593cdf0e10cSrcweir try 594cdf0e10cSrcweir { 595cdf0e10cSrcweir Reference< XURLTransformer > xURLTransformer( xMSF->getServiceManager()->createInstanceWithContext( 596cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.URLTransformer" ) ), xMSF ), UNO_QUERY_THROW ); 597cdf0e10cSrcweir util::URL aUrl; 598cdf0e10cSrcweir aUrl.Complete = sURL; 599cdf0e10cSrcweir xURLTransformer->parseStrict( aUrl ); 600cdf0e10cSrcweir Sequence< PropertyValue > aArgs; 601cdf0e10cSrcweir Reference< XDispatchProvider > xDispatchProvider( xFrame, UNO_QUERY_THROW ); 602cdf0e10cSrcweir Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aUrl, OUString(), 0 ); // "_self" 603cdf0e10cSrcweir if ( xDispatch.is() ) 604cdf0e10cSrcweir xDispatch->dispatch( aUrl, aArgs ); 605cdf0e10cSrcweir } 606cdf0e10cSrcweir catch( Exception& ) 607cdf0e10cSrcweir { 608cdf0e10cSrcweir } 609cdf0e10cSrcweir } 610cdf0e10cSrcweir 611cdf0e10cSrcweir // ----------------------------------------------------------------------------- 612cdf0e10cSrcweir 613cdf0e10cSrcweir sal_Bool ImpOptimizer::Optimize( const Sequence< PropertyValue >& rArguments ) 614cdf0e10cSrcweir { 615cdf0e10cSrcweir sal_Bool bRet = sal_True; 616cdf0e10cSrcweir 617cdf0e10cSrcweir if ( mxModel.is() ) 618cdf0e10cSrcweir { 619cdf0e10cSrcweir sal_Int64 nEstimatedFileSize = 0; 620cdf0e10cSrcweir SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( 0 ) ) ); 621cdf0e10cSrcweir DispatchStatus(); 622cdf0e10cSrcweir 623cdf0e10cSrcweir int i, nICount; 624cdf0e10cSrcweir for ( i = 0, nICount = rArguments.getLength(); i < nICount; i++ ) 625cdf0e10cSrcweir { 626cdf0e10cSrcweir switch( TKGet( rArguments[ i ].Name ) ) 627cdf0e10cSrcweir { 628cdf0e10cSrcweir case TK_StatusDispatcher : rArguments[ i ].Value >>= mxStatusDispatcher; break; 629cdf0e10cSrcweir case TK_InformationDialog: rArguments[ i ].Value >>= mxInformationDialog; break; 630cdf0e10cSrcweir case TK_Settings : 631cdf0e10cSrcweir { 632cdf0e10cSrcweir com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > aSettings; 633cdf0e10cSrcweir int j, nJCount; 634cdf0e10cSrcweir rArguments[ i ].Value >>= aSettings; 635cdf0e10cSrcweir for ( j = 0, nJCount = aSettings.getLength(); j < nJCount; j++ ) 636cdf0e10cSrcweir { 637cdf0e10cSrcweir switch( TKGet( aSettings[ j ].Name ) ) 638cdf0e10cSrcweir { 639cdf0e10cSrcweir case TK_JPEGCompression : aSettings[ j ].Value >>= mbJPEGCompression; break; 640cdf0e10cSrcweir case TK_JPEGQuality : aSettings[ j ].Value >>= mnJPEGQuality; break; 641cdf0e10cSrcweir case TK_RemoveCropArea : aSettings[ j ].Value >>= mbRemoveCropArea; break; 642cdf0e10cSrcweir case TK_ImageResolution : aSettings[ j ].Value >>= mnImageResolution; break; 643cdf0e10cSrcweir case TK_EmbedLinkedGraphics : aSettings[ j ].Value >>= mbEmbedLinkedGraphics; break; 644cdf0e10cSrcweir case TK_OLEOptimization : aSettings[ j ].Value >>= mbOLEOptimization; break; 645cdf0e10cSrcweir case TK_OLEOptimizationType : aSettings[ j ].Value >>= mnOLEOptimizationType; break; 646cdf0e10cSrcweir case TK_CustomShowName : aSettings[ j ].Value >>= maCustomShowName; break; 647cdf0e10cSrcweir case TK_DeleteUnusedMasterPages : aSettings[ j ].Value >>= mbDeleteUnusedMasterPages; break; 648cdf0e10cSrcweir case TK_DeleteHiddenSlides : aSettings[ j ].Value >>= mbDeleteHiddenSlides; break; 649cdf0e10cSrcweir case TK_DeleteNotesPages : aSettings[ j ].Value >>= mbDeleteNotesPages; break; 650cdf0e10cSrcweir case TK_SaveAsURL : aSettings[ j ].Value >>= maSaveAsURL; break; 651cdf0e10cSrcweir case TK_FilterName : aSettings[ j ].Value >>= maFilterName; break; 652cdf0e10cSrcweir case TK_OpenNewDocument : aSettings[ j ].Value >>= mbOpenNewDocument; break; 653cdf0e10cSrcweir case TK_EstimatedFileSize : aSettings[ j ].Value >>= nEstimatedFileSize; break; 654cdf0e10cSrcweir default: break; 655cdf0e10cSrcweir } 656cdf0e10cSrcweir } 657cdf0e10cSrcweir } 658cdf0e10cSrcweir break; 659cdf0e10cSrcweir default: break; 660cdf0e10cSrcweir } 661cdf0e10cSrcweir } 662cdf0e10cSrcweir 663cdf0e10cSrcweir sal_Int64 nSourceSize = 0; 664cdf0e10cSrcweir sal_Int64 nDestSize = 0; 665cdf0e10cSrcweir 666cdf0e10cSrcweir Reference< XFrame > xSelf; 667cdf0e10cSrcweir if ( maSaveAsURL.getLength() ) 668cdf0e10cSrcweir { 669cdf0e10cSrcweir 670cdf0e10cSrcweir SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( 10 ) ) ); 671cdf0e10cSrcweir SetStatusValue( TK_Status, Any( TKGet( STR_DUPLICATING_PRESENTATION ) ) ); 672cdf0e10cSrcweir DispatchStatus(); 673cdf0e10cSrcweir 674cdf0e10cSrcweir Reference< XStorable >xStorable( mxModel, UNO_QUERY ); 675cdf0e10cSrcweir if ( xStorable.is() ) 676cdf0e10cSrcweir { 677cdf0e10cSrcweir if ( xStorable->hasLocation() ) 678cdf0e10cSrcweir nSourceSize = PPPOptimizer::GetFileSize( xStorable->getLocation() ); 679cdf0e10cSrcweir 680cdf0e10cSrcweir Sequence< PropertyValue > aArguments; 681cdf0e10cSrcweir if ( maFilterName.getLength() ) 682cdf0e10cSrcweir { 683cdf0e10cSrcweir int nLength = aArguments.getLength(); 684cdf0e10cSrcweir aArguments.realloc( nLength + 1 ); 685cdf0e10cSrcweir aArguments[ nLength ].Name = TKGet( TK_FilterName ); 686cdf0e10cSrcweir aArguments[ nLength ].Value <<= maFilterName; 687cdf0e10cSrcweir } 688cdf0e10cSrcweir xStorable->storeToURL( maSaveAsURL, aArguments ); 689cdf0e10cSrcweir if ( !nSourceSize ) 690cdf0e10cSrcweir nSourceSize = PPPOptimizer::GetFileSize( maSaveAsURL ); 691cdf0e10cSrcweir 692cdf0e10cSrcweir SetStatusValue( TK_Progress, Any( static_cast< sal_Int32 >( 30 ) ) ); 693cdf0e10cSrcweir SetStatusValue( TK_Status, Any( TKGet( STR_DUPLICATING_PRESENTATION ) ) ); 694cdf0e10cSrcweir DispatchStatus(); 695cdf0e10cSrcweir 696cdf0e10cSrcweir Reference< XDesktop > xDesktop( mxMSF->getServiceManager()->createInstanceWithContext( 697cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ), mxMSF ), UNO_QUERY ); 698cdf0e10cSrcweir Reference< XFrame > xFrame( xDesktop, UNO_QUERY ); 699cdf0e10cSrcweir xSelf = xFrame->findFrame( TKGet( TK__blank ), FrameSearchFlag::CREATE ); 700cdf0e10cSrcweir Reference< XComponentLoader > xComponentLoader( xSelf, UNO_QUERY ); 701cdf0e10cSrcweir 702cdf0e10cSrcweir Sequence< PropertyValue > aLoadProps( 1 ); 703cdf0e10cSrcweir aLoadProps[ 0 ].Name = TKGet( TK_Hidden ); 704cdf0e10cSrcweir aLoadProps[ 0 ].Value <<= (sal_Bool)( sal_True ); 705cdf0e10cSrcweir mxModel = Reference< XModel >( xComponentLoader->loadComponentFromURL( 706cdf0e10cSrcweir maSaveAsURL, TKGet( TK__self ), 0, aLoadProps ), UNO_QUERY ); 707cdf0e10cSrcweir } 708cdf0e10cSrcweir } 709cdf0e10cSrcweir 710cdf0e10cSrcweir // check if the document is ReadOnly -> error 711cdf0e10cSrcweir Reference< XStorable > xStorable( mxModel, UNO_QUERY ); 712cdf0e10cSrcweir if ( xStorable.is() && !xStorable->isReadonly() ) 713cdf0e10cSrcweir { 714cdf0e10cSrcweir mxModel->lockControllers(); 715cdf0e10cSrcweir bRet = Optimize(); 716cdf0e10cSrcweir mxModel->unlockControllers(); 717cdf0e10cSrcweir 718cdf0e10cSrcweir // clearing undo stack: 719cdf0e10cSrcweir Reference< XFrame > xFrame( xSelf.is() ? xSelf : mxInformationDialog ); 720cdf0e10cSrcweir if ( xFrame.is() ) 721cdf0e10cSrcweir { 722cdf0e10cSrcweir const OUString sSlot( RTL_CONSTASCII_USTRINGPARAM( "slot:27115" ) ); 723cdf0e10cSrcweir DispatchURL( mxMSF, sSlot, xFrame ); 724cdf0e10cSrcweir } 725cdf0e10cSrcweir } 726cdf0e10cSrcweir 727cdf0e10cSrcweir if ( maSaveAsURL.getLength() ) 728cdf0e10cSrcweir { 729cdf0e10cSrcweir if ( xStorable.is() ) 730cdf0e10cSrcweir { 731cdf0e10cSrcweir xStorable->store(); 732cdf0e10cSrcweir nDestSize = PPPOptimizer::GetFileSize( maSaveAsURL ); 733cdf0e10cSrcweir } 734cdf0e10cSrcweir } 735cdf0e10cSrcweir 736cdf0e10cSrcweir if ( mxInformationDialog.is() ) 737cdf0e10cSrcweir { 738cdf0e10cSrcweir InformationDialog aInformationDialog( mxMSF, mxInformationDialog, maSaveAsURL, mbOpenNewDocument, nSourceSize, nDestSize, nEstimatedFileSize ); 739cdf0e10cSrcweir aInformationDialog.execute(); 740cdf0e10cSrcweir SetStatusValue( TK_OpenNewDocument, Any( mbOpenNewDocument ) ); 741cdf0e10cSrcweir DispatchStatus(); 742cdf0e10cSrcweir } 743cdf0e10cSrcweir 744cdf0e10cSrcweir if ( maSaveAsURL.getLength() ) 745cdf0e10cSrcweir { 746cdf0e10cSrcweir if ( mbOpenNewDocument && xSelf.is() ) 747cdf0e10cSrcweir { 748cdf0e10cSrcweir Reference< awt::XWindow > xContainerWindow( xSelf->getContainerWindow() ); 749cdf0e10cSrcweir xContainerWindow->setVisible( sal_True ); 750cdf0e10cSrcweir } 751cdf0e10cSrcweir else 752cdf0e10cSrcweir { 753cdf0e10cSrcweir Reference< XComponent > xComponent( mxModel, UNO_QUERY ); 754cdf0e10cSrcweir xComponent->dispose(); 755cdf0e10cSrcweir } 756cdf0e10cSrcweir } 757cdf0e10cSrcweir if ( nSourceSize && nDestSize ) 758cdf0e10cSrcweir { 759cdf0e10cSrcweir SetStatusValue( TK_FileSizeSource, Any( nSourceSize ) ); 760cdf0e10cSrcweir SetStatusValue( TK_FileSizeDestination, Any( nDestSize ) ); 761cdf0e10cSrcweir DispatchStatus(); 762cdf0e10cSrcweir } 763cdf0e10cSrcweir } 764cdf0e10cSrcweir else 765cdf0e10cSrcweir bRet = sal_False; 766cdf0e10cSrcweir return bRet; 767cdf0e10cSrcweir } 768cdf0e10cSrcweir 769