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