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