xref: /AOO41X/main/svtools/source/graphic/grfmgr.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_svtools.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #define ENABLE_BYTESTRING_STREAM_OPERATORS
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <algorithm>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <tools/vcompat.hxx>
36*cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
37*cdf0e10cSrcweir #include <unotools/localfilehelper.hxx>
38*cdf0e10cSrcweir #include <unotools/tempfile.hxx>
39*cdf0e10cSrcweir #include <vcl/svapp.hxx>
40*cdf0e10cSrcweir #include <vcl/cvtgrf.hxx>
41*cdf0e10cSrcweir #include <vcl/metaact.hxx>
42*cdf0e10cSrcweir #include <vcl/virdev.hxx>
43*cdf0e10cSrcweir #include <vcl/salbtype.hxx>
44*cdf0e10cSrcweir #include <unotools/cacheoptions.hxx>
45*cdf0e10cSrcweir #include <svtools/grfmgr.hxx>
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir // --> OD 2010-01-04 #i105243#
48*cdf0e10cSrcweir #include <vcl/pdfextoutdevdata.hxx>
49*cdf0e10cSrcweir // <--
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir // -----------
52*cdf0e10cSrcweir // - Defines -
53*cdf0e10cSrcweir // -----------
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir #define WATERMARK_LUM_OFFSET				50
56*cdf0e10cSrcweir #define WATERMARK_CON_OFFSET				-70
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir // -----------
59*cdf0e10cSrcweir // - statics -
60*cdf0e10cSrcweir // -----------
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir GraphicManager* GraphicObject::mpGlobalMgr = NULL;
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir // ---------------------
65*cdf0e10cSrcweir // - GrfDirectCacheObj -
66*cdf0e10cSrcweir // ---------------------
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir struct GrfSimpleCacheObj
69*cdf0e10cSrcweir {
70*cdf0e10cSrcweir 	Graphic		maGraphic;
71*cdf0e10cSrcweir 	GraphicAttr	maAttr;
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir 				GrfSimpleCacheObj( const Graphic& rGraphic, const GraphicAttr& rAttr ) :
74*cdf0e10cSrcweir 					maGraphic( rGraphic ), maAttr( rAttr ) {}
75*cdf0e10cSrcweir };
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir // -----------------
78*cdf0e10cSrcweir // - GraphicObject -
79*cdf0e10cSrcweir // -----------------
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir TYPEINIT1_AUTOFACTORY( GraphicObject, SvDataCopyStream );
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir // -----------------------------------------------------------------------------
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir GraphicObject::GraphicObject( const GraphicManager* pMgr ) :
86*cdf0e10cSrcweir 	mpLink		( NULL ),
87*cdf0e10cSrcweir 	mpUserData	( NULL )
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir 	ImplConstruct();
90*cdf0e10cSrcweir 	ImplAssignGraphicData();
91*cdf0e10cSrcweir 	ImplSetGraphicManager( pMgr );
92*cdf0e10cSrcweir }
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir // -----------------------------------------------------------------------------
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir GraphicObject::GraphicObject( const Graphic& rGraphic, const GraphicManager* pMgr ) :
97*cdf0e10cSrcweir 	maGraphic	( rGraphic ),
98*cdf0e10cSrcweir 	mpLink		( NULL ),
99*cdf0e10cSrcweir 	mpUserData	( NULL )
100*cdf0e10cSrcweir {
101*cdf0e10cSrcweir 	ImplConstruct();
102*cdf0e10cSrcweir 	ImplAssignGraphicData();
103*cdf0e10cSrcweir 	ImplSetGraphicManager( pMgr );
104*cdf0e10cSrcweir }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir // -----------------------------------------------------------------------------
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir GraphicObject::GraphicObject( const Graphic& rGraphic, const String& rLink, const GraphicManager* pMgr ) :
109*cdf0e10cSrcweir 	maGraphic	( rGraphic ),
110*cdf0e10cSrcweir 	mpLink		( rLink.Len() ? ( new String( rLink ) ) : NULL ),
111*cdf0e10cSrcweir 	mpUserData	( NULL )
112*cdf0e10cSrcweir {
113*cdf0e10cSrcweir 	ImplConstruct();
114*cdf0e10cSrcweir 	ImplAssignGraphicData();
115*cdf0e10cSrcweir 	ImplSetGraphicManager( pMgr );
116*cdf0e10cSrcweir }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir // -----------------------------------------------------------------------------
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir GraphicObject::GraphicObject( const GraphicObject& rGraphicObj, const GraphicManager* pMgr ) :
121*cdf0e10cSrcweir     SvDataCopyStream(),
122*cdf0e10cSrcweir 	maGraphic	( rGraphicObj.GetGraphic() ),
123*cdf0e10cSrcweir 	maAttr		( rGraphicObj.maAttr ),
124*cdf0e10cSrcweir 	mpLink		( rGraphicObj.mpLink ? ( new String( *rGraphicObj.mpLink ) ) : NULL ),
125*cdf0e10cSrcweir 	mpUserData	( rGraphicObj.mpUserData ? ( new String( *rGraphicObj.mpUserData ) ) : NULL )
126*cdf0e10cSrcweir {
127*cdf0e10cSrcweir 	ImplConstruct();
128*cdf0e10cSrcweir 	ImplAssignGraphicData();
129*cdf0e10cSrcweir 	ImplSetGraphicManager( pMgr, NULL, &rGraphicObj );
130*cdf0e10cSrcweir }
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir // -----------------------------------------------------------------------------
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir GraphicObject::GraphicObject( const ByteString& rUniqueID, const GraphicManager* pMgr ) :
135*cdf0e10cSrcweir 	mpLink		( NULL ),
136*cdf0e10cSrcweir 	mpUserData	( NULL )
137*cdf0e10cSrcweir {
138*cdf0e10cSrcweir 	ImplConstruct();
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 	// assign default properties
141*cdf0e10cSrcweir 	ImplAssignGraphicData();
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir 	ImplSetGraphicManager( pMgr, &rUniqueID );
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 	// update properties
146*cdf0e10cSrcweir 	ImplAssignGraphicData();
147*cdf0e10cSrcweir }
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir // -----------------------------------------------------------------------------
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir GraphicObject::~GraphicObject()
152*cdf0e10cSrcweir {
153*cdf0e10cSrcweir 	if( mpMgr )
154*cdf0e10cSrcweir 	{
155*cdf0e10cSrcweir 		mpMgr->ImplUnregisterObj( *this );
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 		if( ( mpMgr == mpGlobalMgr ) && !mpGlobalMgr->ImplHasObjects() )
158*cdf0e10cSrcweir 			delete mpGlobalMgr, mpGlobalMgr = NULL;
159*cdf0e10cSrcweir 	}
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 	delete mpSwapOutTimer;
162*cdf0e10cSrcweir 	delete mpSwapStreamHdl;
163*cdf0e10cSrcweir 	delete mpLink;
164*cdf0e10cSrcweir 	delete mpUserData;
165*cdf0e10cSrcweir 	delete mpSimpleCache;
166*cdf0e10cSrcweir }
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir // -----------------------------------------------------------------------------
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir void GraphicObject::ImplConstruct()
171*cdf0e10cSrcweir {
172*cdf0e10cSrcweir 	mpMgr = NULL;
173*cdf0e10cSrcweir 	mpSwapStreamHdl = NULL;
174*cdf0e10cSrcweir 	mpSwapOutTimer = NULL;
175*cdf0e10cSrcweir 	mpSimpleCache = NULL;
176*cdf0e10cSrcweir     mnAnimationLoopCount = 0;
177*cdf0e10cSrcweir 	mbAutoSwapped = sal_False;
178*cdf0e10cSrcweir 	mbIsInSwapIn = sal_False;
179*cdf0e10cSrcweir 	mbIsInSwapOut = sal_False;
180*cdf0e10cSrcweir }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir // -----------------------------------------------------------------------------
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir void GraphicObject::ImplAssignGraphicData()
185*cdf0e10cSrcweir {
186*cdf0e10cSrcweir 	maPrefSize = maGraphic.GetPrefSize();
187*cdf0e10cSrcweir 	maPrefMapMode = maGraphic.GetPrefMapMode();
188*cdf0e10cSrcweir 	mnSizeBytes = maGraphic.GetSizeBytes();
189*cdf0e10cSrcweir 	meType = maGraphic.GetType();
190*cdf0e10cSrcweir 	mbTransparent = maGraphic.IsTransparent();
191*cdf0e10cSrcweir 	mbAlpha = maGraphic.IsAlpha();
192*cdf0e10cSrcweir 	mbAnimated = maGraphic.IsAnimated();
193*cdf0e10cSrcweir 	mbEPS = maGraphic.IsEPS();
194*cdf0e10cSrcweir 	mbIsRenderGraphic = maGraphic.IsRenderGraphic();
195*cdf0e10cSrcweir 	mbHasRenderGraphic = maGraphic.HasRenderGraphic();
196*cdf0e10cSrcweir     mnAnimationLoopCount = ( mbAnimated ? maGraphic.GetAnimationLoopCount() : 0 );
197*cdf0e10cSrcweir }
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir // -----------------------------------------------------------------------------
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir void GraphicObject::ImplSetGraphicManager( const GraphicManager* pMgr, const ByteString* pID, const GraphicObject* pCopyObj )
202*cdf0e10cSrcweir {
203*cdf0e10cSrcweir 	if( !mpMgr || ( pMgr != mpMgr ) )
204*cdf0e10cSrcweir 	{
205*cdf0e10cSrcweir 		if( !pMgr && mpMgr && ( mpMgr == mpGlobalMgr ) )
206*cdf0e10cSrcweir 			return;
207*cdf0e10cSrcweir 		else
208*cdf0e10cSrcweir 		{
209*cdf0e10cSrcweir 			if( mpMgr )
210*cdf0e10cSrcweir 			{
211*cdf0e10cSrcweir 				mpMgr->ImplUnregisterObj( *this );
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir 				if( ( mpMgr == mpGlobalMgr ) && !mpGlobalMgr->ImplHasObjects() )
214*cdf0e10cSrcweir 					delete mpGlobalMgr, mpGlobalMgr = NULL;
215*cdf0e10cSrcweir 			}
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir 			if( !pMgr )
218*cdf0e10cSrcweir 			{
219*cdf0e10cSrcweir 				if( !mpGlobalMgr )
220*cdf0e10cSrcweir 				{
221*cdf0e10cSrcweir                     SvtCacheOptions aCacheOptions;
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 					mpGlobalMgr = new GraphicManager( aCacheOptions.GetGraphicManagerTotalCacheSize(),
224*cdf0e10cSrcweir                                                       aCacheOptions.GetGraphicManagerObjectCacheSize() );
225*cdf0e10cSrcweir                     mpGlobalMgr->SetCacheTimeout( aCacheOptions.GetGraphicManagerObjectReleaseTime() );
226*cdf0e10cSrcweir 				}
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir 				mpMgr = mpGlobalMgr;
229*cdf0e10cSrcweir 			}
230*cdf0e10cSrcweir 			else
231*cdf0e10cSrcweir 				mpMgr = (GraphicManager*) pMgr;
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir 			mpMgr->ImplRegisterObj( *this, maGraphic, pID, pCopyObj );
234*cdf0e10cSrcweir 		}
235*cdf0e10cSrcweir 	}
236*cdf0e10cSrcweir }
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir // -----------------------------------------------------------------------------
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir void GraphicObject::ImplAutoSwapIn()
241*cdf0e10cSrcweir {
242*cdf0e10cSrcweir 	if( IsSwappedOut() )
243*cdf0e10cSrcweir 	{
244*cdf0e10cSrcweir 		if( mpMgr && mpMgr->ImplFillSwappedGraphicObject( *this, maGraphic ) )
245*cdf0e10cSrcweir 			mbAutoSwapped = sal_False;
246*cdf0e10cSrcweir 		else
247*cdf0e10cSrcweir 		{
248*cdf0e10cSrcweir 			mbIsInSwapIn = sal_True;
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir 			if( maGraphic.SwapIn() )
251*cdf0e10cSrcweir 				mbAutoSwapped = sal_False;
252*cdf0e10cSrcweir 			else
253*cdf0e10cSrcweir 			{
254*cdf0e10cSrcweir 				SvStream* pStream = GetSwapStream();
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir 				if( GRFMGR_AUTOSWAPSTREAM_NONE != pStream )
257*cdf0e10cSrcweir 				{
258*cdf0e10cSrcweir 					if( GRFMGR_AUTOSWAPSTREAM_LINK == pStream )
259*cdf0e10cSrcweir 					{
260*cdf0e10cSrcweir 						if( HasLink() )
261*cdf0e10cSrcweir 						{
262*cdf0e10cSrcweir 							String aURLStr;
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir 							if( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( GetLink(), aURLStr ) )
265*cdf0e10cSrcweir 							{
266*cdf0e10cSrcweir 								SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aURLStr, STREAM_READ );
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir 								if( pIStm )
269*cdf0e10cSrcweir 								{
270*cdf0e10cSrcweir 									(*pIStm) >> maGraphic;
271*cdf0e10cSrcweir 									mbAutoSwapped = ( maGraphic.GetType() != GRAPHIC_NONE );
272*cdf0e10cSrcweir 									delete pIStm;
273*cdf0e10cSrcweir 								}
274*cdf0e10cSrcweir 							}
275*cdf0e10cSrcweir 						}
276*cdf0e10cSrcweir 					}
277*cdf0e10cSrcweir 					else if( GRFMGR_AUTOSWAPSTREAM_TEMP == pStream )
278*cdf0e10cSrcweir 						mbAutoSwapped = !maGraphic.SwapIn();
279*cdf0e10cSrcweir 					else if( GRFMGR_AUTOSWAPSTREAM_LOADED == pStream )
280*cdf0e10cSrcweir 						mbAutoSwapped = maGraphic.IsSwapOut();
281*cdf0e10cSrcweir 					else
282*cdf0e10cSrcweir 					{
283*cdf0e10cSrcweir 						mbAutoSwapped = !maGraphic.SwapIn( pStream );
284*cdf0e10cSrcweir 						delete pStream;
285*cdf0e10cSrcweir 					}
286*cdf0e10cSrcweir 				}
287*cdf0e10cSrcweir 				else
288*cdf0e10cSrcweir 				{
289*cdf0e10cSrcweir 					DBG_ASSERT( ( GRAPHIC_NONE == meType ) || ( GRAPHIC_DEFAULT == meType ),
290*cdf0e10cSrcweir 								"GraphicObject::ImplAutoSwapIn: could not get stream to swap in graphic! (=>KA)" );
291*cdf0e10cSrcweir 				}
292*cdf0e10cSrcweir 			}
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir 			mbIsInSwapIn = sal_False;
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir 			if( !mbAutoSwapped && mpMgr )
297*cdf0e10cSrcweir 				mpMgr->ImplGraphicObjectWasSwappedIn( *this );
298*cdf0e10cSrcweir 		}
299*cdf0e10cSrcweir 	}
300*cdf0e10cSrcweir }
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir // -----------------------------------------------------------------------------
303*cdf0e10cSrcweir sal_Bool GraphicObject::ImplGetCropParams( OutputDevice* pOut, Point& rPt, Size& rSz, const GraphicAttr* pAttr,
304*cdf0e10cSrcweir 									   PolyPolygon& rClipPolyPoly, sal_Bool& bRectClipRegion ) const
305*cdf0e10cSrcweir {
306*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir 	if( GetType() != GRAPHIC_NONE )
309*cdf0e10cSrcweir 	{
310*cdf0e10cSrcweir 		Polygon			aClipPoly( Rectangle( rPt, rSz ) );
311*cdf0e10cSrcweir 		const sal_uInt16	nRot10 = pAttr->GetRotation() % 3600;
312*cdf0e10cSrcweir 		const Point		aOldOrigin( rPt );
313*cdf0e10cSrcweir         // --> OD 2005-09-30 #i54875# - It's not needed to get the graphic again.
314*cdf0e10cSrcweir //        const Graphic&  rGraphic = GetGraphic();
315*cdf0e10cSrcweir         // <--
316*cdf0e10cSrcweir 		const MapMode	aMap100( MAP_100TH_MM );
317*cdf0e10cSrcweir 		Size			aSize100;
318*cdf0e10cSrcweir 		long			nTotalWidth, nTotalHeight;
319*cdf0e10cSrcweir 		long			nNewLeft, nNewTop, nNewRight, nNewBottom;
320*cdf0e10cSrcweir 		double			fScale;
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir 		if( nRot10 )
323*cdf0e10cSrcweir 		{
324*cdf0e10cSrcweir 			aClipPoly.Rotate( rPt, nRot10 );
325*cdf0e10cSrcweir 			bRectClipRegion = sal_False;
326*cdf0e10cSrcweir 		}
327*cdf0e10cSrcweir 		else
328*cdf0e10cSrcweir 			bRectClipRegion = sal_True;
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir 		rClipPolyPoly = aClipPoly;
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir         // --> OD 2005-09-30 #i54875# - directly access member <maGraphic> to
333*cdf0e10cSrcweir         // get <PrefSize> and <PrefMapMode>.
334*cdf0e10cSrcweir //        if( rGraphic.GetPrefMapMode() == MAP_PIXEL )
335*cdf0e10cSrcweir //            aSize100 = Application::GetDefaultDevice()->PixelToLogic( rGraphic.GetPrefSize(), aMap100 );
336*cdf0e10cSrcweir //        else
337*cdf0e10cSrcweir //            aSize100 = pOut->LogicToLogic( rGraphic.GetPrefSize(), rGraphic.GetPrefMapMode(), aMap100 );
338*cdf0e10cSrcweir         if( maGraphic.GetPrefMapMode() == MAP_PIXEL )
339*cdf0e10cSrcweir             aSize100 = Application::GetDefaultDevice()->PixelToLogic( maGraphic.GetPrefSize(), aMap100 );
340*cdf0e10cSrcweir         else
341*cdf0e10cSrcweir         {
342*cdf0e10cSrcweir             MapMode m(maGraphic.GetPrefMapMode());
343*cdf0e10cSrcweir             aSize100 = pOut->LogicToLogic( maGraphic.GetPrefSize(), &m, &aMap100 );
344*cdf0e10cSrcweir         }
345*cdf0e10cSrcweir         // <--
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir 		nTotalWidth = aSize100.Width() - pAttr->GetLeftCrop() - pAttr->GetRightCrop();
348*cdf0e10cSrcweir 		nTotalHeight = aSize100.Height() - pAttr->GetTopCrop() - pAttr->GetBottomCrop();
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir 		if( aSize100.Width() > 0 && aSize100.Height() > 0 && nTotalWidth > 0 && nTotalHeight > 0 )
351*cdf0e10cSrcweir 		{
352*cdf0e10cSrcweir 			fScale = (double) aSize100.Width() / nTotalWidth;
353*cdf0e10cSrcweir 			nNewLeft = -FRound( ( ( pAttr->GetMirrorFlags() & BMP_MIRROR_HORZ ) ? pAttr->GetRightCrop() : pAttr->GetLeftCrop() ) * fScale );
354*cdf0e10cSrcweir 			nNewRight = nNewLeft + FRound( aSize100.Width() * fScale ) - 1;
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir 			fScale = (double) rSz.Width() / aSize100.Width();
357*cdf0e10cSrcweir 			rPt.X() += FRound( nNewLeft * fScale );
358*cdf0e10cSrcweir 			rSz.Width() = FRound( ( nNewRight - nNewLeft + 1 ) * fScale );
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir 			fScale = (double) aSize100.Height() / nTotalHeight;
361*cdf0e10cSrcweir 			nNewTop = -FRound( ( ( pAttr->GetMirrorFlags() & BMP_MIRROR_VERT ) ? pAttr->GetBottomCrop() : pAttr->GetTopCrop() ) * fScale );
362*cdf0e10cSrcweir 			nNewBottom = nNewTop + FRound( aSize100.Height() * fScale ) - 1;
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir 			fScale = (double) rSz.Height() / aSize100.Height();
365*cdf0e10cSrcweir 			rPt.Y() += FRound( nNewTop * fScale );
366*cdf0e10cSrcweir 			rSz.Height() = FRound( ( nNewBottom - nNewTop + 1 ) * fScale );
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir 			if( nRot10 )
369*cdf0e10cSrcweir 			{
370*cdf0e10cSrcweir 				Polygon aOriginPoly( 1 );
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir 				aOriginPoly[ 0 ] = rPt;
373*cdf0e10cSrcweir 				aOriginPoly.Rotate( aOldOrigin, nRot10 );
374*cdf0e10cSrcweir 				rPt = aOriginPoly[ 0 ];
375*cdf0e10cSrcweir 			}
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir 			bRet = sal_True;
378*cdf0e10cSrcweir 		}
379*cdf0e10cSrcweir 	}
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir 	return bRet;
382*cdf0e10cSrcweir }
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir // -----------------------------------------------------------------------------
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir GraphicObject& GraphicObject::operator=( const GraphicObject& rGraphicObj )
387*cdf0e10cSrcweir {
388*cdf0e10cSrcweir 	if( &rGraphicObj != this )
389*cdf0e10cSrcweir 	{
390*cdf0e10cSrcweir 		mpMgr->ImplUnregisterObj( *this );
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir 		delete mpSwapStreamHdl, mpSwapStreamHdl = NULL;
393*cdf0e10cSrcweir 		delete mpSimpleCache, mpSimpleCache = NULL;
394*cdf0e10cSrcweir 		delete mpLink;
395*cdf0e10cSrcweir 		delete mpUserData;
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir 		maGraphic = rGraphicObj.GetGraphic();
398*cdf0e10cSrcweir 		maAttr = rGraphicObj.maAttr;
399*cdf0e10cSrcweir 		mpLink = rGraphicObj.mpLink ? new String( *rGraphicObj.mpLink ) : NULL;
400*cdf0e10cSrcweir 		mpUserData = rGraphicObj.mpUserData ? new String( *rGraphicObj.mpUserData ) : NULL;
401*cdf0e10cSrcweir 		ImplAssignGraphicData();
402*cdf0e10cSrcweir 		mbAutoSwapped = sal_False;
403*cdf0e10cSrcweir 		mpMgr = rGraphicObj.mpMgr;
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir 		mpMgr->ImplRegisterObj( *this, maGraphic, NULL, &rGraphicObj );
406*cdf0e10cSrcweir 	}
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir 	return *this;
409*cdf0e10cSrcweir }
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir // -----------------------------------------------------------------------------
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir sal_Bool GraphicObject::operator==( const GraphicObject& rGraphicObj ) const
414*cdf0e10cSrcweir {
415*cdf0e10cSrcweir 	return(	( rGraphicObj.maGraphic == maGraphic ) &&
416*cdf0e10cSrcweir 			( rGraphicObj.maAttr == maAttr ) &&
417*cdf0e10cSrcweir 			( rGraphicObj.GetLink() == GetLink() ) );
418*cdf0e10cSrcweir }
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir // ------------------------------------------------------------------------
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir void GraphicObject::Load( SvStream& rIStm )
423*cdf0e10cSrcweir {
424*cdf0e10cSrcweir     rIStm >> *this;
425*cdf0e10cSrcweir }
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir // ------------------------------------------------------------------------
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir void GraphicObject::Save( SvStream& rOStm )
430*cdf0e10cSrcweir {
431*cdf0e10cSrcweir     rOStm << *this;
432*cdf0e10cSrcweir }
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir // ------------------------------------------------------------------------
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir void GraphicObject::Assign( const SvDataCopyStream& rCopyStream )
437*cdf0e10cSrcweir {
438*cdf0e10cSrcweir     *this = (const GraphicObject& ) rCopyStream;
439*cdf0e10cSrcweir }
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir // -----------------------------------------------------------------------------
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir ByteString GraphicObject::GetUniqueID() const
444*cdf0e10cSrcweir {
445*cdf0e10cSrcweir 	if ( !IsInSwapIn() && ( IsEPS() || IsRenderGraphic() ) )
446*cdf0e10cSrcweir 		const_cast<GraphicObject*>(this)->FireSwapInRequest();
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir 	ByteString aRet;
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir 	if( mpMgr )
451*cdf0e10cSrcweir 		aRet = mpMgr->ImplGetUniqueID( *this );
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir 	return aRet;
454*cdf0e10cSrcweir }
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir // -----------------------------------------------------------------------------
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir sal_uLong GraphicObject::GetChecksum() const
459*cdf0e10cSrcweir {
460*cdf0e10cSrcweir 	return( ( maGraphic.IsSupportedGraphic() && !maGraphic.IsSwapOut() ) ? maGraphic.GetChecksum() : 0 );
461*cdf0e10cSrcweir }
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir // -----------------------------------------------------------------------------
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir SvStream* GraphicObject::GetSwapStream() const
466*cdf0e10cSrcweir {
467*cdf0e10cSrcweir 	return( HasSwapStreamHdl() ? (SvStream*) mpSwapStreamHdl->Call( (void*) this ) : GRFMGR_AUTOSWAPSTREAM_NONE );
468*cdf0e10cSrcweir }
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir // -----------------------------------------------------------------------------
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir // !!! to be removed
473*cdf0e10cSrcweir sal_uLong GraphicObject::GetReleaseFromCache() const
474*cdf0e10cSrcweir {
475*cdf0e10cSrcweir 	return 0;
476*cdf0e10cSrcweir }
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir // -----------------------------------------------------------------------------
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir void GraphicObject::SetAttr( const GraphicAttr& rAttr )
481*cdf0e10cSrcweir {
482*cdf0e10cSrcweir 	maAttr = rAttr;
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir 	if( mpSimpleCache && ( mpSimpleCache->maAttr != rAttr ) )
485*cdf0e10cSrcweir 		delete mpSimpleCache, mpSimpleCache = NULL;
486*cdf0e10cSrcweir }
487*cdf0e10cSrcweir 
488*cdf0e10cSrcweir // -----------------------------------------------------------------------------
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir void GraphicObject::SetLink()
491*cdf0e10cSrcweir {
492*cdf0e10cSrcweir 	if( mpLink )
493*cdf0e10cSrcweir 		delete mpLink, mpLink = NULL;
494*cdf0e10cSrcweir }
495*cdf0e10cSrcweir 
496*cdf0e10cSrcweir // -----------------------------------------------------------------------------
497*cdf0e10cSrcweir 
498*cdf0e10cSrcweir void GraphicObject::SetLink( const String& rLink )
499*cdf0e10cSrcweir {
500*cdf0e10cSrcweir 	delete mpLink, mpLink = new String( rLink );
501*cdf0e10cSrcweir }
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir // -----------------------------------------------------------------------------
504*cdf0e10cSrcweir 
505*cdf0e10cSrcweir String GraphicObject::GetLink() const
506*cdf0e10cSrcweir {
507*cdf0e10cSrcweir 	if( mpLink )
508*cdf0e10cSrcweir 		return *mpLink;
509*cdf0e10cSrcweir 	else
510*cdf0e10cSrcweir 		return String();
511*cdf0e10cSrcweir }
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir // -----------------------------------------------------------------------------
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir void GraphicObject::SetUserData()
516*cdf0e10cSrcweir {
517*cdf0e10cSrcweir 	if( mpUserData )
518*cdf0e10cSrcweir 		delete mpUserData, mpUserData = NULL;
519*cdf0e10cSrcweir }
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir // -----------------------------------------------------------------------------
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir void GraphicObject::SetUserData( const String& rUserData )
524*cdf0e10cSrcweir {
525*cdf0e10cSrcweir 	delete mpUserData, mpUserData = new String( rUserData );
526*cdf0e10cSrcweir }
527*cdf0e10cSrcweir 
528*cdf0e10cSrcweir // -----------------------------------------------------------------------------
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir String GraphicObject::GetUserData() const
531*cdf0e10cSrcweir {
532*cdf0e10cSrcweir 	if( mpUserData )
533*cdf0e10cSrcweir 		return *mpUserData;
534*cdf0e10cSrcweir 	else
535*cdf0e10cSrcweir 		return String();
536*cdf0e10cSrcweir }
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir // -----------------------------------------------------------------------------
539*cdf0e10cSrcweir 
540*cdf0e10cSrcweir void GraphicObject::SetSwapStreamHdl()
541*cdf0e10cSrcweir {
542*cdf0e10cSrcweir 	if( mpSwapStreamHdl )
543*cdf0e10cSrcweir 	{
544*cdf0e10cSrcweir 		delete mpSwapOutTimer, mpSwapOutTimer = NULL;
545*cdf0e10cSrcweir 		delete mpSwapStreamHdl, mpSwapStreamHdl = NULL;
546*cdf0e10cSrcweir 	}
547*cdf0e10cSrcweir }
548*cdf0e10cSrcweir 
549*cdf0e10cSrcweir // -----------------------------------------------------------------------------
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir void GraphicObject::SetSwapStreamHdl( const Link& rHdl, const sal_uLong nSwapOutTimeout )
552*cdf0e10cSrcweir {
553*cdf0e10cSrcweir 	delete mpSwapStreamHdl,	mpSwapStreamHdl = new Link( rHdl );
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir 	if( nSwapOutTimeout )
556*cdf0e10cSrcweir 	{
557*cdf0e10cSrcweir 		if( !mpSwapOutTimer )
558*cdf0e10cSrcweir 		{
559*cdf0e10cSrcweir 			mpSwapOutTimer = new Timer;
560*cdf0e10cSrcweir 			mpSwapOutTimer->SetTimeoutHdl( LINK( this, GraphicObject, ImplAutoSwapOutHdl ) );
561*cdf0e10cSrcweir 		}
562*cdf0e10cSrcweir 
563*cdf0e10cSrcweir 		mpSwapOutTimer->SetTimeout( nSwapOutTimeout );
564*cdf0e10cSrcweir 		mpSwapOutTimer->Start();
565*cdf0e10cSrcweir 	}
566*cdf0e10cSrcweir 	else
567*cdf0e10cSrcweir 		delete mpSwapOutTimer, mpSwapOutTimer = NULL;
568*cdf0e10cSrcweir }
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir // -----------------------------------------------------------------------------
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir Link GraphicObject::GetSwapStreamHdl() const
573*cdf0e10cSrcweir {
574*cdf0e10cSrcweir 	if( mpSwapStreamHdl )
575*cdf0e10cSrcweir 		return *mpSwapStreamHdl;
576*cdf0e10cSrcweir 	else
577*cdf0e10cSrcweir 		return Link();
578*cdf0e10cSrcweir }
579*cdf0e10cSrcweir 
580*cdf0e10cSrcweir // -----------------------------------------------------------------------------
581*cdf0e10cSrcweir 
582*cdf0e10cSrcweir void GraphicObject::FireSwapInRequest()
583*cdf0e10cSrcweir {
584*cdf0e10cSrcweir 	ImplAutoSwapIn();
585*cdf0e10cSrcweir }
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir // -----------------------------------------------------------------------------
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir void GraphicObject::FireSwapOutRequest()
590*cdf0e10cSrcweir {
591*cdf0e10cSrcweir 	ImplAutoSwapOutHdl( NULL );
592*cdf0e10cSrcweir }
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir // -----------------------------------------------------------------------------
595*cdf0e10cSrcweir 
596*cdf0e10cSrcweir void GraphicObject::GraphicManagerDestroyed()
597*cdf0e10cSrcweir {
598*cdf0e10cSrcweir 	// we're alive, but our manager doesn't live anymore ==> connect to default manager
599*cdf0e10cSrcweir 	mpMgr = NULL;
600*cdf0e10cSrcweir 	ImplSetGraphicManager( NULL );
601*cdf0e10cSrcweir }
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir // -----------------------------------------------------------------------------
604*cdf0e10cSrcweir 
605*cdf0e10cSrcweir void GraphicObject::SetGraphicManager( const GraphicManager& rMgr )
606*cdf0e10cSrcweir {
607*cdf0e10cSrcweir 	ImplSetGraphicManager( &rMgr );
608*cdf0e10cSrcweir }
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir // -----------------------------------------------------------------------------
611*cdf0e10cSrcweir 
612*cdf0e10cSrcweir sal_Bool GraphicObject::IsCached( OutputDevice* pOut, const Point& rPt, const Size& rSz,
613*cdf0e10cSrcweir 							  const GraphicAttr* pAttr, sal_uLong nFlags ) const
614*cdf0e10cSrcweir {
615*cdf0e10cSrcweir 	sal_Bool bRet;
616*cdf0e10cSrcweir 
617*cdf0e10cSrcweir 	if( nFlags & GRFMGR_DRAW_CACHED )
618*cdf0e10cSrcweir     {
619*cdf0e10cSrcweir         // --> OD 2005-10-11 #i54875# - Consider cropped graphics.
620*cdf0e10cSrcweir         // Note: The graphic manager caches a cropped graphic with its
621*cdf0e10cSrcweir         //       uncropped position and size.
622*cdf0e10cSrcweir //        bRet = mpMgr->IsInCache( pOut, rPt, rSz, *this, ( pAttr ? *pAttr : GetAttr() ) );
623*cdf0e10cSrcweir         Point aPt( rPt );
624*cdf0e10cSrcweir         Size aSz( rSz );
625*cdf0e10cSrcweir         if ( pAttr->IsCropped() )
626*cdf0e10cSrcweir         {
627*cdf0e10cSrcweir             PolyPolygon aClipPolyPoly;
628*cdf0e10cSrcweir             sal_Bool        bRectClip;
629*cdf0e10cSrcweir             ImplGetCropParams( pOut, aPt, aSz, pAttr, aClipPolyPoly, bRectClip );
630*cdf0e10cSrcweir         }
631*cdf0e10cSrcweir         bRet = mpMgr->IsInCache( pOut, aPt, aSz, *this, ( pAttr ? *pAttr : GetAttr() ) );
632*cdf0e10cSrcweir     }
633*cdf0e10cSrcweir 	else
634*cdf0e10cSrcweir 		bRet = sal_False;
635*cdf0e10cSrcweir 
636*cdf0e10cSrcweir 	return bRet;
637*cdf0e10cSrcweir }
638*cdf0e10cSrcweir 
639*cdf0e10cSrcweir // -----------------------------------------------------------------------------
640*cdf0e10cSrcweir 
641*cdf0e10cSrcweir void GraphicObject::ReleaseFromCache()
642*cdf0e10cSrcweir {
643*cdf0e10cSrcweir 
644*cdf0e10cSrcweir 	mpMgr->ReleaseFromCache( *this );
645*cdf0e10cSrcweir }
646*cdf0e10cSrcweir 
647*cdf0e10cSrcweir // -----------------------------------------------------------------------------
648*cdf0e10cSrcweir 
649*cdf0e10cSrcweir void GraphicObject::SetAnimationNotifyHdl( const Link& rLink )
650*cdf0e10cSrcweir {
651*cdf0e10cSrcweir 	maGraphic.SetAnimationNotifyHdl( rLink );
652*cdf0e10cSrcweir }
653*cdf0e10cSrcweir 
654*cdf0e10cSrcweir // -----------------------------------------------------------------------------
655*cdf0e10cSrcweir 
656*cdf0e10cSrcweir List* GraphicObject::GetAnimationInfoList() const
657*cdf0e10cSrcweir {
658*cdf0e10cSrcweir 	return maGraphic.GetAnimationInfoList();
659*cdf0e10cSrcweir }
660*cdf0e10cSrcweir 
661*cdf0e10cSrcweir // -----------------------------------------------------------------------------
662*cdf0e10cSrcweir 
663*cdf0e10cSrcweir sal_Bool GraphicObject::Draw( OutputDevice* pOut, const Point& rPt, const Size& rSz,
664*cdf0e10cSrcweir 						  const GraphicAttr* pAttr, sal_uLong nFlags )
665*cdf0e10cSrcweir {
666*cdf0e10cSrcweir 	GraphicAttr	        aAttr( pAttr ? *pAttr : GetAttr() );
667*cdf0e10cSrcweir 	Point 		        aPt( rPt );
668*cdf0e10cSrcweir 	Size  	            aSz( rSz );
669*cdf0e10cSrcweir     const sal_uInt32    nOldDrawMode = pOut->GetDrawMode();
670*cdf0e10cSrcweir 	sal_Bool		        bCropped = aAttr.IsCropped();
671*cdf0e10cSrcweir 	sal_Bool		        bCached = sal_False;
672*cdf0e10cSrcweir 	sal_Bool		        bRet;
673*cdf0e10cSrcweir 
674*cdf0e10cSrcweir     // #i29534# Provide output rects for PDF writer
675*cdf0e10cSrcweir     Rectangle			aCropRect;
676*cdf0e10cSrcweir 
677*cdf0e10cSrcweir     if( !( GRFMGR_DRAW_USE_DRAWMODE_SETTINGS & nFlags ) )
678*cdf0e10cSrcweir         pOut->SetDrawMode( nOldDrawMode & ( ~( DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT ) ) );
679*cdf0e10cSrcweir 
680*cdf0e10cSrcweir 	// mirrored horizontically
681*cdf0e10cSrcweir 	if( aSz.Width() < 0L )
682*cdf0e10cSrcweir 	{
683*cdf0e10cSrcweir 		aPt.X() += aSz.Width() + 1;
684*cdf0e10cSrcweir 		aSz.Width() = -aSz.Width();
685*cdf0e10cSrcweir 		aAttr.SetMirrorFlags( aAttr.GetMirrorFlags() ^ BMP_MIRROR_HORZ );
686*cdf0e10cSrcweir 	}
687*cdf0e10cSrcweir 
688*cdf0e10cSrcweir 	// mirrored vertically
689*cdf0e10cSrcweir 	if( aSz.Height() < 0L )
690*cdf0e10cSrcweir 	{
691*cdf0e10cSrcweir 		aPt.Y() += aSz.Height() + 1;
692*cdf0e10cSrcweir 		aSz.Height() = -aSz.Height();
693*cdf0e10cSrcweir 		aAttr.SetMirrorFlags( aAttr.GetMirrorFlags() ^ BMP_MIRROR_VERT );
694*cdf0e10cSrcweir 	}
695*cdf0e10cSrcweir 
696*cdf0e10cSrcweir 	if( bCropped )
697*cdf0e10cSrcweir 	{
698*cdf0e10cSrcweir 		PolyPolygon aClipPolyPoly;
699*cdf0e10cSrcweir 		sal_Bool		bRectClip;
700*cdf0e10cSrcweir 		const sal_Bool	bCrop = ImplGetCropParams( pOut, aPt, aSz, &aAttr, aClipPolyPoly, bRectClip );
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir 		pOut->Push( PUSH_CLIPREGION );
703*cdf0e10cSrcweir 
704*cdf0e10cSrcweir 		if( bCrop )
705*cdf0e10cSrcweir 		{
706*cdf0e10cSrcweir 			if( bRectClip )
707*cdf0e10cSrcweir             {
708*cdf0e10cSrcweir                 // #i29534# Store crop rect for later forwarding to
709*cdf0e10cSrcweir                 // PDF writer
710*cdf0e10cSrcweir                 aCropRect = aClipPolyPoly.GetBoundRect();
711*cdf0e10cSrcweir 				pOut->IntersectClipRegion( aCropRect );
712*cdf0e10cSrcweir             }
713*cdf0e10cSrcweir 			else
714*cdf0e10cSrcweir             {
715*cdf0e10cSrcweir 				pOut->IntersectClipRegion( aClipPolyPoly );
716*cdf0e10cSrcweir             }
717*cdf0e10cSrcweir 		}
718*cdf0e10cSrcweir 	}
719*cdf0e10cSrcweir 
720*cdf0e10cSrcweir 	bRet = mpMgr->DrawObj( pOut, aPt, aSz, *this, aAttr, nFlags, bCached );
721*cdf0e10cSrcweir 
722*cdf0e10cSrcweir 	if( bCropped )
723*cdf0e10cSrcweir 		pOut->Pop();
724*cdf0e10cSrcweir 
725*cdf0e10cSrcweir     pOut->SetDrawMode( nOldDrawMode );
726*cdf0e10cSrcweir 
727*cdf0e10cSrcweir     // #i29534# Moved below OutDev restoration, to avoid multiple swap-ins
728*cdf0e10cSrcweir     // (code above needs to call GetGraphic twice)
729*cdf0e10cSrcweir 	if( bCached )
730*cdf0e10cSrcweir 	{
731*cdf0e10cSrcweir 		if( mpSwapOutTimer )
732*cdf0e10cSrcweir 			mpSwapOutTimer->Start();
733*cdf0e10cSrcweir 		else
734*cdf0e10cSrcweir 			FireSwapOutRequest();
735*cdf0e10cSrcweir 	}
736*cdf0e10cSrcweir 
737*cdf0e10cSrcweir 	return bRet;
738*cdf0e10cSrcweir }
739*cdf0e10cSrcweir 
740*cdf0e10cSrcweir // --> OD 2010-01-04 #i105243#
741*cdf0e10cSrcweir sal_Bool GraphicObject::DrawWithPDFHandling( OutputDevice& rOutDev,
742*cdf0e10cSrcweir                                          const Point& rPt, const Size& rSz,
743*cdf0e10cSrcweir                                          const GraphicAttr* pGrfAttr,
744*cdf0e10cSrcweir                                          const sal_uLong nFlags )
745*cdf0e10cSrcweir {
746*cdf0e10cSrcweir     const GraphicAttr aGrfAttr( pGrfAttr ? *pGrfAttr : GetAttr() );
747*cdf0e10cSrcweir 
748*cdf0e10cSrcweir     // Notify PDF writer about linked graphic (if any)
749*cdf0e10cSrcweir     sal_Bool bWritingPdfLinkedGraphic( sal_False );
750*cdf0e10cSrcweir     Point aPt( rPt );
751*cdf0e10cSrcweir     Size aSz( rSz );
752*cdf0e10cSrcweir     Rectangle aCropRect;
753*cdf0e10cSrcweir     vcl::PDFExtOutDevData* pPDFExtOutDevData =
754*cdf0e10cSrcweir             dynamic_cast<vcl::PDFExtOutDevData*>(rOutDev.GetExtOutDevData());
755*cdf0e10cSrcweir     if( pPDFExtOutDevData )
756*cdf0e10cSrcweir     {
757*cdf0e10cSrcweir         // only delegate image handling to PDF, if no special treatment is necessary
758*cdf0e10cSrcweir         if( GetGraphic().IsLink() &&
759*cdf0e10cSrcweir             rSz.Width() > 0L &&
760*cdf0e10cSrcweir             rSz.Height() > 0L &&
761*cdf0e10cSrcweir             !aGrfAttr.IsSpecialDrawMode() &&
762*cdf0e10cSrcweir             !aGrfAttr.IsMirrored() &&
763*cdf0e10cSrcweir             !aGrfAttr.IsRotated() &&
764*cdf0e10cSrcweir             !aGrfAttr.IsAdjusted() )
765*cdf0e10cSrcweir         {
766*cdf0e10cSrcweir             bWritingPdfLinkedGraphic = true;
767*cdf0e10cSrcweir 
768*cdf0e10cSrcweir             if( aGrfAttr.IsCropped() )
769*cdf0e10cSrcweir             {
770*cdf0e10cSrcweir                 PolyPolygon aClipPolyPoly;
771*cdf0e10cSrcweir                 sal_Bool bRectClip;
772*cdf0e10cSrcweir                 const sal_Bool bCrop = ImplGetCropParams( &rOutDev,
773*cdf0e10cSrcweir                                                       aPt, aSz,
774*cdf0e10cSrcweir                                                       &aGrfAttr,
775*cdf0e10cSrcweir                                                       aClipPolyPoly,
776*cdf0e10cSrcweir                                                       bRectClip );
777*cdf0e10cSrcweir                 if ( bCrop && bRectClip )
778*cdf0e10cSrcweir                 {
779*cdf0e10cSrcweir                     aCropRect = aClipPolyPoly.GetBoundRect();
780*cdf0e10cSrcweir                 }
781*cdf0e10cSrcweir             }
782*cdf0e10cSrcweir 
783*cdf0e10cSrcweir             pPDFExtOutDevData->BeginGroup();
784*cdf0e10cSrcweir         }
785*cdf0e10cSrcweir     }
786*cdf0e10cSrcweir 
787*cdf0e10cSrcweir     sal_Bool bRet = Draw( &rOutDev, rPt, rSz, &aGrfAttr, nFlags );
788*cdf0e10cSrcweir 
789*cdf0e10cSrcweir     // Notify PDF writer about linked graphic (if any)
790*cdf0e10cSrcweir     if( bWritingPdfLinkedGraphic )
791*cdf0e10cSrcweir     {
792*cdf0e10cSrcweir         pPDFExtOutDevData->EndGroup( const_cast< Graphic& >(GetGraphic()),
793*cdf0e10cSrcweir                                      aGrfAttr.GetTransparency(),
794*cdf0e10cSrcweir                                      Rectangle( aPt, aSz ),
795*cdf0e10cSrcweir                                      aCropRect );
796*cdf0e10cSrcweir     }
797*cdf0e10cSrcweir 
798*cdf0e10cSrcweir     return bRet;
799*cdf0e10cSrcweir }
800*cdf0e10cSrcweir // <--
801*cdf0e10cSrcweir 
802*cdf0e10cSrcweir // -----------------------------------------------------------------------------
803*cdf0e10cSrcweir 
804*cdf0e10cSrcweir sal_Bool GraphicObject::DrawTiled( OutputDevice* pOut, const Rectangle& rArea, const Size& rSize,
805*cdf0e10cSrcweir                                const Size& rOffset, const GraphicAttr* pAttr, sal_uLong nFlags, int nTileCacheSize1D )
806*cdf0e10cSrcweir {
807*cdf0e10cSrcweir     if( pOut == NULL || rSize.Width() == 0 || rSize.Height() == 0 )
808*cdf0e10cSrcweir         return sal_False;
809*cdf0e10cSrcweir 
810*cdf0e10cSrcweir     const MapMode 	aOutMapMode( pOut->GetMapMode() );
811*cdf0e10cSrcweir     const MapMode	aMapMode( aOutMapMode.GetMapUnit(), Point(), aOutMapMode.GetScaleX(), aOutMapMode.GetScaleY() );
812*cdf0e10cSrcweir     // #106258# Clamp size to 1 for zero values. This is okay, since
813*cdf0e10cSrcweir     // logical size of zero is handled above already
814*cdf0e10cSrcweir     const Size		aOutTileSize( ::std::max( 1L, pOut->LogicToPixel( rSize, aOutMapMode ).Width() ),
815*cdf0e10cSrcweir                                   ::std::max( 1L, pOut->LogicToPixel( rSize, aOutMapMode ).Height() ) );
816*cdf0e10cSrcweir 
817*cdf0e10cSrcweir 	//#i69780 clip final tile size to a sane max size
818*cdf0e10cSrcweir     while (((sal_Int64)rSize.Width() * nTileCacheSize1D) > SAL_MAX_UINT16)
819*cdf0e10cSrcweir         nTileCacheSize1D /= 2;
820*cdf0e10cSrcweir     while (((sal_Int64)rSize.Height() * nTileCacheSize1D) > SAL_MAX_UINT16)
821*cdf0e10cSrcweir         nTileCacheSize1D /= 2;
822*cdf0e10cSrcweir 
823*cdf0e10cSrcweir     return ImplDrawTiled( pOut, rArea, aOutTileSize, rOffset, pAttr, nFlags, nTileCacheSize1D );
824*cdf0e10cSrcweir }
825*cdf0e10cSrcweir 
826*cdf0e10cSrcweir // -----------------------------------------------------------------------------
827*cdf0e10cSrcweir 
828*cdf0e10cSrcweir sal_Bool GraphicObject::StartAnimation( OutputDevice* pOut, const Point& rPt, const Size& rSz,
829*cdf0e10cSrcweir 									long nExtraData, const GraphicAttr* pAttr, sal_uLong /*nFlags*/,
830*cdf0e10cSrcweir 									OutputDevice* pFirstFrameOutDev )
831*cdf0e10cSrcweir {
832*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
833*cdf0e10cSrcweir 
834*cdf0e10cSrcweir 	GetGraphic();
835*cdf0e10cSrcweir 
836*cdf0e10cSrcweir 	if( !IsSwappedOut() )
837*cdf0e10cSrcweir 	{
838*cdf0e10cSrcweir     	const GraphicAttr aAttr( pAttr ? *pAttr : GetAttr() );
839*cdf0e10cSrcweir 
840*cdf0e10cSrcweir 		if( mbAnimated )
841*cdf0e10cSrcweir 		{
842*cdf0e10cSrcweir 			Point   aPt( rPt );
843*cdf0e10cSrcweir 			Size	aSz( rSz );
844*cdf0e10cSrcweir 			sal_Bool	bCropped = aAttr.IsCropped();
845*cdf0e10cSrcweir 
846*cdf0e10cSrcweir 			if( bCropped )
847*cdf0e10cSrcweir 			{
848*cdf0e10cSrcweir 				PolyPolygon aClipPolyPoly;
849*cdf0e10cSrcweir 				sal_Bool		bRectClip;
850*cdf0e10cSrcweir 				const sal_Bool	bCrop = ImplGetCropParams( pOut, aPt, aSz, &aAttr, aClipPolyPoly, bRectClip );
851*cdf0e10cSrcweir 
852*cdf0e10cSrcweir 				pOut->Push( PUSH_CLIPREGION );
853*cdf0e10cSrcweir 
854*cdf0e10cSrcweir 				if( bCrop )
855*cdf0e10cSrcweir 				{
856*cdf0e10cSrcweir 					if( bRectClip )
857*cdf0e10cSrcweir 						pOut->IntersectClipRegion( aClipPolyPoly.GetBoundRect() );
858*cdf0e10cSrcweir 					else
859*cdf0e10cSrcweir 						pOut->IntersectClipRegion( aClipPolyPoly );
860*cdf0e10cSrcweir 				}
861*cdf0e10cSrcweir 			}
862*cdf0e10cSrcweir 
863*cdf0e10cSrcweir 			if( !mpSimpleCache || ( mpSimpleCache->maAttr != aAttr ) || pFirstFrameOutDev )
864*cdf0e10cSrcweir 			{
865*cdf0e10cSrcweir 				if( mpSimpleCache )
866*cdf0e10cSrcweir 					delete mpSimpleCache;
867*cdf0e10cSrcweir 
868*cdf0e10cSrcweir 				mpSimpleCache = new GrfSimpleCacheObj( GetTransformedGraphic( &aAttr ), aAttr );
869*cdf0e10cSrcweir 				mpSimpleCache->maGraphic.SetAnimationNotifyHdl( GetAnimationNotifyHdl() );
870*cdf0e10cSrcweir 			}
871*cdf0e10cSrcweir 
872*cdf0e10cSrcweir 			mpSimpleCache->maGraphic.StartAnimation( pOut, aPt, aSz, nExtraData, pFirstFrameOutDev );
873*cdf0e10cSrcweir 
874*cdf0e10cSrcweir 			if( bCropped )
875*cdf0e10cSrcweir 				pOut->Pop();
876*cdf0e10cSrcweir 
877*cdf0e10cSrcweir 			bRet = sal_True;
878*cdf0e10cSrcweir 		}
879*cdf0e10cSrcweir 		else
880*cdf0e10cSrcweir 			bRet = Draw( pOut, rPt, rSz, &aAttr, GRFMGR_DRAW_STANDARD );
881*cdf0e10cSrcweir 	}
882*cdf0e10cSrcweir 
883*cdf0e10cSrcweir 	return bRet;
884*cdf0e10cSrcweir }
885*cdf0e10cSrcweir 
886*cdf0e10cSrcweir // -----------------------------------------------------------------------------
887*cdf0e10cSrcweir 
888*cdf0e10cSrcweir void GraphicObject::StopAnimation( OutputDevice* pOut, long nExtraData )
889*cdf0e10cSrcweir {
890*cdf0e10cSrcweir 	if( mpSimpleCache )
891*cdf0e10cSrcweir 		mpSimpleCache->maGraphic.StopAnimation( pOut, nExtraData );
892*cdf0e10cSrcweir }
893*cdf0e10cSrcweir 
894*cdf0e10cSrcweir // -----------------------------------------------------------------------------
895*cdf0e10cSrcweir 
896*cdf0e10cSrcweir const Graphic& GraphicObject::GetGraphic() const
897*cdf0e10cSrcweir {
898*cdf0e10cSrcweir 	if( mbAutoSwapped )
899*cdf0e10cSrcweir 		( (GraphicObject*) this )->ImplAutoSwapIn();
900*cdf0e10cSrcweir 
901*cdf0e10cSrcweir 	return maGraphic;
902*cdf0e10cSrcweir }
903*cdf0e10cSrcweir 
904*cdf0e10cSrcweir // -----------------------------------------------------------------------------
905*cdf0e10cSrcweir 
906*cdf0e10cSrcweir void GraphicObject::SetGraphic( const Graphic& rGraphic, const GraphicObject* pCopyObj )
907*cdf0e10cSrcweir {
908*cdf0e10cSrcweir 	mpMgr->ImplUnregisterObj( *this );
909*cdf0e10cSrcweir 
910*cdf0e10cSrcweir 	if( mpSwapOutTimer )
911*cdf0e10cSrcweir 		mpSwapOutTimer->Stop();
912*cdf0e10cSrcweir 
913*cdf0e10cSrcweir 	maGraphic = rGraphic;
914*cdf0e10cSrcweir 	mbAutoSwapped = sal_False;
915*cdf0e10cSrcweir 	ImplAssignGraphicData();
916*cdf0e10cSrcweir 	delete mpLink, mpLink = NULL;
917*cdf0e10cSrcweir 	delete mpSimpleCache, mpSimpleCache = NULL;
918*cdf0e10cSrcweir 
919*cdf0e10cSrcweir 	mpMgr->ImplRegisterObj( *this, maGraphic, 0, pCopyObj);
920*cdf0e10cSrcweir 
921*cdf0e10cSrcweir 	if( mpSwapOutTimer )
922*cdf0e10cSrcweir 		mpSwapOutTimer->Start();
923*cdf0e10cSrcweir }
924*cdf0e10cSrcweir 
925*cdf0e10cSrcweir // -----------------------------------------------------------------------------
926*cdf0e10cSrcweir 
927*cdf0e10cSrcweir void GraphicObject::SetGraphic( const Graphic& rGraphic, const String& rLink )
928*cdf0e10cSrcweir {
929*cdf0e10cSrcweir 	SetGraphic( rGraphic );
930*cdf0e10cSrcweir 	mpLink = new String( rLink );
931*cdf0e10cSrcweir }
932*cdf0e10cSrcweir 
933*cdf0e10cSrcweir // -----------------------------------------------------------------------------
934*cdf0e10cSrcweir 
935*cdf0e10cSrcweir Graphic GraphicObject::GetTransformedGraphic( const Size& rDestSize, const MapMode& rDestMap, const GraphicAttr& rAttr ) const
936*cdf0e10cSrcweir {
937*cdf0e10cSrcweir     // #104550# Extracted from svx/source/svdraw/svdograf.cxx
938*cdf0e10cSrcweir 	Graphic		    	aTransGraphic( maGraphic );
939*cdf0e10cSrcweir 	const GraphicType	eType = GetType();
940*cdf0e10cSrcweir     const Size      	aSrcSize( aTransGraphic.GetPrefSize() );
941*cdf0e10cSrcweir 
942*cdf0e10cSrcweir     // #104115# Convert the crop margins to graphic object mapmode
943*cdf0e10cSrcweir     const MapMode aMapGraph( aTransGraphic.GetPrefMapMode() );
944*cdf0e10cSrcweir     const MapMode aMap100( MAP_100TH_MM );
945*cdf0e10cSrcweir 
946*cdf0e10cSrcweir     Size aCropLeftTop;
947*cdf0e10cSrcweir     Size aCropRightBottom;
948*cdf0e10cSrcweir 
949*cdf0e10cSrcweir     if( GRAPHIC_GDIMETAFILE == eType )
950*cdf0e10cSrcweir     {
951*cdf0e10cSrcweir         GDIMetaFile aMtf( aTransGraphic.GetGDIMetaFile() );
952*cdf0e10cSrcweir 
953*cdf0e10cSrcweir         if( aMapGraph == MAP_PIXEL )
954*cdf0e10cSrcweir         {
955*cdf0e10cSrcweir             aCropLeftTop = Application::GetDefaultDevice()->LogicToPixel( Size( rAttr.GetLeftCrop(),
956*cdf0e10cSrcweir                                                                                 rAttr.GetTopCrop() ),
957*cdf0e10cSrcweir                                                                           aMap100 );
958*cdf0e10cSrcweir             aCropRightBottom = Application::GetDefaultDevice()->LogicToPixel( Size( rAttr.GetRightCrop(),
959*cdf0e10cSrcweir                                                                                     rAttr.GetBottomCrop() ),
960*cdf0e10cSrcweir                                                                               aMap100 );
961*cdf0e10cSrcweir         }
962*cdf0e10cSrcweir         else
963*cdf0e10cSrcweir         {
964*cdf0e10cSrcweir             aCropLeftTop = OutputDevice::LogicToLogic( Size( rAttr.GetLeftCrop(),
965*cdf0e10cSrcweir                                                              rAttr.GetTopCrop() ),
966*cdf0e10cSrcweir                                                        aMap100,
967*cdf0e10cSrcweir                                                        aMapGraph );
968*cdf0e10cSrcweir             aCropRightBottom = OutputDevice::LogicToLogic( Size( rAttr.GetRightCrop(),
969*cdf0e10cSrcweir                                                                  rAttr.GetBottomCrop() ),
970*cdf0e10cSrcweir                                                            aMap100,
971*cdf0e10cSrcweir                                                            aMapGraph );
972*cdf0e10cSrcweir         }
973*cdf0e10cSrcweir 
974*cdf0e10cSrcweir         // #104115# If the metafile is cropped, give it a special
975*cdf0e10cSrcweir         // treatment: clip against the remaining area, scale up such
976*cdf0e10cSrcweir         // that this area later fills the desired size, and move the
977*cdf0e10cSrcweir         // origin to the upper left edge of that area.
978*cdf0e10cSrcweir         if( rAttr.IsCropped() )
979*cdf0e10cSrcweir         {
980*cdf0e10cSrcweir             const MapMode aMtfMapMode( aMtf.GetPrefMapMode() );
981*cdf0e10cSrcweir 
982*cdf0e10cSrcweir             Rectangle aClipRect( aMtfMapMode.GetOrigin().X() + aCropLeftTop.Width(),
983*cdf0e10cSrcweir                                  aMtfMapMode.GetOrigin().Y() + aCropLeftTop.Height(),
984*cdf0e10cSrcweir                                  aMtfMapMode.GetOrigin().X() + aSrcSize.Width() - aCropRightBottom.Width(),
985*cdf0e10cSrcweir                                  aMtfMapMode.GetOrigin().Y() + aSrcSize.Height() - aCropRightBottom.Height() );
986*cdf0e10cSrcweir 
987*cdf0e10cSrcweir             // #104115# To correctly crop rotated metafiles, clip by view rectangle
988*cdf0e10cSrcweir             aMtf.AddAction( new MetaISectRectClipRegionAction( aClipRect ), 0 );
989*cdf0e10cSrcweir 
990*cdf0e10cSrcweir             // #104115# To crop the metafile, scale larger than the output rectangle
991*cdf0e10cSrcweir             aMtf.Scale( (double)rDestSize.Width() / (aSrcSize.Width() - aCropLeftTop.Width() - aCropRightBottom.Width()),
992*cdf0e10cSrcweir                         (double)rDestSize.Height() / (aSrcSize.Height() - aCropLeftTop.Height() - aCropRightBottom.Height()) );
993*cdf0e10cSrcweir 
994*cdf0e10cSrcweir             // #104115# Adapt the pref size by hand (scale changes it
995*cdf0e10cSrcweir             // proportionally, but we want it to be smaller than the
996*cdf0e10cSrcweir             // former size, to crop the excess out)
997*cdf0e10cSrcweir             aMtf.SetPrefSize( Size( (long)((double)rDestSize.Width() *  (1.0 + (aCropLeftTop.Width() + aCropRightBottom.Width()) / aSrcSize.Width())  + .5),
998*cdf0e10cSrcweir                                     (long)((double)rDestSize.Height() * (1.0 + (aCropLeftTop.Height() + aCropRightBottom.Height()) / aSrcSize.Height()) + .5) ) );
999*cdf0e10cSrcweir 
1000*cdf0e10cSrcweir             // #104115# Adapt the origin of the new mapmode, such that it
1001*cdf0e10cSrcweir             // is shifted to the place where the cropped output starts
1002*cdf0e10cSrcweir             Point aNewOrigin( (long)((double)aMtfMapMode.GetOrigin().X() + rDestSize.Width() * aCropLeftTop.Width() / (aSrcSize.Width() - aCropLeftTop.Width() - aCropRightBottom.Width()) + .5),
1003*cdf0e10cSrcweir                               (long)((double)aMtfMapMode.GetOrigin().Y() + rDestSize.Height() * aCropLeftTop.Height() / (aSrcSize.Height() - aCropLeftTop.Height() - aCropRightBottom.Height()) + .5) );
1004*cdf0e10cSrcweir             MapMode aNewMap( rDestMap );
1005*cdf0e10cSrcweir             aNewMap.SetOrigin( OutputDevice::LogicToLogic(aNewOrigin, aMtfMapMode, rDestMap) );
1006*cdf0e10cSrcweir             aMtf.SetPrefMapMode( aNewMap );
1007*cdf0e10cSrcweir         }
1008*cdf0e10cSrcweir         else
1009*cdf0e10cSrcweir         {
1010*cdf0e10cSrcweir             aMtf.Scale( Fraction( rDestSize.Width(), aSrcSize.Width() ), Fraction( rDestSize.Height(), aSrcSize.Height() ) );
1011*cdf0e10cSrcweir             aMtf.SetPrefMapMode( rDestMap );
1012*cdf0e10cSrcweir         }
1013*cdf0e10cSrcweir 
1014*cdf0e10cSrcweir         aTransGraphic = aMtf;
1015*cdf0e10cSrcweir     }
1016*cdf0e10cSrcweir     else if( GRAPHIC_BITMAP == eType )
1017*cdf0e10cSrcweir     {
1018*cdf0e10cSrcweir         BitmapEx    aBitmapEx( aTransGraphic.GetBitmapEx() );
1019*cdf0e10cSrcweir 
1020*cdf0e10cSrcweir         // convert crops to pixel
1021*cdf0e10cSrcweir         aCropLeftTop = Application::GetDefaultDevice()->LogicToPixel( Size( rAttr.GetLeftCrop(),
1022*cdf0e10cSrcweir                                                                             rAttr.GetTopCrop() ),
1023*cdf0e10cSrcweir                                                                       aMap100 );
1024*cdf0e10cSrcweir         aCropRightBottom = Application::GetDefaultDevice()->LogicToPixel( Size( rAttr.GetRightCrop(),
1025*cdf0e10cSrcweir                                                                                 rAttr.GetBottomCrop() ),
1026*cdf0e10cSrcweir                                                                           aMap100 );
1027*cdf0e10cSrcweir 
1028*cdf0e10cSrcweir         // convert from prefmapmode to pixel
1029*cdf0e10cSrcweir         const Size aSrcSizePixel( Application::GetDefaultDevice()->LogicToPixel( aSrcSize,
1030*cdf0e10cSrcweir                                                                                  aMapGraph ) );
1031*cdf0e10cSrcweir 
1032*cdf0e10cSrcweir         // setup crop rectangle in pixel
1033*cdf0e10cSrcweir         Rectangle aCropRect( aCropLeftTop.Width(), aCropLeftTop.Height(),
1034*cdf0e10cSrcweir                              aSrcSizePixel.Width() - aCropRightBottom.Width(),
1035*cdf0e10cSrcweir                              aSrcSizePixel.Height() - aCropRightBottom.Height() );
1036*cdf0e10cSrcweir 
1037*cdf0e10cSrcweir         // #105641# Also crop animations
1038*cdf0e10cSrcweir         if( aTransGraphic.IsAnimated() )
1039*cdf0e10cSrcweir         {
1040*cdf0e10cSrcweir             sal_uInt16 nFrame;
1041*cdf0e10cSrcweir             Animation aAnim( aTransGraphic.GetAnimation() );
1042*cdf0e10cSrcweir 
1043*cdf0e10cSrcweir             for( nFrame=0; nFrame<aAnim.Count(); ++nFrame )
1044*cdf0e10cSrcweir             {
1045*cdf0e10cSrcweir                 AnimationBitmap aAnimBmp( aAnim.Get( nFrame ) );
1046*cdf0e10cSrcweir 
1047*cdf0e10cSrcweir                 if( !aCropRect.IsInside( Rectangle(aAnimBmp.aPosPix, aAnimBmp.aSizePix) ) )
1048*cdf0e10cSrcweir                 {
1049*cdf0e10cSrcweir                     // setup actual cropping (relative to frame position)
1050*cdf0e10cSrcweir                     Rectangle aCropRectRel( aCropRect );
1051*cdf0e10cSrcweir                     aCropRectRel.Move( -aAnimBmp.aPosPix.X(),
1052*cdf0e10cSrcweir                                        -aAnimBmp.aPosPix.Y() );
1053*cdf0e10cSrcweir 
1054*cdf0e10cSrcweir                     // cropping affects this frame, apply it then
1055*cdf0e10cSrcweir                     // do _not_ apply enlargement, this is done below
1056*cdf0e10cSrcweir                     ImplTransformBitmap( aAnimBmp.aBmpEx, rAttr, Size(), Size(),
1057*cdf0e10cSrcweir                                          aCropRectRel, rDestSize, sal_False );
1058*cdf0e10cSrcweir 
1059*cdf0e10cSrcweir                     aAnim.Replace( aAnimBmp, nFrame );
1060*cdf0e10cSrcweir                 }
1061*cdf0e10cSrcweir                 // else: bitmap completely within crop area,
1062*cdf0e10cSrcweir                 // i.e. nothing is cropped away
1063*cdf0e10cSrcweir             }
1064*cdf0e10cSrcweir 
1065*cdf0e10cSrcweir             // now, apply enlargement (if any) through global animation size
1066*cdf0e10cSrcweir             if( aCropLeftTop.Width() < 0 ||
1067*cdf0e10cSrcweir                 aCropLeftTop.Height() < 0 ||
1068*cdf0e10cSrcweir                 aCropRightBottom.Width() < 0 ||
1069*cdf0e10cSrcweir                 aCropRightBottom.Height() < 0 )
1070*cdf0e10cSrcweir             {
1071*cdf0e10cSrcweir                 Size aNewSize( aAnim.GetDisplaySizePixel() );
1072*cdf0e10cSrcweir                 aNewSize.Width() += aCropRightBottom.Width() < 0 ? -aCropRightBottom.Width() : 0;
1073*cdf0e10cSrcweir                 aNewSize.Width() += aCropLeftTop.Width() < 0 ? -aCropLeftTop.Width() : 0;
1074*cdf0e10cSrcweir                 aNewSize.Height() += aCropRightBottom.Height() < 0 ? -aCropRightBottom.Height() : 0;
1075*cdf0e10cSrcweir                 aNewSize.Height() += aCropLeftTop.Height() < 0 ? -aCropLeftTop.Height() : 0;
1076*cdf0e10cSrcweir                 aAnim.SetDisplaySizePixel( aNewSize );
1077*cdf0e10cSrcweir             }
1078*cdf0e10cSrcweir 
1079*cdf0e10cSrcweir             // if topleft has changed, we must move all frames to the
1080*cdf0e10cSrcweir             // right and bottom, resp.
1081*cdf0e10cSrcweir             if( aCropLeftTop.Width() < 0 ||
1082*cdf0e10cSrcweir                 aCropLeftTop.Height() < 0 )
1083*cdf0e10cSrcweir             {
1084*cdf0e10cSrcweir                 Point aPosOffset( aCropLeftTop.Width() < 0 ? -aCropLeftTop.Width() : 0,
1085*cdf0e10cSrcweir                                   aCropLeftTop.Height() < 0 ? -aCropLeftTop.Height() : 0 );
1086*cdf0e10cSrcweir 
1087*cdf0e10cSrcweir                 for( nFrame=0; nFrame<aAnim.Count(); ++nFrame )
1088*cdf0e10cSrcweir                 {
1089*cdf0e10cSrcweir                     AnimationBitmap aAnimBmp( aAnim.Get( nFrame ) );
1090*cdf0e10cSrcweir 
1091*cdf0e10cSrcweir                     aAnimBmp.aPosPix += aPosOffset;
1092*cdf0e10cSrcweir 
1093*cdf0e10cSrcweir                     aAnim.Replace( aAnimBmp, nFrame );
1094*cdf0e10cSrcweir                 }
1095*cdf0e10cSrcweir             }
1096*cdf0e10cSrcweir 
1097*cdf0e10cSrcweir             aTransGraphic = aAnim;
1098*cdf0e10cSrcweir         }
1099*cdf0e10cSrcweir         else
1100*cdf0e10cSrcweir         {
1101*cdf0e10cSrcweir             BitmapEx aBmpEx( aTransGraphic.GetBitmapEx() );
1102*cdf0e10cSrcweir 
1103*cdf0e10cSrcweir             ImplTransformBitmap( aBmpEx, rAttr, aCropLeftTop, aCropRightBottom,
1104*cdf0e10cSrcweir                                  aCropRect, rDestSize, sal_True );
1105*cdf0e10cSrcweir 
1106*cdf0e10cSrcweir             aTransGraphic = aBmpEx;
1107*cdf0e10cSrcweir         }
1108*cdf0e10cSrcweir 
1109*cdf0e10cSrcweir         aTransGraphic.SetPrefSize( rDestSize );
1110*cdf0e10cSrcweir         aTransGraphic.SetPrefMapMode( rDestMap );
1111*cdf0e10cSrcweir     }
1112*cdf0e10cSrcweir 
1113*cdf0e10cSrcweir     GraphicObject aGrfObj( aTransGraphic );
1114*cdf0e10cSrcweir     aTransGraphic = aGrfObj.GetTransformedGraphic( &rAttr );
1115*cdf0e10cSrcweir 
1116*cdf0e10cSrcweir 	return aTransGraphic;
1117*cdf0e10cSrcweir }
1118*cdf0e10cSrcweir 
1119*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1120*cdf0e10cSrcweir 
1121*cdf0e10cSrcweir Graphic GraphicObject::GetTransformedGraphic( const GraphicAttr* pAttr ) const // TODO: Change to Impl
1122*cdf0e10cSrcweir {
1123*cdf0e10cSrcweir 	GetGraphic();
1124*cdf0e10cSrcweir 
1125*cdf0e10cSrcweir 	Graphic     aGraphic;
1126*cdf0e10cSrcweir     GraphicAttr aAttr( pAttr ? *pAttr : GetAttr() );
1127*cdf0e10cSrcweir 
1128*cdf0e10cSrcweir 	if( maGraphic.IsSupportedGraphic() && !maGraphic.IsSwapOut() )
1129*cdf0e10cSrcweir 	{
1130*cdf0e10cSrcweir 		if( aAttr.IsSpecialDrawMode() || aAttr.IsAdjusted() || aAttr.IsMirrored() || aAttr.IsRotated() || aAttr.IsTransparent() )
1131*cdf0e10cSrcweir 		{
1132*cdf0e10cSrcweir 			if( GetType() == GRAPHIC_BITMAP )
1133*cdf0e10cSrcweir 			{
1134*cdf0e10cSrcweir 				if( IsAnimated() )
1135*cdf0e10cSrcweir 				{
1136*cdf0e10cSrcweir 					Animation aAnimation( maGraphic.GetAnimation() );
1137*cdf0e10cSrcweir 					GraphicManager::ImplAdjust( aAnimation, aAttr, ADJUSTMENT_ALL );
1138*cdf0e10cSrcweir                     aAnimation.SetLoopCount( mnAnimationLoopCount );
1139*cdf0e10cSrcweir 					aGraphic = aAnimation;
1140*cdf0e10cSrcweir 				}
1141*cdf0e10cSrcweir 				else
1142*cdf0e10cSrcweir 				{
1143*cdf0e10cSrcweir 					BitmapEx aBmpEx( maGraphic.GetBitmapEx() );
1144*cdf0e10cSrcweir 					GraphicManager::ImplAdjust( aBmpEx, aAttr, ADJUSTMENT_ALL );
1145*cdf0e10cSrcweir 					aGraphic = aBmpEx;
1146*cdf0e10cSrcweir 				}
1147*cdf0e10cSrcweir 			}
1148*cdf0e10cSrcweir 			else
1149*cdf0e10cSrcweir 			{
1150*cdf0e10cSrcweir 				GDIMetaFile aMtf( maGraphic.GetGDIMetaFile() );
1151*cdf0e10cSrcweir 				GraphicManager::ImplAdjust( aMtf, aAttr, ADJUSTMENT_ALL );
1152*cdf0e10cSrcweir 				aGraphic = aMtf;
1153*cdf0e10cSrcweir 			}
1154*cdf0e10cSrcweir 		}
1155*cdf0e10cSrcweir 		else
1156*cdf0e10cSrcweir         {
1157*cdf0e10cSrcweir 			if( ( GetType() == GRAPHIC_BITMAP ) && IsAnimated() )
1158*cdf0e10cSrcweir 			{
1159*cdf0e10cSrcweir 				Animation aAnimation( maGraphic.GetAnimation() );
1160*cdf0e10cSrcweir                 aAnimation.SetLoopCount( mnAnimationLoopCount );
1161*cdf0e10cSrcweir 				aGraphic = aAnimation;
1162*cdf0e10cSrcweir 			}
1163*cdf0e10cSrcweir             else
1164*cdf0e10cSrcweir 			    aGraphic = maGraphic;
1165*cdf0e10cSrcweir         }
1166*cdf0e10cSrcweir 	}
1167*cdf0e10cSrcweir 
1168*cdf0e10cSrcweir 	return aGraphic;
1169*cdf0e10cSrcweir }
1170*cdf0e10cSrcweir 
1171*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1172*cdf0e10cSrcweir 
1173*cdf0e10cSrcweir void GraphicObject::ResetAnimationLoopCount()
1174*cdf0e10cSrcweir {
1175*cdf0e10cSrcweir 	if( IsAnimated() && !IsSwappedOut() )
1176*cdf0e10cSrcweir 	{
1177*cdf0e10cSrcweir 		maGraphic.ResetAnimationLoopCount();
1178*cdf0e10cSrcweir 
1179*cdf0e10cSrcweir 		if( mpSimpleCache )
1180*cdf0e10cSrcweir 			mpSimpleCache->maGraphic.ResetAnimationLoopCount();
1181*cdf0e10cSrcweir 	}
1182*cdf0e10cSrcweir }
1183*cdf0e10cSrcweir 
1184*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1185*cdf0e10cSrcweir 
1186*cdf0e10cSrcweir sal_Bool GraphicObject::SwapOut()
1187*cdf0e10cSrcweir {
1188*cdf0e10cSrcweir 	sal_Bool bRet = ( !mbAutoSwapped ? maGraphic.SwapOut() : sal_False );
1189*cdf0e10cSrcweir 
1190*cdf0e10cSrcweir 	if( bRet && mpMgr )
1191*cdf0e10cSrcweir 		mpMgr->ImplGraphicObjectWasSwappedOut( *this );
1192*cdf0e10cSrcweir 
1193*cdf0e10cSrcweir 	return bRet;
1194*cdf0e10cSrcweir }
1195*cdf0e10cSrcweir 
1196*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1197*cdf0e10cSrcweir 
1198*cdf0e10cSrcweir sal_Bool GraphicObject::SwapOut( SvStream* pOStm )
1199*cdf0e10cSrcweir {
1200*cdf0e10cSrcweir 	sal_Bool bRet = ( !mbAutoSwapped ? maGraphic.SwapOut( pOStm ) : sal_False );
1201*cdf0e10cSrcweir 
1202*cdf0e10cSrcweir 	if( bRet && mpMgr )
1203*cdf0e10cSrcweir 		mpMgr->ImplGraphicObjectWasSwappedOut( *this );
1204*cdf0e10cSrcweir 
1205*cdf0e10cSrcweir 	return bRet;
1206*cdf0e10cSrcweir }
1207*cdf0e10cSrcweir 
1208*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1209*cdf0e10cSrcweir 
1210*cdf0e10cSrcweir sal_Bool GraphicObject::SwapIn()
1211*cdf0e10cSrcweir {
1212*cdf0e10cSrcweir 	sal_Bool bRet;
1213*cdf0e10cSrcweir 
1214*cdf0e10cSrcweir 	if( mbAutoSwapped )
1215*cdf0e10cSrcweir 	{
1216*cdf0e10cSrcweir 		ImplAutoSwapIn();
1217*cdf0e10cSrcweir 		bRet = sal_True;
1218*cdf0e10cSrcweir 	}
1219*cdf0e10cSrcweir 	else if( mpMgr && mpMgr->ImplFillSwappedGraphicObject( *this, maGraphic ) )
1220*cdf0e10cSrcweir 		bRet = sal_True;
1221*cdf0e10cSrcweir 	else
1222*cdf0e10cSrcweir 	{
1223*cdf0e10cSrcweir 		bRet = maGraphic.SwapIn();
1224*cdf0e10cSrcweir 
1225*cdf0e10cSrcweir 		if( bRet && mpMgr )
1226*cdf0e10cSrcweir 			mpMgr->ImplGraphicObjectWasSwappedIn( *this );
1227*cdf0e10cSrcweir 	}
1228*cdf0e10cSrcweir 
1229*cdf0e10cSrcweir 	if( bRet )
1230*cdf0e10cSrcweir 		ImplAssignGraphicData();
1231*cdf0e10cSrcweir 
1232*cdf0e10cSrcweir 	return bRet;
1233*cdf0e10cSrcweir }
1234*cdf0e10cSrcweir 
1235*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1236*cdf0e10cSrcweir 
1237*cdf0e10cSrcweir sal_Bool GraphicObject::SwapIn( SvStream* pIStm )
1238*cdf0e10cSrcweir {
1239*cdf0e10cSrcweir 	sal_Bool bRet;
1240*cdf0e10cSrcweir 
1241*cdf0e10cSrcweir 	if( mbAutoSwapped )
1242*cdf0e10cSrcweir 	{
1243*cdf0e10cSrcweir 		ImplAutoSwapIn();
1244*cdf0e10cSrcweir 		bRet = sal_True;
1245*cdf0e10cSrcweir 	}
1246*cdf0e10cSrcweir 	else if( mpMgr && mpMgr->ImplFillSwappedGraphicObject( *this, maGraphic ) )
1247*cdf0e10cSrcweir 		bRet = sal_True;
1248*cdf0e10cSrcweir 	else
1249*cdf0e10cSrcweir 	{
1250*cdf0e10cSrcweir 		bRet = maGraphic.SwapIn( pIStm );
1251*cdf0e10cSrcweir 
1252*cdf0e10cSrcweir 		if( bRet && mpMgr )
1253*cdf0e10cSrcweir 			mpMgr->ImplGraphicObjectWasSwappedIn( *this );
1254*cdf0e10cSrcweir 	}
1255*cdf0e10cSrcweir 
1256*cdf0e10cSrcweir 	if( bRet )
1257*cdf0e10cSrcweir 		ImplAssignGraphicData();
1258*cdf0e10cSrcweir 
1259*cdf0e10cSrcweir 	return bRet;
1260*cdf0e10cSrcweir }
1261*cdf0e10cSrcweir 
1262*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1263*cdf0e10cSrcweir 
1264*cdf0e10cSrcweir void GraphicObject::SetSwapState()
1265*cdf0e10cSrcweir {
1266*cdf0e10cSrcweir 	if( !IsSwappedOut() )
1267*cdf0e10cSrcweir 	{
1268*cdf0e10cSrcweir 		mbAutoSwapped = sal_True;
1269*cdf0e10cSrcweir 
1270*cdf0e10cSrcweir 		if( mpMgr )
1271*cdf0e10cSrcweir 			mpMgr->ImplGraphicObjectWasSwappedOut( *this );
1272*cdf0e10cSrcweir 	}
1273*cdf0e10cSrcweir }
1274*cdf0e10cSrcweir 
1275*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1276*cdf0e10cSrcweir 
1277*cdf0e10cSrcweir IMPL_LINK( GraphicObject, ImplAutoSwapOutHdl, void*, EMPTYARG )
1278*cdf0e10cSrcweir {
1279*cdf0e10cSrcweir 	if( !IsSwappedOut() )
1280*cdf0e10cSrcweir 	{
1281*cdf0e10cSrcweir 		mbIsInSwapOut = sal_True;
1282*cdf0e10cSrcweir 
1283*cdf0e10cSrcweir 		SvStream* pStream = GetSwapStream();
1284*cdf0e10cSrcweir 
1285*cdf0e10cSrcweir 		if( GRFMGR_AUTOSWAPSTREAM_NONE != pStream )
1286*cdf0e10cSrcweir 		{
1287*cdf0e10cSrcweir 			if( GRFMGR_AUTOSWAPSTREAM_LINK == pStream )
1288*cdf0e10cSrcweir 				mbAutoSwapped = SwapOut( NULL );
1289*cdf0e10cSrcweir 			else
1290*cdf0e10cSrcweir 			{
1291*cdf0e10cSrcweir 				if( GRFMGR_AUTOSWAPSTREAM_TEMP == pStream )
1292*cdf0e10cSrcweir 					mbAutoSwapped = SwapOut();
1293*cdf0e10cSrcweir 				else
1294*cdf0e10cSrcweir 				{
1295*cdf0e10cSrcweir 					mbAutoSwapped = SwapOut( pStream );
1296*cdf0e10cSrcweir 					delete pStream;
1297*cdf0e10cSrcweir 				}
1298*cdf0e10cSrcweir 			}
1299*cdf0e10cSrcweir 		}
1300*cdf0e10cSrcweir 
1301*cdf0e10cSrcweir 		mbIsInSwapOut = sal_False;
1302*cdf0e10cSrcweir 	}
1303*cdf0e10cSrcweir 
1304*cdf0e10cSrcweir 	if( mpSwapOutTimer )
1305*cdf0e10cSrcweir 		mpSwapOutTimer->Start();
1306*cdf0e10cSrcweir 
1307*cdf0e10cSrcweir 	return 0L;
1308*cdf0e10cSrcweir }
1309*cdf0e10cSrcweir 
1310*cdf0e10cSrcweir // ------------------------------------------------------------------------
1311*cdf0e10cSrcweir 
1312*cdf0e10cSrcweir SvStream& operator>>( SvStream& rIStm, GraphicObject& rGraphicObj )
1313*cdf0e10cSrcweir {
1314*cdf0e10cSrcweir 	VersionCompat	aCompat( rIStm, STREAM_READ );
1315*cdf0e10cSrcweir 	Graphic			aGraphic;
1316*cdf0e10cSrcweir 	GraphicAttr		aAttr;
1317*cdf0e10cSrcweir 	ByteString		aLink;
1318*cdf0e10cSrcweir 	sal_Bool			bLink;
1319*cdf0e10cSrcweir 
1320*cdf0e10cSrcweir 	rIStm >> aGraphic >> aAttr >> bLink;
1321*cdf0e10cSrcweir 
1322*cdf0e10cSrcweir 	rGraphicObj.SetGraphic( aGraphic );
1323*cdf0e10cSrcweir 	rGraphicObj.SetAttr( aAttr );
1324*cdf0e10cSrcweir 
1325*cdf0e10cSrcweir 	if( bLink )
1326*cdf0e10cSrcweir 	{
1327*cdf0e10cSrcweir 		rIStm >> aLink;
1328*cdf0e10cSrcweir 		rGraphicObj.SetLink( UniString( aLink, RTL_TEXTENCODING_UTF8 ) );
1329*cdf0e10cSrcweir 	}
1330*cdf0e10cSrcweir 	else
1331*cdf0e10cSrcweir 		rGraphicObj.SetLink();
1332*cdf0e10cSrcweir 
1333*cdf0e10cSrcweir 	rGraphicObj.SetSwapStreamHdl();
1334*cdf0e10cSrcweir 
1335*cdf0e10cSrcweir 	return rIStm;
1336*cdf0e10cSrcweir }
1337*cdf0e10cSrcweir 
1338*cdf0e10cSrcweir // ------------------------------------------------------------------------
1339*cdf0e10cSrcweir 
1340*cdf0e10cSrcweir SvStream& operator<<( SvStream& rOStm, const GraphicObject& rGraphicObj )
1341*cdf0e10cSrcweir {
1342*cdf0e10cSrcweir 	VersionCompat	aCompat( rOStm, STREAM_WRITE, 1 );
1343*cdf0e10cSrcweir 	const sal_Bool		bLink =  rGraphicObj.HasLink();
1344*cdf0e10cSrcweir 
1345*cdf0e10cSrcweir 	rOStm << rGraphicObj.GetGraphic() << rGraphicObj.GetAttr() << bLink;
1346*cdf0e10cSrcweir 
1347*cdf0e10cSrcweir 	if( bLink )
1348*cdf0e10cSrcweir 		rOStm << ByteString( rGraphicObj.GetLink(), RTL_TEXTENCODING_UTF8 );
1349*cdf0e10cSrcweir 
1350*cdf0e10cSrcweir 	return rOStm;
1351*cdf0e10cSrcweir }
1352*cdf0e10cSrcweir 
1353*cdf0e10cSrcweir #define UNO_NAME_GRAPHOBJ_URLPREFIX "vnd.sun.star.GraphicObject:"
1354*cdf0e10cSrcweir 
1355*cdf0e10cSrcweir GraphicObject GraphicObject::CreateGraphicObjectFromURL( const ::rtl::OUString &rURL )
1356*cdf0e10cSrcweir {
1357*cdf0e10cSrcweir 	const String aURL( rURL ), aPrefix( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_GRAPHOBJ_URLPREFIX) );
1358*cdf0e10cSrcweir 	if( aURL.Search( aPrefix ) == 0 )
1359*cdf0e10cSrcweir 	{
1360*cdf0e10cSrcweir 		// graphic manager url
1361*cdf0e10cSrcweir 		ByteString aUniqueID( String(rURL.copy( sizeof( UNO_NAME_GRAPHOBJ_URLPREFIX ) - 1 )), RTL_TEXTENCODING_UTF8 );
1362*cdf0e10cSrcweir 		return GraphicObject( aUniqueID );
1363*cdf0e10cSrcweir 	}
1364*cdf0e10cSrcweir 	else
1365*cdf0e10cSrcweir 	{
1366*cdf0e10cSrcweir 		Graphic		aGraphic;
1367*cdf0e10cSrcweir 		if ( aURL.Len() )
1368*cdf0e10cSrcweir 		{
1369*cdf0e10cSrcweir 			SvStream*	pStream = utl::UcbStreamHelper::CreateStream( aURL, STREAM_READ );
1370*cdf0e10cSrcweir 			if( pStream )
1371*cdf0e10cSrcweir 				GraphicConverter::Import( *pStream, aGraphic );
1372*cdf0e10cSrcweir 		}
1373*cdf0e10cSrcweir 
1374*cdf0e10cSrcweir 		return GraphicObject( aGraphic );
1375*cdf0e10cSrcweir 	}
1376*cdf0e10cSrcweir }
1377