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 "graphiccollector.hxx" 28cdf0e10cSrcweir #include <com/sun/star/awt/XDevice.hpp> 29cdf0e10cSrcweir #include <com/sun/star/frame/XFramesSupplier.hpp> 30cdf0e10cSrcweir #include <com/sun/star/drawing/FillStyle.hpp> 31cdf0e10cSrcweir #include <com/sun/star/drawing/BitmapMode.hpp> 32cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPagesSupplier.hpp> 33cdf0e10cSrcweir #include <com/sun/star/presentation/XPresentationPage.hpp> 34cdf0e10cSrcweir #include <com/sun/star/drawing/XMasterPagesSupplier.hpp> 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include "impoptimizer.hxx" 37cdf0e10cSrcweir 38cdf0e10cSrcweir using namespace ::rtl; 39cdf0e10cSrcweir using namespace ::com::sun::star; 40cdf0e10cSrcweir using namespace ::com::sun::star::uno; 41cdf0e10cSrcweir using namespace ::com::sun::star::awt; 42cdf0e10cSrcweir using namespace ::com::sun::star::drawing; 43cdf0e10cSrcweir using namespace ::com::sun::star::graphic; 44cdf0e10cSrcweir using namespace ::com::sun::star::frame; 45cdf0e10cSrcweir using namespace ::com::sun::star::beans; 46cdf0e10cSrcweir using namespace ::com::sun::star::presentation; 47cdf0e10cSrcweir 48cdf0e10cSrcweir const DeviceInfo& GraphicCollector::GetDeviceInfo( const Reference< XComponentContext >& rxFact ) 49cdf0e10cSrcweir { 50cdf0e10cSrcweir static DeviceInfo aDeviceInfo; 51cdf0e10cSrcweir if( !aDeviceInfo.Width ) 52cdf0e10cSrcweir { 53cdf0e10cSrcweir try 54cdf0e10cSrcweir { 55cdf0e10cSrcweir Reference< XFramesSupplier > xDesktop( rxFact->getServiceManager()->createInstanceWithContext( 56cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ), rxFact ), UNO_QUERY_THROW ); 57cdf0e10cSrcweir Reference< XFrame > xFrame( xDesktop->getActiveFrame() ); 58cdf0e10cSrcweir Reference< XWindow > xWindow( xFrame->getContainerWindow() ); 59cdf0e10cSrcweir Reference< XDevice > xDevice( xWindow, UNO_QUERY_THROW ); 60cdf0e10cSrcweir aDeviceInfo = xDevice->getInfo(); 61cdf0e10cSrcweir } 62cdf0e10cSrcweir catch( Exception& ) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir } 65cdf0e10cSrcweir } 66cdf0e10cSrcweir return aDeviceInfo; 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir void ImpAddEntity( std::vector< GraphicCollector::GraphicEntity >& rGraphicEntities, const GraphicSettings& rGraphicSettings, const GraphicCollector::GraphicUser& rUser ) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir const rtl::OUString aGraphicURL( rUser.maGraphicURL ); 72cdf0e10cSrcweir const rtl::OUString sPackageURL( OUString::createFromAscii( "vnd.sun.star.GraphicObject:" ) ); 73cdf0e10cSrcweir 74cdf0e10cSrcweir if ( rGraphicSettings.mbEmbedLinkedGraphics || ( !aGraphicURL.getLength() || aGraphicURL.match( sPackageURL, 0 ) ) ) 75cdf0e10cSrcweir { 76cdf0e10cSrcweir std::vector< GraphicCollector::GraphicEntity >::iterator aIter( rGraphicEntities.begin() ); 77cdf0e10cSrcweir while( aIter != rGraphicEntities.end() ) 78cdf0e10cSrcweir { 79cdf0e10cSrcweir if ( aIter->maUser[ 0 ].maGraphicURL == aGraphicURL ) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir if ( rUser.maLogicalSize.Width > aIter->maLogicalSize.Width ) 82cdf0e10cSrcweir aIter->maLogicalSize.Width = rUser.maLogicalSize.Width; 83cdf0e10cSrcweir if ( rUser.maLogicalSize.Height > aIter->maLogicalSize.Height ) 84cdf0e10cSrcweir aIter->maLogicalSize.Height = rUser.maLogicalSize.Height; 85cdf0e10cSrcweir aIter->maUser.push_back( rUser ); 86cdf0e10cSrcweir break; 87cdf0e10cSrcweir } 88cdf0e10cSrcweir aIter++; 89cdf0e10cSrcweir } 90cdf0e10cSrcweir if ( aIter == rGraphicEntities.end() ) 91cdf0e10cSrcweir { 92cdf0e10cSrcweir GraphicCollector::GraphicEntity aEntity( rUser ); 93cdf0e10cSrcweir rGraphicEntities.push_back( aEntity ); 94cdf0e10cSrcweir } 95cdf0e10cSrcweir } 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir void ImpAddGraphicEntity( const Reference< XComponentContext >& rxMSF, Reference< XShape >& rxShape, const GraphicSettings& rGraphicSettings, std::vector< GraphicCollector::GraphicEntity >& rGraphicEntities ) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir Reference< XGraphic > xGraphic; 101cdf0e10cSrcweir Reference< XPropertySet > xShapePropertySet( rxShape, UNO_QUERY_THROW ); 102cdf0e10cSrcweir if ( xShapePropertySet->getPropertyValue( TKGet( TK_Graphic ) ) >>= xGraphic ) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir text::GraphicCrop aGraphicCropLogic( 0, 0, 0, 0 ); 105cdf0e10cSrcweir 106cdf0e10cSrcweir GraphicCollector::GraphicUser aUser; 107cdf0e10cSrcweir aUser.mxShape = rxShape; 108cdf0e10cSrcweir aUser.mbFillBitmap = sal_False; 109cdf0e10cSrcweir xShapePropertySet->getPropertyValue( TKGet( TK_GraphicURL ) ) >>= aUser.maGraphicURL; 110cdf0e10cSrcweir xShapePropertySet->getPropertyValue( TKGet( TK_GraphicStreamURL ) ) >>= aUser.maGraphicStreamURL; 111cdf0e10cSrcweir xShapePropertySet->getPropertyValue( TKGet( TK_GraphicCrop ) ) >>= aGraphicCropLogic; 112cdf0e10cSrcweir awt::Size aLogicalSize( rxShape->getSize() ); 113cdf0e10cSrcweir 114cdf0e10cSrcweir // calculating the logical size, as if there were no cropping 115cdf0e10cSrcweir if ( aGraphicCropLogic.Left || aGraphicCropLogic.Right || aGraphicCropLogic.Top || aGraphicCropLogic.Bottom ) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir awt::Size aSize100thMM( GraphicCollector::GetOriginalSize( rxMSF, xGraphic ) ); 118cdf0e10cSrcweir if ( aSize100thMM.Width && aSize100thMM.Height ) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir awt::Size aCropSize( aSize100thMM.Width - ( aGraphicCropLogic.Left + aGraphicCropLogic.Right ), 121cdf0e10cSrcweir aSize100thMM.Height - ( aGraphicCropLogic.Top + aGraphicCropLogic.Bottom )); 122cdf0e10cSrcweir if ( aCropSize.Width && aCropSize.Height ) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir awt::Size aNewLogSize( static_cast< sal_Int32 >( static_cast< double >( aSize100thMM.Width * aLogicalSize.Width ) / aCropSize.Width ), 125cdf0e10cSrcweir static_cast< sal_Int32 >( static_cast< double >( aSize100thMM.Height * aLogicalSize.Height ) / aCropSize.Height ) ); 126cdf0e10cSrcweir aLogicalSize = aNewLogSize; 127cdf0e10cSrcweir } 128cdf0e10cSrcweir } 129cdf0e10cSrcweir } 130cdf0e10cSrcweir aUser.maGraphicCropLogic = aGraphicCropLogic; 131cdf0e10cSrcweir aUser.maLogicalSize = aLogicalSize; 132cdf0e10cSrcweir ImpAddEntity( rGraphicEntities, rGraphicSettings, aUser ); 133cdf0e10cSrcweir } 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136cdf0e10cSrcweir void ImpAddFillBitmapEntity( const Reference< XComponentContext >& rxMSF, const Reference< XPropertySet >& rxPropertySet, const awt::Size& rLogicalSize, 137cdf0e10cSrcweir std::vector< GraphicCollector::GraphicEntity >& rGraphicEntities, const GraphicSettings& rGraphicSettings, const Reference< XPropertySet >& rxPagePropertySet ) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir try 140cdf0e10cSrcweir { 141cdf0e10cSrcweir FillStyle eFillStyle; 142cdf0e10cSrcweir if ( rxPropertySet->getPropertyValue( TKGet( TK_FillStyle ) ) >>= eFillStyle ) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir if ( eFillStyle == FillStyle_BITMAP ) 145cdf0e10cSrcweir { 146cdf0e10cSrcweir rtl::OUString aFillBitmapURL; 147cdf0e10cSrcweir Reference< XBitmap > xFillBitmap; 148cdf0e10cSrcweir if ( rxPropertySet->getPropertyValue( TKGet( TK_FillBitmap ) ) >>= xFillBitmap ) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir Reference< XGraphic > xGraphic( xFillBitmap, UNO_QUERY_THROW ); 151cdf0e10cSrcweir if ( xGraphic.is() ) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir awt::Size aLogicalSize( rLogicalSize ); 154cdf0e10cSrcweir Reference< XPropertySetInfo > axPropSetInfo( rxPropertySet->getPropertySetInfo() ); 155cdf0e10cSrcweir if ( axPropSetInfo.is() ) 156cdf0e10cSrcweir { 157cdf0e10cSrcweir if ( axPropSetInfo->hasPropertyByName( TKGet( TK_FillBitmapMode ) ) ) 158cdf0e10cSrcweir { 159cdf0e10cSrcweir BitmapMode eBitmapMode; 160cdf0e10cSrcweir if ( rxPropertySet->getPropertyValue( TKGet( TK_FillBitmapMode ) ) >>= eBitmapMode ) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir if ( ( eBitmapMode == BitmapMode_REPEAT ) || ( eBitmapMode == BitmapMode_NO_REPEAT ) ) 163cdf0e10cSrcweir { 164cdf0e10cSrcweir sal_Bool bLogicalSize = sal_False; 165cdf0e10cSrcweir awt::Size aSize( 0, 0 ); 166cdf0e10cSrcweir if ( ( rxPropertySet->getPropertyValue( TKGet( TK_FillBitmapLogicalSize ) ) >>= bLogicalSize ) 167cdf0e10cSrcweir && ( rxPropertySet->getPropertyValue( TKGet( TK_FillBitmapSizeX ) ) >>= aSize.Width ) 168cdf0e10cSrcweir && ( rxPropertySet->getPropertyValue( TKGet( TK_FillBitmapSizeY ) ) >>= aSize.Height ) ) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir if ( bLogicalSize ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir if ( !aSize.Width || !aSize.Height ) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir awt::Size aSize100thMM( GraphicCollector::GetOriginalSize( rxMSF, xGraphic ) ); 175cdf0e10cSrcweir if ( aSize100thMM.Width && aSize100thMM.Height ) 176cdf0e10cSrcweir aLogicalSize = aSize100thMM; 177cdf0e10cSrcweir } 178cdf0e10cSrcweir else 179cdf0e10cSrcweir aLogicalSize = aSize; 180cdf0e10cSrcweir } 181cdf0e10cSrcweir else 182cdf0e10cSrcweir { 183cdf0e10cSrcweir aLogicalSize.Width = sal::static_int_cast< sal_Int32 >( ( static_cast< double >( aLogicalSize.Width ) * aSize.Width ) / -100.0 ); 184cdf0e10cSrcweir aLogicalSize.Height = sal::static_int_cast< sal_Int32 >( ( static_cast< double >( aLogicalSize.Height ) * aSize.Height ) / -100.0 ); 185cdf0e10cSrcweir } 186cdf0e10cSrcweir } 187cdf0e10cSrcweir } 188cdf0e10cSrcweir } 189cdf0e10cSrcweir } 190cdf0e10cSrcweir } 191cdf0e10cSrcweir GraphicCollector::GraphicUser aUser; 192cdf0e10cSrcweir aUser.mxPropertySet = rxPropertySet; 193cdf0e10cSrcweir rxPropertySet->getPropertyValue( TKGet( TK_FillBitmapURL ) ) >>= aUser.maGraphicURL; 194cdf0e10cSrcweir aUser.mbFillBitmap = sal_True; 195cdf0e10cSrcweir aUser.maLogicalSize = aLogicalSize; 196cdf0e10cSrcweir aUser.mxPagePropertySet = rxPagePropertySet; 197cdf0e10cSrcweir ImpAddEntity( rGraphicEntities, rGraphicSettings, aUser ); 198cdf0e10cSrcweir } 199cdf0e10cSrcweir } 200cdf0e10cSrcweir } 201cdf0e10cSrcweir } 202cdf0e10cSrcweir } 203cdf0e10cSrcweir catch( Exception& ) 204cdf0e10cSrcweir { 205cdf0e10cSrcweir } 206cdf0e10cSrcweir } 207cdf0e10cSrcweir 208cdf0e10cSrcweir void ImpCollectBackgroundGraphic( const Reference< XComponentContext >& rxMSF, const Reference< XDrawPage >& rxDrawPage, const GraphicSettings& rGraphicSettings, std::vector< GraphicCollector::GraphicEntity >& rGraphicEntities ) 209cdf0e10cSrcweir { 210cdf0e10cSrcweir try 211cdf0e10cSrcweir { 212cdf0e10cSrcweir awt::Size aLogicalSize( 28000, 21000 ); 213cdf0e10cSrcweir Reference< XPropertySet > xPropertySet( rxDrawPage, UNO_QUERY_THROW ); 214cdf0e10cSrcweir xPropertySet->getPropertyValue( TKGet( TK_Width ) ) >>= aLogicalSize.Width; 215cdf0e10cSrcweir xPropertySet->getPropertyValue( TKGet( TK_Height ) ) >>= aLogicalSize.Height; 216cdf0e10cSrcweir 217cdf0e10cSrcweir Reference< XPropertySet > xBackgroundPropSet; 218cdf0e10cSrcweir if ( xPropertySet->getPropertyValue( TKGet( TK_Background ) ) >>= xBackgroundPropSet ) 219cdf0e10cSrcweir ImpAddFillBitmapEntity( rxMSF, xBackgroundPropSet, aLogicalSize, rGraphicEntities, rGraphicSettings, xPropertySet ); 220cdf0e10cSrcweir } 221cdf0e10cSrcweir catch( Exception& ) 222cdf0e10cSrcweir { 223cdf0e10cSrcweir } 224cdf0e10cSrcweir } 225cdf0e10cSrcweir 226cdf0e10cSrcweir void ImpCollectGraphicObjects( const Reference< XComponentContext >& rxMSF, const Reference< XShapes >& rxShapes, const GraphicSettings& rGraphicSettings, std::vector< GraphicCollector::GraphicEntity >& rGraphicEntities ) 227cdf0e10cSrcweir { 228cdf0e10cSrcweir for ( sal_Int32 i = 0; i < rxShapes->getCount(); i++ ) 229cdf0e10cSrcweir { 230cdf0e10cSrcweir try 231cdf0e10cSrcweir { 232cdf0e10cSrcweir const OUString sGraphicObjectShape( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.GraphicObjectShape" ) ); 233cdf0e10cSrcweir const OUString sGroupShape( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.GroupShape" ) ); 234cdf0e10cSrcweir Reference< XShape > xShape( rxShapes->getByIndex( i ), UNO_QUERY_THROW ); 235cdf0e10cSrcweir const OUString sShapeType( xShape->getShapeType() ); 236cdf0e10cSrcweir if ( sShapeType == sGroupShape ) 237cdf0e10cSrcweir { 238cdf0e10cSrcweir Reference< XShapes > xShapes( xShape, UNO_QUERY_THROW ); 239cdf0e10cSrcweir ImpCollectGraphicObjects( rxMSF, xShapes, rGraphicSettings, rGraphicEntities ); 240cdf0e10cSrcweir continue; 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243cdf0e10cSrcweir if ( sShapeType == sGraphicObjectShape ) 244cdf0e10cSrcweir ImpAddGraphicEntity( rxMSF, xShape, rGraphicSettings, rGraphicEntities ); 245cdf0e10cSrcweir 246cdf0e10cSrcweir // now check for a fillstyle 247cdf0e10cSrcweir Reference< XPropertySet > xEmptyPagePropSet; 248cdf0e10cSrcweir Reference< XPropertySet > xShapePropertySet( xShape, UNO_QUERY_THROW ); 249cdf0e10cSrcweir awt::Size aLogicalSize( xShape->getSize() ); 250cdf0e10cSrcweir ImpAddFillBitmapEntity( rxMSF, xShapePropertySet, aLogicalSize, rGraphicEntities, rGraphicSettings, xEmptyPagePropSet ); 251cdf0e10cSrcweir } 252cdf0e10cSrcweir catch( Exception& ) 253cdf0e10cSrcweir { 254cdf0e10cSrcweir } 255cdf0e10cSrcweir } 256cdf0e10cSrcweir } 257cdf0e10cSrcweir 258cdf0e10cSrcweir awt::Size GraphicCollector::GetOriginalSize( const Reference< XComponentContext >& rxMSF, const Reference< XGraphic >& rxGraphic ) 259cdf0e10cSrcweir { 260cdf0e10cSrcweir awt::Size aSize100thMM( 0, 0 ); 261cdf0e10cSrcweir Reference< XPropertySet > xGraphicPropertySet( rxGraphic, UNO_QUERY_THROW ); 262cdf0e10cSrcweir if ( xGraphicPropertySet->getPropertyValue( TKGet( TK_Size100thMM ) ) >>= aSize100thMM ) 263cdf0e10cSrcweir { 264cdf0e10cSrcweir if ( !aSize100thMM.Width && !aSize100thMM.Height ) 265cdf0e10cSrcweir { // MAPMODE_PIXEL USED :-( 266cdf0e10cSrcweir awt::Size aSourceSizePixel( 0, 0 ); 267cdf0e10cSrcweir if ( xGraphicPropertySet->getPropertyValue( TKGet( TK_SizePixel ) ) >>= aSourceSizePixel ) 268cdf0e10cSrcweir { 269cdf0e10cSrcweir const DeviceInfo& rDeviceInfo( GraphicCollector::GetDeviceInfo( rxMSF ) ); 270cdf0e10cSrcweir if ( rDeviceInfo.PixelPerMeterX && rDeviceInfo.PixelPerMeterY ) 271cdf0e10cSrcweir { 272cdf0e10cSrcweir aSize100thMM.Width = static_cast< sal_Int32 >( ( aSourceSizePixel.Width * 100000.0 ) / rDeviceInfo.PixelPerMeterX ); 273cdf0e10cSrcweir aSize100thMM.Height = static_cast< sal_Int32 >( ( aSourceSizePixel.Height * 100000.0 ) / rDeviceInfo.PixelPerMeterY ); 274cdf0e10cSrcweir } 275cdf0e10cSrcweir } 276cdf0e10cSrcweir } 277cdf0e10cSrcweir } 278cdf0e10cSrcweir return aSize100thMM; 279cdf0e10cSrcweir } 280cdf0e10cSrcweir 281cdf0e10cSrcweir void GraphicCollector::CollectGraphics( const Reference< XComponentContext >& rxMSF, const Reference< XModel >& rxModel, 282cdf0e10cSrcweir const GraphicSettings& rGraphicSettings, std::vector< GraphicCollector::GraphicEntity >& rGraphicList ) 283cdf0e10cSrcweir { 284cdf0e10cSrcweir try 285cdf0e10cSrcweir { 286cdf0e10cSrcweir sal_Int32 i; 287cdf0e10cSrcweir Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW ); 288cdf0e10cSrcweir Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW ); 289cdf0e10cSrcweir for ( i = 0; i < xDrawPages->getCount(); i++ ) 290cdf0e10cSrcweir { 291cdf0e10cSrcweir Reference< XDrawPage > xDrawPage( xDrawPages->getByIndex( i ), UNO_QUERY_THROW ); 292cdf0e10cSrcweir ImpCollectBackgroundGraphic( rxMSF, xDrawPage, rGraphicSettings, rGraphicList ); 293cdf0e10cSrcweir Reference< XShapes > xDrawShapes( xDrawPage, UNO_QUERY_THROW ); 294cdf0e10cSrcweir ImpCollectGraphicObjects( rxMSF, xDrawShapes, rGraphicSettings, rGraphicList ); 295cdf0e10cSrcweir 296cdf0e10cSrcweir Reference< XPresentationPage > xPresentationPage( xDrawPage, UNO_QUERY_THROW ); 297cdf0e10cSrcweir Reference< XDrawPage > xNotesPage( xPresentationPage->getNotesPage() ); 298cdf0e10cSrcweir ImpCollectBackgroundGraphic( rxMSF, xNotesPage, rGraphicSettings, rGraphicList ); 299cdf0e10cSrcweir Reference< XShapes > xNotesShapes( xNotesPage, UNO_QUERY_THROW ); 300cdf0e10cSrcweir ImpCollectGraphicObjects( rxMSF, xNotesShapes, rGraphicSettings, rGraphicList ); 301cdf0e10cSrcweir } 302cdf0e10cSrcweir Reference< XMasterPagesSupplier > xMasterPagesSupplier( rxModel, UNO_QUERY_THROW ); 303cdf0e10cSrcweir Reference< XDrawPages > xMasterPages( xMasterPagesSupplier->getMasterPages(), UNO_QUERY_THROW ); 304cdf0e10cSrcweir for ( i = 0; i < xMasterPages->getCount(); i++ ) 305cdf0e10cSrcweir { 306cdf0e10cSrcweir Reference< XDrawPage > xMasterPage( xMasterPages->getByIndex( i ), UNO_QUERY_THROW ); 307cdf0e10cSrcweir ImpCollectBackgroundGraphic( rxMSF, xMasterPage, rGraphicSettings, rGraphicList ); 308cdf0e10cSrcweir Reference< XShapes > xMasterPageShapes( xMasterPage, UNO_QUERY_THROW ); 309cdf0e10cSrcweir ImpCollectGraphicObjects( rxMSF, xMasterPageShapes, rGraphicSettings, rGraphicList ); 310cdf0e10cSrcweir } 311cdf0e10cSrcweir 312cdf0e10cSrcweir std::vector< GraphicCollector::GraphicEntity >::iterator aGraphicIter( rGraphicList.begin() ); 313cdf0e10cSrcweir std::vector< GraphicCollector::GraphicEntity >::iterator aGraphicIEnd( rGraphicList.end() ); 314cdf0e10cSrcweir while( aGraphicIter != aGraphicIEnd ) 315cdf0e10cSrcweir { 316cdf0e10cSrcweir // check if it is possible to remove the crop area 317cdf0e10cSrcweir aGraphicIter->mbRemoveCropArea = rGraphicSettings.mbRemoveCropArea; 318cdf0e10cSrcweir if ( aGraphicIter->mbRemoveCropArea ) 319cdf0e10cSrcweir { 320cdf0e10cSrcweir std::vector< GraphicCollector::GraphicUser >::iterator aGUIter( aGraphicIter->maUser.begin() ); 321cdf0e10cSrcweir while( aGraphicIter->mbRemoveCropArea && ( aGUIter != aGraphicIter->maUser.end() ) ) 322cdf0e10cSrcweir { 323cdf0e10cSrcweir if ( aGUIter->maGraphicCropLogic.Left || aGUIter->maGraphicCropLogic.Top 324cdf0e10cSrcweir || aGUIter->maGraphicCropLogic.Right || aGUIter->maGraphicCropLogic.Bottom ) 325cdf0e10cSrcweir { 326cdf0e10cSrcweir if ( aGUIter == aGraphicIter->maUser.begin() ) 327cdf0e10cSrcweir aGraphicIter->maGraphicCropLogic = aGUIter->maGraphicCropLogic; 328cdf0e10cSrcweir else if ( ( aGraphicIter->maGraphicCropLogic.Left != aGUIter->maGraphicCropLogic.Left ) 329cdf0e10cSrcweir || ( aGraphicIter->maGraphicCropLogic.Top != aGUIter->maGraphicCropLogic.Top ) 330cdf0e10cSrcweir || ( aGraphicIter->maGraphicCropLogic.Right != aGUIter->maGraphicCropLogic.Right ) 331cdf0e10cSrcweir || ( aGraphicIter->maGraphicCropLogic.Bottom != aGUIter->maGraphicCropLogic.Bottom ) ) 332cdf0e10cSrcweir { 333cdf0e10cSrcweir aGraphicIter->mbRemoveCropArea = sal_False; 334cdf0e10cSrcweir } 335cdf0e10cSrcweir } 336cdf0e10cSrcweir else 337cdf0e10cSrcweir aGraphicIter->mbRemoveCropArea = sal_False; 338cdf0e10cSrcweir aGUIter++; 339cdf0e10cSrcweir } 340cdf0e10cSrcweir } 341cdf0e10cSrcweir if ( !aGraphicIter->mbRemoveCropArea ) 342cdf0e10cSrcweir aGraphicIter->maGraphicCropLogic = text::GraphicCrop( 0, 0, 0, 0 ); 343cdf0e10cSrcweir aGraphicIter++; 344cdf0e10cSrcweir } 345cdf0e10cSrcweir } 346cdf0e10cSrcweir catch ( Exception& ) 347cdf0e10cSrcweir { 348cdf0e10cSrcweir } 349cdf0e10cSrcweir } 350cdf0e10cSrcweir 351cdf0e10cSrcweir void ImpCountGraphicObjects( const Reference< XComponentContext >& rxMSF, const Reference< XShapes >& rxShapes, const GraphicSettings& rGraphicSettings, sal_Int32& rnGraphics ) 352cdf0e10cSrcweir { 353cdf0e10cSrcweir for ( sal_Int32 i = 0; i < rxShapes->getCount(); i++ ) 354cdf0e10cSrcweir { 355cdf0e10cSrcweir try 356cdf0e10cSrcweir { 357cdf0e10cSrcweir const OUString sGraphicObjectShape( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.GraphicObjectShape" ) ); 358cdf0e10cSrcweir const OUString sGroupShape( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.GroupShape" ) ); 359cdf0e10cSrcweir Reference< XShape > xShape( rxShapes->getByIndex( i ), UNO_QUERY_THROW ); 360cdf0e10cSrcweir const OUString sShapeType( xShape->getShapeType() ); 361cdf0e10cSrcweir if ( sShapeType == sGroupShape ) 362cdf0e10cSrcweir { 363cdf0e10cSrcweir Reference< XShapes > xShapes( xShape, UNO_QUERY_THROW ); 364cdf0e10cSrcweir ImpCountGraphicObjects( rxMSF, xShapes, rGraphicSettings, rnGraphics ); 365cdf0e10cSrcweir continue; 366cdf0e10cSrcweir } 367cdf0e10cSrcweir 368cdf0e10cSrcweir if ( sShapeType == sGraphicObjectShape ) 369cdf0e10cSrcweir { 370cdf0e10cSrcweir rnGraphics++; 371cdf0e10cSrcweir } 372cdf0e10cSrcweir 373cdf0e10cSrcweir // now check for a fillstyle 374cdf0e10cSrcweir Reference< XPropertySet > xEmptyPagePropSet; 375cdf0e10cSrcweir Reference< XPropertySet > xShapePropertySet( xShape, UNO_QUERY_THROW ); 376cdf0e10cSrcweir awt::Size aLogicalSize( xShape->getSize() ); 377cdf0e10cSrcweir 378cdf0e10cSrcweir FillStyle eFillStyle; 379cdf0e10cSrcweir if ( xShapePropertySet->getPropertyValue( TKGet( TK_FillStyle ) ) >>= eFillStyle ) 380cdf0e10cSrcweir { 381cdf0e10cSrcweir if ( eFillStyle == FillStyle_BITMAP ) 382cdf0e10cSrcweir { 383cdf0e10cSrcweir rnGraphics++; 384cdf0e10cSrcweir } 385cdf0e10cSrcweir } 386cdf0e10cSrcweir } 387cdf0e10cSrcweir catch( Exception& ) 388cdf0e10cSrcweir { 389cdf0e10cSrcweir } 390cdf0e10cSrcweir } 391cdf0e10cSrcweir } 392cdf0e10cSrcweir 393cdf0e10cSrcweir void ImpCountBackgroundGraphic( const Reference< XComponentContext >& /* rxMSF */, const Reference< XDrawPage >& rxDrawPage, 394cdf0e10cSrcweir const GraphicSettings& /* rGraphicSettings */, sal_Int32& rnGraphics ) 395cdf0e10cSrcweir { 396cdf0e10cSrcweir try 397cdf0e10cSrcweir { 398cdf0e10cSrcweir awt::Size aLogicalSize( 28000, 21000 ); 399cdf0e10cSrcweir Reference< XPropertySet > xPropertySet( rxDrawPage, UNO_QUERY_THROW ); 400cdf0e10cSrcweir xPropertySet->getPropertyValue( TKGet( TK_Width ) ) >>= aLogicalSize.Width; 401cdf0e10cSrcweir xPropertySet->getPropertyValue( TKGet( TK_Height ) ) >>= aLogicalSize.Height; 402cdf0e10cSrcweir 403cdf0e10cSrcweir Reference< XPropertySet > xBackgroundPropSet; 404cdf0e10cSrcweir if ( xPropertySet->getPropertyValue( TKGet( TK_Background ) ) >>= xBackgroundPropSet ) 405cdf0e10cSrcweir { 406cdf0e10cSrcweir FillStyle eFillStyle; 407cdf0e10cSrcweir if ( xBackgroundPropSet->getPropertyValue( TKGet( TK_FillStyle ) ) >>= eFillStyle ) 408cdf0e10cSrcweir { 409cdf0e10cSrcweir if ( eFillStyle == FillStyle_BITMAP ) 410cdf0e10cSrcweir { 411cdf0e10cSrcweir rnGraphics++; 412cdf0e10cSrcweir } 413cdf0e10cSrcweir } 414cdf0e10cSrcweir } 415cdf0e10cSrcweir } 416cdf0e10cSrcweir catch( Exception& ) 417cdf0e10cSrcweir { 418cdf0e10cSrcweir } 419cdf0e10cSrcweir } 420cdf0e10cSrcweir 421cdf0e10cSrcweir void GraphicCollector::CountGraphics( const Reference< XComponentContext >& rxMSF, const Reference< XModel >& rxModel, 422cdf0e10cSrcweir const GraphicSettings& rGraphicSettings, sal_Int32& rnGraphics ) 423cdf0e10cSrcweir { 424cdf0e10cSrcweir try 425cdf0e10cSrcweir { 426cdf0e10cSrcweir sal_Int32 i; 427cdf0e10cSrcweir Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW ); 428cdf0e10cSrcweir Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW ); 429cdf0e10cSrcweir for ( i = 0; i < xDrawPages->getCount(); i++ ) 430cdf0e10cSrcweir { 431cdf0e10cSrcweir Reference< XDrawPage > xDrawPage( xDrawPages->getByIndex( i ), UNO_QUERY_THROW ); 432cdf0e10cSrcweir ImpCountBackgroundGraphic( rxMSF, xDrawPage, rGraphicSettings, rnGraphics ); 433cdf0e10cSrcweir Reference< XShapes > xDrawShapes( xDrawPage, UNO_QUERY_THROW ); 434cdf0e10cSrcweir ImpCountGraphicObjects( rxMSF, xDrawShapes, rGraphicSettings, rnGraphics ); 435cdf0e10cSrcweir 436cdf0e10cSrcweir Reference< XPresentationPage > xPresentationPage( xDrawPage, UNO_QUERY_THROW ); 437cdf0e10cSrcweir Reference< XDrawPage > xNotesPage( xPresentationPage->getNotesPage() ); 438cdf0e10cSrcweir ImpCountBackgroundGraphic( rxMSF, xNotesPage, rGraphicSettings, rnGraphics ); 439cdf0e10cSrcweir Reference< XShapes > xNotesShapes( xNotesPage, UNO_QUERY_THROW ); 440cdf0e10cSrcweir ImpCountGraphicObjects( rxMSF, xNotesShapes, rGraphicSettings, rnGraphics ); 441cdf0e10cSrcweir } 442cdf0e10cSrcweir Reference< XMasterPagesSupplier > xMasterPagesSupplier( rxModel, UNO_QUERY_THROW ); 443cdf0e10cSrcweir Reference< XDrawPages > xMasterPages( xMasterPagesSupplier->getMasterPages(), UNO_QUERY_THROW ); 444cdf0e10cSrcweir for ( i = 0; i < xMasterPages->getCount(); i++ ) 445cdf0e10cSrcweir { 446cdf0e10cSrcweir Reference< XDrawPage > xMasterPage( xMasterPages->getByIndex( i ), UNO_QUERY_THROW ); 447cdf0e10cSrcweir ImpCountBackgroundGraphic( rxMSF, xMasterPage, rGraphicSettings, rnGraphics ); 448cdf0e10cSrcweir Reference< XShapes > xMasterPageShapes( xMasterPage, UNO_QUERY_THROW ); 449cdf0e10cSrcweir ImpCountGraphicObjects( rxMSF, xMasterPageShapes, rGraphicSettings, rnGraphics ); 450cdf0e10cSrcweir } 451cdf0e10cSrcweir } 452cdf0e10cSrcweir catch ( Exception& ) 453cdf0e10cSrcweir { 454cdf0e10cSrcweir } 455cdf0e10cSrcweir } 456cdf0e10cSrcweir 457