xref: /AOO41X/main/svtools/source/graphic/grfmgr.cxx (revision 58b03506c5ac486b1153db5c7612229071716300)
15900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
35900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
45900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
55900e8ecSAndrew Rist  * distributed with this work for additional information
65900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
75900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
85900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
95900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
115900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
135900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
145900e8ecSAndrew Rist  * software distributed under the License is distributed on an
155900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
175900e8ecSAndrew Rist  * specific language governing permissions and limitations
185900e8ecSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
205900e8ecSAndrew Rist  *************************************************************/
215900e8ecSAndrew Rist 
225900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #define ENABLE_BYTESTRING_STREAM_OPERATORS
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <algorithm>
30cdf0e10cSrcweir 
31*58b03506SArrigo Marchiori #include <com/sun/star/uno/Reference.hxx>
32*58b03506SArrigo Marchiori #include <com/sun/star/document/XLinkAuthorizer.hpp>
33*58b03506SArrigo Marchiori #include <com/sun/star/frame/XDesktop.hpp>
34*58b03506SArrigo Marchiori #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35cdf0e10cSrcweir #include <tools/vcompat.hxx>
36*58b03506SArrigo Marchiori #include <ucbhelper/contentbroker.hxx>
37cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
38cdf0e10cSrcweir #include <unotools/localfilehelper.hxx>
39cdf0e10cSrcweir #include <unotools/tempfile.hxx>
40cdf0e10cSrcweir #include <vcl/svapp.hxx>
41cdf0e10cSrcweir #include <vcl/cvtgrf.hxx>
42cdf0e10cSrcweir #include <vcl/metaact.hxx>
43cdf0e10cSrcweir #include <vcl/virdev.hxx>
44cdf0e10cSrcweir #include <vcl/salbtype.hxx>
45cdf0e10cSrcweir #include <unotools/cacheoptions.hxx>
46cdf0e10cSrcweir #include <svtools/grfmgr.hxx>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir // --> OD 2010-01-04 #i105243#
49cdf0e10cSrcweir #include <vcl/pdfextoutdevdata.hxx>
50cdf0e10cSrcweir // <--
51cdf0e10cSrcweir 
52*58b03506SArrigo Marchiori using namespace ::com::sun::star;
53*58b03506SArrigo Marchiori 
54cdf0e10cSrcweir // -----------
55cdf0e10cSrcweir // - Defines -
56cdf0e10cSrcweir // -----------
57cdf0e10cSrcweir 
58cdf0e10cSrcweir #define WATERMARK_LUM_OFFSET				50
59cdf0e10cSrcweir #define WATERMARK_CON_OFFSET				-70
60cdf0e10cSrcweir 
61cdf0e10cSrcweir // -----------
62cdf0e10cSrcweir // - statics -
63cdf0e10cSrcweir // -----------
64cdf0e10cSrcweir 
65cdf0e10cSrcweir GraphicManager* GraphicObject::mpGlobalMgr = NULL;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir // ---------------------
68cdf0e10cSrcweir // - GrfDirectCacheObj -
69cdf0e10cSrcweir // ---------------------
70cdf0e10cSrcweir 
71cdf0e10cSrcweir struct GrfSimpleCacheObj
72cdf0e10cSrcweir {
73cdf0e10cSrcweir 	Graphic		maGraphic;
74cdf0e10cSrcweir 	GraphicAttr	maAttr;
75cdf0e10cSrcweir 
GrfSimpleCacheObjGrfSimpleCacheObj76cdf0e10cSrcweir 				GrfSimpleCacheObj( const Graphic& rGraphic, const GraphicAttr& rAttr ) :
77cdf0e10cSrcweir 					maGraphic( rGraphic ), maAttr( rAttr ) {}
78cdf0e10cSrcweir };
79cdf0e10cSrcweir 
80cdf0e10cSrcweir // -----------------
81cdf0e10cSrcweir // - GraphicObject -
82cdf0e10cSrcweir // -----------------
83cdf0e10cSrcweir 
84cdf0e10cSrcweir TYPEINIT1_AUTOFACTORY( GraphicObject, SvDataCopyStream );
85cdf0e10cSrcweir 
86d327e58aSArmin Le Grand // unique increasing ID for being able to detect the GraphicObject with the
87d327e58aSArmin Le Grand // oldest last data changes
88d327e58aSArmin Le Grand static sal_uLong aIncrementingTimeOfLastDataChange = 1;
89d327e58aSArmin Le Grand 
ImplAfterDataChange()90d327e58aSArmin Le Grand void GraphicObject::ImplAfterDataChange()
91d327e58aSArmin Le Grand {
92d327e58aSArmin Le Grand     // set unique timestamp ID of last data change
93d327e58aSArmin Le Grand     mnDataChangeTimeStamp = aIncrementingTimeOfLastDataChange++;
94d327e58aSArmin Le Grand 
95d327e58aSArmin Le Grand     // check memory footprint of all GraphicObjects managed and evtl. take action
96d327e58aSArmin Le Grand     GetGraphicManager().ImplCheckSizeOfSwappedInGraphics();
97d327e58aSArmin Le Grand }
98d327e58aSArmin Le Grand 
99cdf0e10cSrcweir // -----------------------------------------------------------------------------
100cdf0e10cSrcweir 
GraphicObject(const GraphicManager * pMgr)101cdf0e10cSrcweir GraphicObject::GraphicObject( const GraphicManager* pMgr ) :
102cdf0e10cSrcweir 	mpLink		( NULL ),
103cdf0e10cSrcweir 	mpUserData	( NULL )
104cdf0e10cSrcweir {
105cdf0e10cSrcweir 	ImplConstruct();
106cdf0e10cSrcweir 	ImplAssignGraphicData();
107cdf0e10cSrcweir 	ImplSetGraphicManager( pMgr );
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir // -----------------------------------------------------------------------------
111cdf0e10cSrcweir 
GraphicObject(const Graphic & rGraphic,const GraphicManager * pMgr)112cdf0e10cSrcweir GraphicObject::GraphicObject( const Graphic& rGraphic, const GraphicManager* pMgr ) :
113cdf0e10cSrcweir 	maGraphic	( rGraphic ),
114cdf0e10cSrcweir 	mpLink		( NULL ),
115cdf0e10cSrcweir 	mpUserData	( NULL )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir 	ImplConstruct();
118cdf0e10cSrcweir 	ImplAssignGraphicData();
119cdf0e10cSrcweir 	ImplSetGraphicManager( pMgr );
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir // -----------------------------------------------------------------------------
123cdf0e10cSrcweir 
GraphicObject(const Graphic & rGraphic,const String & rLink,const GraphicManager * pMgr)124cdf0e10cSrcweir GraphicObject::GraphicObject( const Graphic& rGraphic, const String& rLink, const GraphicManager* pMgr ) :
125cdf0e10cSrcweir 	maGraphic	( rGraphic ),
126cdf0e10cSrcweir 	mpLink		( rLink.Len() ? ( new String( rLink ) ) : NULL ),
127cdf0e10cSrcweir 	mpUserData	( NULL )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir 	ImplConstruct();
130cdf0e10cSrcweir 	ImplAssignGraphicData();
131cdf0e10cSrcweir 	ImplSetGraphicManager( pMgr );
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir // -----------------------------------------------------------------------------
135cdf0e10cSrcweir 
GraphicObject(const GraphicObject & rGraphicObj,const GraphicManager * pMgr)136cdf0e10cSrcweir GraphicObject::GraphicObject( const GraphicObject& rGraphicObj, const GraphicManager* pMgr ) :
137cdf0e10cSrcweir     SvDataCopyStream(),
138cdf0e10cSrcweir 	maGraphic	( rGraphicObj.GetGraphic() ),
139cdf0e10cSrcweir 	maAttr		( rGraphicObj.maAttr ),
140cdf0e10cSrcweir 	mpLink		( rGraphicObj.mpLink ? ( new String( *rGraphicObj.mpLink ) ) : NULL ),
141cdf0e10cSrcweir 	mpUserData	( rGraphicObj.mpUserData ? ( new String( *rGraphicObj.mpUserData ) ) : NULL )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir 	ImplConstruct();
144cdf0e10cSrcweir 	ImplAssignGraphicData();
145cdf0e10cSrcweir 	ImplSetGraphicManager( pMgr, NULL, &rGraphicObj );
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir // -----------------------------------------------------------------------------
149cdf0e10cSrcweir 
GraphicObject(const ByteString & rUniqueID,const GraphicManager * pMgr)150cdf0e10cSrcweir GraphicObject::GraphicObject( const ByteString& rUniqueID, const GraphicManager* pMgr ) :
151cdf0e10cSrcweir 	mpLink		( NULL ),
152cdf0e10cSrcweir 	mpUserData	( NULL )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir 	ImplConstruct();
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 	// assign default properties
157cdf0e10cSrcweir 	ImplAssignGraphicData();
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 	ImplSetGraphicManager( pMgr, &rUniqueID );
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 	// update properties
162cdf0e10cSrcweir 	ImplAssignGraphicData();
163cdf0e10cSrcweir }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir // -----------------------------------------------------------------------------
166cdf0e10cSrcweir 
~GraphicObject()167cdf0e10cSrcweir GraphicObject::~GraphicObject()
168cdf0e10cSrcweir {
169cdf0e10cSrcweir 	if( mpMgr )
170cdf0e10cSrcweir 	{
171cdf0e10cSrcweir 		mpMgr->ImplUnregisterObj( *this );
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 		if( ( mpMgr == mpGlobalMgr ) && !mpGlobalMgr->ImplHasObjects() )
174cdf0e10cSrcweir 			delete mpGlobalMgr, mpGlobalMgr = NULL;
175cdf0e10cSrcweir 	}
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 	delete mpSwapOutTimer;
178cdf0e10cSrcweir 	delete mpSwapStreamHdl;
179cdf0e10cSrcweir 	delete mpLink;
180cdf0e10cSrcweir 	delete mpUserData;
181cdf0e10cSrcweir 	delete mpSimpleCache;
182cdf0e10cSrcweir }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir // -----------------------------------------------------------------------------
185cdf0e10cSrcweir 
ImplConstruct()186cdf0e10cSrcweir void GraphicObject::ImplConstruct()
187cdf0e10cSrcweir {
188cdf0e10cSrcweir 	mpMgr = NULL;
189cdf0e10cSrcweir 	mpSwapStreamHdl = NULL;
190cdf0e10cSrcweir 	mpSwapOutTimer = NULL;
191cdf0e10cSrcweir 	mpSimpleCache = NULL;
192cdf0e10cSrcweir     mnAnimationLoopCount = 0;
193cdf0e10cSrcweir 	mbAutoSwapped = sal_False;
194cdf0e10cSrcweir 	mbIsInSwapIn = sal_False;
195cdf0e10cSrcweir 	mbIsInSwapOut = sal_False;
196d327e58aSArmin Le Grand 
197d327e58aSArmin Le Grand     // Init with a unique, increasing ID
198d327e58aSArmin Le Grand     mnDataChangeTimeStamp = aIncrementingTimeOfLastDataChange++;
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir // -----------------------------------------------------------------------------
202cdf0e10cSrcweir 
ImplAssignGraphicData()203cdf0e10cSrcweir void GraphicObject::ImplAssignGraphicData()
204cdf0e10cSrcweir {
205cdf0e10cSrcweir 	maPrefSize = maGraphic.GetPrefSize();
206cdf0e10cSrcweir 	maPrefMapMode = maGraphic.GetPrefMapMode();
207cdf0e10cSrcweir 	mnSizeBytes = maGraphic.GetSizeBytes();
208cdf0e10cSrcweir 	meType = maGraphic.GetType();
209cdf0e10cSrcweir 	mbTransparent = maGraphic.IsTransparent();
210cdf0e10cSrcweir 	mbAlpha = maGraphic.IsAlpha();
211cdf0e10cSrcweir 	mbAnimated = maGraphic.IsAnimated();
212cdf0e10cSrcweir 	mbEPS = maGraphic.IsEPS();
213cdf0e10cSrcweir     mnAnimationLoopCount = ( mbAnimated ? maGraphic.GetAnimationLoopCount() : 0 );
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir // -----------------------------------------------------------------------------
217cdf0e10cSrcweir 
ImplSetGraphicManager(const GraphicManager * pMgr,const ByteString * pID,const GraphicObject * pCopyObj)218cdf0e10cSrcweir void GraphicObject::ImplSetGraphicManager( const GraphicManager* pMgr, const ByteString* pID, const GraphicObject* pCopyObj )
219cdf0e10cSrcweir {
220cdf0e10cSrcweir 	if( !mpMgr || ( pMgr != mpMgr ) )
221cdf0e10cSrcweir 	{
222cdf0e10cSrcweir 		if( !pMgr && mpMgr && ( mpMgr == mpGlobalMgr ) )
223cdf0e10cSrcweir 			return;
224cdf0e10cSrcweir 		else
225cdf0e10cSrcweir 		{
226cdf0e10cSrcweir 			if( mpMgr )
227cdf0e10cSrcweir 			{
228cdf0e10cSrcweir 				mpMgr->ImplUnregisterObj( *this );
229cdf0e10cSrcweir 
230cdf0e10cSrcweir 				if( ( mpMgr == mpGlobalMgr ) && !mpGlobalMgr->ImplHasObjects() )
231cdf0e10cSrcweir 					delete mpGlobalMgr, mpGlobalMgr = NULL;
232cdf0e10cSrcweir 			}
233cdf0e10cSrcweir 
234cdf0e10cSrcweir 			if( !pMgr )
235cdf0e10cSrcweir 			{
236cdf0e10cSrcweir 				if( !mpGlobalMgr )
237cdf0e10cSrcweir 				{
238cdf0e10cSrcweir                     SvtCacheOptions aCacheOptions;
239cdf0e10cSrcweir 
240cdf0e10cSrcweir 					mpGlobalMgr = new GraphicManager( aCacheOptions.GetGraphicManagerTotalCacheSize(),
241cdf0e10cSrcweir                                                       aCacheOptions.GetGraphicManagerObjectCacheSize() );
242cdf0e10cSrcweir                     mpGlobalMgr->SetCacheTimeout( aCacheOptions.GetGraphicManagerObjectReleaseTime() );
243cdf0e10cSrcweir 				}
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 				mpMgr = mpGlobalMgr;
246cdf0e10cSrcweir 			}
247cdf0e10cSrcweir 			else
248cdf0e10cSrcweir 				mpMgr = (GraphicManager*) pMgr;
249cdf0e10cSrcweir 
250cdf0e10cSrcweir 			mpMgr->ImplRegisterObj( *this, maGraphic, pID, pCopyObj );
251cdf0e10cSrcweir 		}
252cdf0e10cSrcweir 	}
253cdf0e10cSrcweir }
254cdf0e10cSrcweir 
255cdf0e10cSrcweir // -----------------------------------------------------------------------------
256cdf0e10cSrcweir 
ImplAutoSwapIn()257cdf0e10cSrcweir void GraphicObject::ImplAutoSwapIn()
258cdf0e10cSrcweir {
259cdf0e10cSrcweir 	if( IsSwappedOut() )
260cdf0e10cSrcweir 	{
261cdf0e10cSrcweir 		if( mpMgr && mpMgr->ImplFillSwappedGraphicObject( *this, maGraphic ) )
262cdf0e10cSrcweir 			mbAutoSwapped = sal_False;
263cdf0e10cSrcweir 		else
264cdf0e10cSrcweir 		{
265cdf0e10cSrcweir 			mbIsInSwapIn = sal_True;
266cdf0e10cSrcweir 
267cdf0e10cSrcweir 			if( maGraphic.SwapIn() )
268cdf0e10cSrcweir 				mbAutoSwapped = sal_False;
269cdf0e10cSrcweir 			else
270cdf0e10cSrcweir 			{
271cdf0e10cSrcweir 				SvStream* pStream = GetSwapStream();
272cdf0e10cSrcweir 
273cdf0e10cSrcweir 				if( GRFMGR_AUTOSWAPSTREAM_NONE != pStream )
274cdf0e10cSrcweir 				{
275cdf0e10cSrcweir 					if( GRFMGR_AUTOSWAPSTREAM_LINK == pStream )
276cdf0e10cSrcweir 					{
277cdf0e10cSrcweir 						if( HasLink() )
278cdf0e10cSrcweir 						{
279cdf0e10cSrcweir 							String aURLStr;
280cdf0e10cSrcweir 
281cdf0e10cSrcweir 							if( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( GetLink(), aURLStr ) )
282cdf0e10cSrcweir 							{
283cdf0e10cSrcweir 								SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aURLStr, STREAM_READ );
284cdf0e10cSrcweir 
285cdf0e10cSrcweir 								if( pIStm )
286cdf0e10cSrcweir 								{
287cdf0e10cSrcweir 									(*pIStm) >> maGraphic;
288cdf0e10cSrcweir 									mbAutoSwapped = ( maGraphic.GetType() != GRAPHIC_NONE );
289cdf0e10cSrcweir 									delete pIStm;
290cdf0e10cSrcweir 								}
291cdf0e10cSrcweir 							}
292cdf0e10cSrcweir 						}
293cdf0e10cSrcweir 					}
294cdf0e10cSrcweir 					else if( GRFMGR_AUTOSWAPSTREAM_TEMP == pStream )
295cdf0e10cSrcweir 						mbAutoSwapped = !maGraphic.SwapIn();
296cdf0e10cSrcweir 					else if( GRFMGR_AUTOSWAPSTREAM_LOADED == pStream )
297cdf0e10cSrcweir 						mbAutoSwapped = maGraphic.IsSwapOut();
298cdf0e10cSrcweir 					else
299cdf0e10cSrcweir 					{
300cdf0e10cSrcweir 						mbAutoSwapped = !maGraphic.SwapIn( pStream );
301cdf0e10cSrcweir 						delete pStream;
302cdf0e10cSrcweir 					}
303cdf0e10cSrcweir 				}
304cdf0e10cSrcweir 				else
305cdf0e10cSrcweir 				{
306cdf0e10cSrcweir 					DBG_ASSERT( ( GRAPHIC_NONE == meType ) || ( GRAPHIC_DEFAULT == meType ),
307cdf0e10cSrcweir 								"GraphicObject::ImplAutoSwapIn: could not get stream to swap in graphic! (=>KA)" );
308cdf0e10cSrcweir 				}
309cdf0e10cSrcweir 			}
310cdf0e10cSrcweir 
311cdf0e10cSrcweir 			mbIsInSwapIn = sal_False;
312cdf0e10cSrcweir 
313cdf0e10cSrcweir 			if( !mbAutoSwapped && mpMgr )
314cdf0e10cSrcweir 				mpMgr->ImplGraphicObjectWasSwappedIn( *this );
315cdf0e10cSrcweir 		}
316d327e58aSArmin Le Grand 
317d327e58aSArmin Le Grand         // Handle evtl. needed AfterDataChanges
318d327e58aSArmin Le Grand         ImplAfterDataChange();
319cdf0e10cSrcweir 	}
320cdf0e10cSrcweir }
321cdf0e10cSrcweir 
322cdf0e10cSrcweir // -----------------------------------------------------------------------------
ImplGetCropParams(OutputDevice * pOut,Point & rPt,Size & rSz,const GraphicAttr * pAttr,PolyPolygon & rClipPolyPoly,sal_Bool & bRectClipRegion) const323cdf0e10cSrcweir sal_Bool GraphicObject::ImplGetCropParams( OutputDevice* pOut, Point& rPt, Size& rSz, const GraphicAttr* pAttr,
324cdf0e10cSrcweir 									   PolyPolygon& rClipPolyPoly, sal_Bool& bRectClipRegion ) const
325cdf0e10cSrcweir {
326cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
327cdf0e10cSrcweir 
328cdf0e10cSrcweir 	if( GetType() != GRAPHIC_NONE )
329cdf0e10cSrcweir 	{
330cdf0e10cSrcweir 		Polygon			aClipPoly( Rectangle( rPt, rSz ) );
331cdf0e10cSrcweir 		const sal_uInt16	nRot10 = pAttr->GetRotation() % 3600;
332cdf0e10cSrcweir 		const Point		aOldOrigin( rPt );
333cdf0e10cSrcweir         // --> OD 2005-09-30 #i54875# - It's not needed to get the graphic again.
334cdf0e10cSrcweir //        const Graphic&  rGraphic = GetGraphic();
335cdf0e10cSrcweir         // <--
336cdf0e10cSrcweir 		const MapMode	aMap100( MAP_100TH_MM );
337cdf0e10cSrcweir 		Size			aSize100;
338cdf0e10cSrcweir 		long			nTotalWidth, nTotalHeight;
339cdf0e10cSrcweir 		long			nNewLeft, nNewTop, nNewRight, nNewBottom;
340cdf0e10cSrcweir 		double			fScale;
341cdf0e10cSrcweir 
342cdf0e10cSrcweir 		if( nRot10 )
343cdf0e10cSrcweir 		{
344cdf0e10cSrcweir 			aClipPoly.Rotate( rPt, nRot10 );
345cdf0e10cSrcweir 			bRectClipRegion = sal_False;
346cdf0e10cSrcweir 		}
347cdf0e10cSrcweir 		else
348cdf0e10cSrcweir 			bRectClipRegion = sal_True;
349cdf0e10cSrcweir 
350cdf0e10cSrcweir 		rClipPolyPoly = aClipPoly;
351cdf0e10cSrcweir 
352cdf0e10cSrcweir         // --> OD 2005-09-30 #i54875# - directly access member <maGraphic> to
353cdf0e10cSrcweir         // get <PrefSize> and <PrefMapMode>.
354cdf0e10cSrcweir //        if( rGraphic.GetPrefMapMode() == MAP_PIXEL )
355cdf0e10cSrcweir //            aSize100 = Application::GetDefaultDevice()->PixelToLogic( rGraphic.GetPrefSize(), aMap100 );
356cdf0e10cSrcweir //        else
357cdf0e10cSrcweir //            aSize100 = pOut->LogicToLogic( rGraphic.GetPrefSize(), rGraphic.GetPrefMapMode(), aMap100 );
358cdf0e10cSrcweir         if( maGraphic.GetPrefMapMode() == MAP_PIXEL )
359cdf0e10cSrcweir             aSize100 = Application::GetDefaultDevice()->PixelToLogic( maGraphic.GetPrefSize(), aMap100 );
360cdf0e10cSrcweir         else
361cdf0e10cSrcweir         {
362cdf0e10cSrcweir             MapMode m(maGraphic.GetPrefMapMode());
363cdf0e10cSrcweir             aSize100 = pOut->LogicToLogic( maGraphic.GetPrefSize(), &m, &aMap100 );
364cdf0e10cSrcweir         }
365cdf0e10cSrcweir         // <--
366cdf0e10cSrcweir 
367cdf0e10cSrcweir 		nTotalWidth = aSize100.Width() - pAttr->GetLeftCrop() - pAttr->GetRightCrop();
368cdf0e10cSrcweir 		nTotalHeight = aSize100.Height() - pAttr->GetTopCrop() - pAttr->GetBottomCrop();
369cdf0e10cSrcweir 
370cdf0e10cSrcweir 		if( aSize100.Width() > 0 && aSize100.Height() > 0 && nTotalWidth > 0 && nTotalHeight > 0 )
371cdf0e10cSrcweir 		{
372cdf0e10cSrcweir 			fScale = (double) aSize100.Width() / nTotalWidth;
373cdf0e10cSrcweir 			nNewLeft = -FRound( ( ( pAttr->GetMirrorFlags() & BMP_MIRROR_HORZ ) ? pAttr->GetRightCrop() : pAttr->GetLeftCrop() ) * fScale );
374cdf0e10cSrcweir 			nNewRight = nNewLeft + FRound( aSize100.Width() * fScale ) - 1;
375cdf0e10cSrcweir 
376cdf0e10cSrcweir 			fScale = (double) rSz.Width() / aSize100.Width();
377cdf0e10cSrcweir 			rPt.X() += FRound( nNewLeft * fScale );
378cdf0e10cSrcweir 			rSz.Width() = FRound( ( nNewRight - nNewLeft + 1 ) * fScale );
379cdf0e10cSrcweir 
380cdf0e10cSrcweir 			fScale = (double) aSize100.Height() / nTotalHeight;
381cdf0e10cSrcweir 			nNewTop = -FRound( ( ( pAttr->GetMirrorFlags() & BMP_MIRROR_VERT ) ? pAttr->GetBottomCrop() : pAttr->GetTopCrop() ) * fScale );
382cdf0e10cSrcweir 			nNewBottom = nNewTop + FRound( aSize100.Height() * fScale ) - 1;
383cdf0e10cSrcweir 
384cdf0e10cSrcweir 			fScale = (double) rSz.Height() / aSize100.Height();
385cdf0e10cSrcweir 			rPt.Y() += FRound( nNewTop * fScale );
386cdf0e10cSrcweir 			rSz.Height() = FRound( ( nNewBottom - nNewTop + 1 ) * fScale );
387cdf0e10cSrcweir 
388cdf0e10cSrcweir 			if( nRot10 )
389cdf0e10cSrcweir 			{
390cdf0e10cSrcweir 				Polygon aOriginPoly( 1 );
391cdf0e10cSrcweir 
392cdf0e10cSrcweir 				aOriginPoly[ 0 ] = rPt;
393cdf0e10cSrcweir 				aOriginPoly.Rotate( aOldOrigin, nRot10 );
394cdf0e10cSrcweir 				rPt = aOriginPoly[ 0 ];
395cdf0e10cSrcweir 			}
396cdf0e10cSrcweir 
397cdf0e10cSrcweir 			bRet = sal_True;
398cdf0e10cSrcweir 		}
399cdf0e10cSrcweir 	}
400cdf0e10cSrcweir 
401cdf0e10cSrcweir 	return bRet;
402cdf0e10cSrcweir }
403cdf0e10cSrcweir 
404cdf0e10cSrcweir // -----------------------------------------------------------------------------
405cdf0e10cSrcweir 
operator =(const GraphicObject & rGraphicObj)406cdf0e10cSrcweir GraphicObject& GraphicObject::operator=( const GraphicObject& rGraphicObj )
407cdf0e10cSrcweir {
408cdf0e10cSrcweir 	if( &rGraphicObj != this )
409cdf0e10cSrcweir 	{
410cdf0e10cSrcweir 		mpMgr->ImplUnregisterObj( *this );
411cdf0e10cSrcweir 
412cdf0e10cSrcweir 		delete mpSwapStreamHdl, mpSwapStreamHdl = NULL;
413cdf0e10cSrcweir 		delete mpSimpleCache, mpSimpleCache = NULL;
414cdf0e10cSrcweir 		delete mpLink;
415cdf0e10cSrcweir 		delete mpUserData;
416cdf0e10cSrcweir 
417cdf0e10cSrcweir 		maGraphic = rGraphicObj.GetGraphic();
418cdf0e10cSrcweir 		maAttr = rGraphicObj.maAttr;
419cdf0e10cSrcweir 		mpLink = rGraphicObj.mpLink ? new String( *rGraphicObj.mpLink ) : NULL;
420cdf0e10cSrcweir 		mpUserData = rGraphicObj.mpUserData ? new String( *rGraphicObj.mpUserData ) : NULL;
421cdf0e10cSrcweir 		ImplAssignGraphicData();
422cdf0e10cSrcweir 		mbAutoSwapped = sal_False;
423cdf0e10cSrcweir 		mpMgr = rGraphicObj.mpMgr;
424cdf0e10cSrcweir 
425cdf0e10cSrcweir 		mpMgr->ImplRegisterObj( *this, maGraphic, NULL, &rGraphicObj );
426cdf0e10cSrcweir 	}
427cdf0e10cSrcweir 
428cdf0e10cSrcweir 	return *this;
429cdf0e10cSrcweir }
430cdf0e10cSrcweir 
431cdf0e10cSrcweir // -----------------------------------------------------------------------------
432cdf0e10cSrcweir 
operator ==(const GraphicObject & rGraphicObj) const433cdf0e10cSrcweir sal_Bool GraphicObject::operator==( const GraphicObject& rGraphicObj ) const
434cdf0e10cSrcweir {
435cdf0e10cSrcweir 	return(	( rGraphicObj.maGraphic == maGraphic ) &&
436cdf0e10cSrcweir 			( rGraphicObj.maAttr == maAttr ) &&
437cdf0e10cSrcweir 			( rGraphicObj.GetLink() == GetLink() ) );
438cdf0e10cSrcweir }
439cdf0e10cSrcweir 
440cdf0e10cSrcweir // ------------------------------------------------------------------------
441cdf0e10cSrcweir 
Load(SvStream & rIStm)442cdf0e10cSrcweir void GraphicObject::Load( SvStream& rIStm )
443cdf0e10cSrcweir {
444cdf0e10cSrcweir     rIStm >> *this;
445cdf0e10cSrcweir }
446cdf0e10cSrcweir 
447cdf0e10cSrcweir // ------------------------------------------------------------------------
448cdf0e10cSrcweir 
Save(SvStream & rOStm)449cdf0e10cSrcweir void GraphicObject::Save( SvStream& rOStm )
450cdf0e10cSrcweir {
451cdf0e10cSrcweir     rOStm << *this;
452cdf0e10cSrcweir }
453cdf0e10cSrcweir 
454cdf0e10cSrcweir // ------------------------------------------------------------------------
455cdf0e10cSrcweir 
Assign(const SvDataCopyStream & rCopyStream)456cdf0e10cSrcweir void GraphicObject::Assign( const SvDataCopyStream& rCopyStream )
457cdf0e10cSrcweir {
458cdf0e10cSrcweir     *this = (const GraphicObject& ) rCopyStream;
459cdf0e10cSrcweir }
460cdf0e10cSrcweir 
461cdf0e10cSrcweir // -----------------------------------------------------------------------------
462cdf0e10cSrcweir 
GetUniqueID() const463cdf0e10cSrcweir ByteString GraphicObject::GetUniqueID() const
464cdf0e10cSrcweir {
465ddde725dSArmin Le Grand 	if ( !IsInSwapIn() && IsEPS() )
466cdf0e10cSrcweir 		const_cast<GraphicObject*>(this)->FireSwapInRequest();
467cdf0e10cSrcweir 
468cdf0e10cSrcweir 	ByteString aRet;
469cdf0e10cSrcweir 
470cdf0e10cSrcweir 	if( mpMgr )
471cdf0e10cSrcweir 		aRet = mpMgr->ImplGetUniqueID( *this );
472cdf0e10cSrcweir 
473cdf0e10cSrcweir 	return aRet;
474cdf0e10cSrcweir }
475cdf0e10cSrcweir 
476cdf0e10cSrcweir // -----------------------------------------------------------------------------
477cdf0e10cSrcweir 
GetChecksum() const478cdf0e10cSrcweir sal_uLong GraphicObject::GetChecksum() const
479cdf0e10cSrcweir {
480cdf0e10cSrcweir 	return( ( maGraphic.IsSupportedGraphic() && !maGraphic.IsSwapOut() ) ? maGraphic.GetChecksum() : 0 );
481cdf0e10cSrcweir }
482cdf0e10cSrcweir 
483cdf0e10cSrcweir // -----------------------------------------------------------------------------
484cdf0e10cSrcweir 
GetSwapStream() const485cdf0e10cSrcweir SvStream* GraphicObject::GetSwapStream() const
486cdf0e10cSrcweir {
487cdf0e10cSrcweir 	return( HasSwapStreamHdl() ? (SvStream*) mpSwapStreamHdl->Call( (void*) this ) : GRFMGR_AUTOSWAPSTREAM_NONE );
488cdf0e10cSrcweir }
489cdf0e10cSrcweir 
490cdf0e10cSrcweir // -----------------------------------------------------------------------------
491cdf0e10cSrcweir 
492cdf0e10cSrcweir // !!! to be removed
GetReleaseFromCache() const493cdf0e10cSrcweir sal_uLong GraphicObject::GetReleaseFromCache() const
494cdf0e10cSrcweir {
495cdf0e10cSrcweir 	return 0;
496cdf0e10cSrcweir }
497cdf0e10cSrcweir 
498cdf0e10cSrcweir // -----------------------------------------------------------------------------
499cdf0e10cSrcweir 
SetAttr(const GraphicAttr & rAttr)500cdf0e10cSrcweir void GraphicObject::SetAttr( const GraphicAttr& rAttr )
501cdf0e10cSrcweir {
502cdf0e10cSrcweir 	maAttr = rAttr;
503cdf0e10cSrcweir 
504cdf0e10cSrcweir 	if( mpSimpleCache && ( mpSimpleCache->maAttr != rAttr ) )
505cdf0e10cSrcweir 		delete mpSimpleCache, mpSimpleCache = NULL;
506cdf0e10cSrcweir }
507cdf0e10cSrcweir 
508cdf0e10cSrcweir // -----------------------------------------------------------------------------
509cdf0e10cSrcweir 
SetLink()510cdf0e10cSrcweir void GraphicObject::SetLink()
511cdf0e10cSrcweir {
512cdf0e10cSrcweir 	if( mpLink )
513cdf0e10cSrcweir 		delete mpLink, mpLink = NULL;
514cdf0e10cSrcweir }
515cdf0e10cSrcweir 
516cdf0e10cSrcweir // -----------------------------------------------------------------------------
517cdf0e10cSrcweir 
SetLink(const String & rLink)518cdf0e10cSrcweir void GraphicObject::SetLink( const String& rLink )
519cdf0e10cSrcweir {
520cdf0e10cSrcweir 	delete mpLink, mpLink = new String( rLink );
521cdf0e10cSrcweir }
522cdf0e10cSrcweir 
523cdf0e10cSrcweir // -----------------------------------------------------------------------------
524cdf0e10cSrcweir 
GetLink() const525cdf0e10cSrcweir String GraphicObject::GetLink() const
526cdf0e10cSrcweir {
527cdf0e10cSrcweir 	if( mpLink )
528cdf0e10cSrcweir 		return *mpLink;
529cdf0e10cSrcweir 	else
530cdf0e10cSrcweir 		return String();
531cdf0e10cSrcweir }
532cdf0e10cSrcweir 
533cdf0e10cSrcweir // -----------------------------------------------------------------------------
534cdf0e10cSrcweir 
SetUserData()535cdf0e10cSrcweir void GraphicObject::SetUserData()
536cdf0e10cSrcweir {
537cdf0e10cSrcweir 	if( mpUserData )
538cdf0e10cSrcweir 		delete mpUserData, mpUserData = NULL;
539cdf0e10cSrcweir }
540cdf0e10cSrcweir 
541cdf0e10cSrcweir // -----------------------------------------------------------------------------
542cdf0e10cSrcweir 
SetUserData(const String & rUserData)543cdf0e10cSrcweir void GraphicObject::SetUserData( const String& rUserData )
544cdf0e10cSrcweir {
545cdf0e10cSrcweir 	delete mpUserData, mpUserData = new String( rUserData );
546cdf0e10cSrcweir }
547cdf0e10cSrcweir 
548cdf0e10cSrcweir // -----------------------------------------------------------------------------
549cdf0e10cSrcweir 
GetUserData() const550cdf0e10cSrcweir String GraphicObject::GetUserData() const
551cdf0e10cSrcweir {
552cdf0e10cSrcweir 	if( mpUserData )
553cdf0e10cSrcweir 		return *mpUserData;
554cdf0e10cSrcweir 	else
555cdf0e10cSrcweir 		return String();
556cdf0e10cSrcweir }
557cdf0e10cSrcweir 
558cdf0e10cSrcweir // -----------------------------------------------------------------------------
559cdf0e10cSrcweir 
SetSwapStreamHdl()560cdf0e10cSrcweir void GraphicObject::SetSwapStreamHdl()
561cdf0e10cSrcweir {
562cdf0e10cSrcweir 	if( mpSwapStreamHdl )
563cdf0e10cSrcweir 	{
564cdf0e10cSrcweir 		delete mpSwapOutTimer, mpSwapOutTimer = NULL;
565cdf0e10cSrcweir 		delete mpSwapStreamHdl, mpSwapStreamHdl = NULL;
566cdf0e10cSrcweir 	}
567cdf0e10cSrcweir }
568cdf0e10cSrcweir 
569cdf0e10cSrcweir // -----------------------------------------------------------------------------
570cdf0e10cSrcweir 
SetSwapStreamHdl(const Link & rHdl,const sal_uLong nSwapOutTimeout)571cdf0e10cSrcweir void GraphicObject::SetSwapStreamHdl( const Link& rHdl, const sal_uLong nSwapOutTimeout )
572cdf0e10cSrcweir {
573cdf0e10cSrcweir 	delete mpSwapStreamHdl,	mpSwapStreamHdl = new Link( rHdl );
574cdf0e10cSrcweir 
575cdf0e10cSrcweir 	if( nSwapOutTimeout )
576cdf0e10cSrcweir 	{
577cdf0e10cSrcweir 		if( !mpSwapOutTimer )
578cdf0e10cSrcweir 		{
579cdf0e10cSrcweir 			mpSwapOutTimer = new Timer;
580cdf0e10cSrcweir 			mpSwapOutTimer->SetTimeoutHdl( LINK( this, GraphicObject, ImplAutoSwapOutHdl ) );
581cdf0e10cSrcweir 		}
582cdf0e10cSrcweir 
583cdf0e10cSrcweir 		mpSwapOutTimer->SetTimeout( nSwapOutTimeout );
584cdf0e10cSrcweir 		mpSwapOutTimer->Start();
585cdf0e10cSrcweir 	}
586cdf0e10cSrcweir 	else
587cdf0e10cSrcweir 		delete mpSwapOutTimer, mpSwapOutTimer = NULL;
588cdf0e10cSrcweir }
589cdf0e10cSrcweir 
590cdf0e10cSrcweir // -----------------------------------------------------------------------------
591cdf0e10cSrcweir 
GetSwapStreamHdl() const592cdf0e10cSrcweir Link GraphicObject::GetSwapStreamHdl() const
593cdf0e10cSrcweir {
594cdf0e10cSrcweir 	if( mpSwapStreamHdl )
595cdf0e10cSrcweir 		return *mpSwapStreamHdl;
596cdf0e10cSrcweir 	else
597cdf0e10cSrcweir 		return Link();
598cdf0e10cSrcweir }
599cdf0e10cSrcweir 
600cdf0e10cSrcweir // -----------------------------------------------------------------------------
601cdf0e10cSrcweir 
FireSwapInRequest()602cdf0e10cSrcweir void GraphicObject::FireSwapInRequest()
603cdf0e10cSrcweir {
604cdf0e10cSrcweir 	ImplAutoSwapIn();
605cdf0e10cSrcweir }
606cdf0e10cSrcweir 
607cdf0e10cSrcweir // -----------------------------------------------------------------------------
608cdf0e10cSrcweir 
FireSwapOutRequest()609cdf0e10cSrcweir void GraphicObject::FireSwapOutRequest()
610cdf0e10cSrcweir {
611cdf0e10cSrcweir 	ImplAutoSwapOutHdl( NULL );
612cdf0e10cSrcweir }
613cdf0e10cSrcweir 
614cdf0e10cSrcweir // -----------------------------------------------------------------------------
615cdf0e10cSrcweir 
GraphicManagerDestroyed()616cdf0e10cSrcweir void GraphicObject::GraphicManagerDestroyed()
617cdf0e10cSrcweir {
618cdf0e10cSrcweir 	// we're alive, but our manager doesn't live anymore ==> connect to default manager
619cdf0e10cSrcweir 	mpMgr = NULL;
620cdf0e10cSrcweir 	ImplSetGraphicManager( NULL );
621cdf0e10cSrcweir }
622cdf0e10cSrcweir 
623cdf0e10cSrcweir // -----------------------------------------------------------------------------
624cdf0e10cSrcweir 
SetGraphicManager(const GraphicManager & rMgr)625cdf0e10cSrcweir void GraphicObject::SetGraphicManager( const GraphicManager& rMgr )
626cdf0e10cSrcweir {
627cdf0e10cSrcweir 	ImplSetGraphicManager( &rMgr );
628cdf0e10cSrcweir }
629cdf0e10cSrcweir 
630cdf0e10cSrcweir // -----------------------------------------------------------------------------
631cdf0e10cSrcweir 
IsCached(OutputDevice * pOut,const Point & rPt,const Size & rSz,const GraphicAttr * pAttr,sal_uLong nFlags) const632cdf0e10cSrcweir sal_Bool GraphicObject::IsCached( OutputDevice* pOut, const Point& rPt, const Size& rSz,
633cdf0e10cSrcweir 							  const GraphicAttr* pAttr, sal_uLong nFlags ) const
634cdf0e10cSrcweir {
635cdf0e10cSrcweir 	sal_Bool bRet;
636cdf0e10cSrcweir 
637cdf0e10cSrcweir 	if( nFlags & GRFMGR_DRAW_CACHED )
638cdf0e10cSrcweir     {
639cdf0e10cSrcweir         // --> OD 2005-10-11 #i54875# - Consider cropped graphics.
640cdf0e10cSrcweir         // Note: The graphic manager caches a cropped graphic with its
641cdf0e10cSrcweir         //       uncropped position and size.
642cdf0e10cSrcweir //        bRet = mpMgr->IsInCache( pOut, rPt, rSz, *this, ( pAttr ? *pAttr : GetAttr() ) );
643cdf0e10cSrcweir         Point aPt( rPt );
644cdf0e10cSrcweir         Size aSz( rSz );
645cdf0e10cSrcweir         if ( pAttr->IsCropped() )
646cdf0e10cSrcweir         {
647cdf0e10cSrcweir             PolyPolygon aClipPolyPoly;
648cdf0e10cSrcweir             sal_Bool        bRectClip;
649cdf0e10cSrcweir             ImplGetCropParams( pOut, aPt, aSz, pAttr, aClipPolyPoly, bRectClip );
650cdf0e10cSrcweir         }
651cdf0e10cSrcweir         bRet = mpMgr->IsInCache( pOut, aPt, aSz, *this, ( pAttr ? *pAttr : GetAttr() ) );
652cdf0e10cSrcweir     }
653cdf0e10cSrcweir 	else
654cdf0e10cSrcweir 		bRet = sal_False;
655cdf0e10cSrcweir 
656cdf0e10cSrcweir 	return bRet;
657cdf0e10cSrcweir }
658cdf0e10cSrcweir 
659cdf0e10cSrcweir // -----------------------------------------------------------------------------
660cdf0e10cSrcweir 
ReleaseFromCache()661cdf0e10cSrcweir void GraphicObject::ReleaseFromCache()
662cdf0e10cSrcweir {
663cdf0e10cSrcweir 
664cdf0e10cSrcweir 	mpMgr->ReleaseFromCache( *this );
665cdf0e10cSrcweir }
666cdf0e10cSrcweir 
667cdf0e10cSrcweir // -----------------------------------------------------------------------------
668cdf0e10cSrcweir 
SetAnimationNotifyHdl(const Link & rLink)669cdf0e10cSrcweir void GraphicObject::SetAnimationNotifyHdl( const Link& rLink )
670cdf0e10cSrcweir {
671cdf0e10cSrcweir 	maGraphic.SetAnimationNotifyHdl( rLink );
672cdf0e10cSrcweir }
673cdf0e10cSrcweir 
674cdf0e10cSrcweir // -----------------------------------------------------------------------------
675cdf0e10cSrcweir 
GetAnimationInfoList() const676cdf0e10cSrcweir List* GraphicObject::GetAnimationInfoList() const
677cdf0e10cSrcweir {
678cdf0e10cSrcweir 	return maGraphic.GetAnimationInfoList();
679cdf0e10cSrcweir }
680cdf0e10cSrcweir 
681cdf0e10cSrcweir // -----------------------------------------------------------------------------
682cdf0e10cSrcweir 
Draw(OutputDevice * pOut,const Point & rPt,const Size & rSz,const GraphicAttr * pAttr,sal_uLong nFlags)683cdf0e10cSrcweir sal_Bool GraphicObject::Draw( OutputDevice* pOut, const Point& rPt, const Size& rSz,
684cdf0e10cSrcweir 						  const GraphicAttr* pAttr, sal_uLong nFlags )
685cdf0e10cSrcweir {
686cdf0e10cSrcweir 	GraphicAttr	        aAttr( pAttr ? *pAttr : GetAttr() );
687cdf0e10cSrcweir 	Point 		        aPt( rPt );
688cdf0e10cSrcweir 	Size  	            aSz( rSz );
689cdf0e10cSrcweir     const sal_uInt32    nOldDrawMode = pOut->GetDrawMode();
690cdf0e10cSrcweir 	sal_Bool		        bCropped = aAttr.IsCropped();
691cdf0e10cSrcweir 	sal_Bool		        bCached = sal_False;
692cdf0e10cSrcweir 	sal_Bool		        bRet;
693cdf0e10cSrcweir 
694cdf0e10cSrcweir     // #i29534# Provide output rects for PDF writer
695cdf0e10cSrcweir     Rectangle			aCropRect;
696cdf0e10cSrcweir 
697cdf0e10cSrcweir     if( !( GRFMGR_DRAW_USE_DRAWMODE_SETTINGS & nFlags ) )
698cdf0e10cSrcweir         pOut->SetDrawMode( nOldDrawMode & ( ~( DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT ) ) );
699cdf0e10cSrcweir 
700cdf0e10cSrcweir 	// mirrored horizontically
701cdf0e10cSrcweir 	if( aSz.Width() < 0L )
702cdf0e10cSrcweir 	{
703cdf0e10cSrcweir 		aPt.X() += aSz.Width() + 1;
704cdf0e10cSrcweir 		aSz.Width() = -aSz.Width();
705cdf0e10cSrcweir 		aAttr.SetMirrorFlags( aAttr.GetMirrorFlags() ^ BMP_MIRROR_HORZ );
706cdf0e10cSrcweir 	}
707cdf0e10cSrcweir 
708cdf0e10cSrcweir 	// mirrored vertically
709cdf0e10cSrcweir 	if( aSz.Height() < 0L )
710cdf0e10cSrcweir 	{
711cdf0e10cSrcweir 		aPt.Y() += aSz.Height() + 1;
712cdf0e10cSrcweir 		aSz.Height() = -aSz.Height();
713cdf0e10cSrcweir 		aAttr.SetMirrorFlags( aAttr.GetMirrorFlags() ^ BMP_MIRROR_VERT );
714cdf0e10cSrcweir 	}
715cdf0e10cSrcweir 
716cdf0e10cSrcweir 	if( bCropped )
717cdf0e10cSrcweir 	{
718cdf0e10cSrcweir 		PolyPolygon aClipPolyPoly;
719cdf0e10cSrcweir 		sal_Bool		bRectClip;
720cdf0e10cSrcweir 		const sal_Bool	bCrop = ImplGetCropParams( pOut, aPt, aSz, &aAttr, aClipPolyPoly, bRectClip );
721cdf0e10cSrcweir 
722cdf0e10cSrcweir 		pOut->Push( PUSH_CLIPREGION );
723cdf0e10cSrcweir 
724cdf0e10cSrcweir 		if( bCrop )
725cdf0e10cSrcweir 		{
726cdf0e10cSrcweir 			if( bRectClip )
727cdf0e10cSrcweir             {
728cdf0e10cSrcweir                 // #i29534# Store crop rect for later forwarding to
729cdf0e10cSrcweir                 // PDF writer
730cdf0e10cSrcweir                 aCropRect = aClipPolyPoly.GetBoundRect();
731cdf0e10cSrcweir 				pOut->IntersectClipRegion( aCropRect );
732cdf0e10cSrcweir             }
733cdf0e10cSrcweir 			else
734cdf0e10cSrcweir             {
735cdf0e10cSrcweir 				pOut->IntersectClipRegion( aClipPolyPoly );
736cdf0e10cSrcweir             }
737cdf0e10cSrcweir 		}
738cdf0e10cSrcweir 	}
739cdf0e10cSrcweir 
740cdf0e10cSrcweir 	bRet = mpMgr->DrawObj( pOut, aPt, aSz, *this, aAttr, nFlags, bCached );
741cdf0e10cSrcweir 
742cdf0e10cSrcweir 	if( bCropped )
743cdf0e10cSrcweir 		pOut->Pop();
744cdf0e10cSrcweir 
745cdf0e10cSrcweir     pOut->SetDrawMode( nOldDrawMode );
746cdf0e10cSrcweir 
747cdf0e10cSrcweir     // #i29534# Moved below OutDev restoration, to avoid multiple swap-ins
748cdf0e10cSrcweir     // (code above needs to call GetGraphic twice)
749cdf0e10cSrcweir 	if( bCached )
750cdf0e10cSrcweir 	{
751cdf0e10cSrcweir 		if( mpSwapOutTimer )
752cdf0e10cSrcweir 			mpSwapOutTimer->Start();
753cdf0e10cSrcweir 		else
754cdf0e10cSrcweir 			FireSwapOutRequest();
755cdf0e10cSrcweir 	}
756cdf0e10cSrcweir 
757cdf0e10cSrcweir 	return bRet;
758cdf0e10cSrcweir }
759cdf0e10cSrcweir 
760cdf0e10cSrcweir // --> OD 2010-01-04 #i105243#
DrawWithPDFHandling(OutputDevice & rOutDev,const Point & rPt,const Size & rSz,const GraphicAttr * pGrfAttr,const sal_uLong nFlags)761cdf0e10cSrcweir sal_Bool GraphicObject::DrawWithPDFHandling( OutputDevice& rOutDev,
762cdf0e10cSrcweir                                          const Point& rPt, const Size& rSz,
763cdf0e10cSrcweir                                          const GraphicAttr* pGrfAttr,
764cdf0e10cSrcweir                                          const sal_uLong nFlags )
765cdf0e10cSrcweir {
766cdf0e10cSrcweir     const GraphicAttr aGrfAttr( pGrfAttr ? *pGrfAttr : GetAttr() );
767cdf0e10cSrcweir 
768cdf0e10cSrcweir     // Notify PDF writer about linked graphic (if any)
769cdf0e10cSrcweir     sal_Bool bWritingPdfLinkedGraphic( sal_False );
770cdf0e10cSrcweir     Point aPt( rPt );
771cdf0e10cSrcweir     Size aSz( rSz );
772cdf0e10cSrcweir     Rectangle aCropRect;
773cdf0e10cSrcweir     vcl::PDFExtOutDevData* pPDFExtOutDevData =
774cdf0e10cSrcweir             dynamic_cast<vcl::PDFExtOutDevData*>(rOutDev.GetExtOutDevData());
775cdf0e10cSrcweir     if( pPDFExtOutDevData )
776cdf0e10cSrcweir     {
777cdf0e10cSrcweir         // only delegate image handling to PDF, if no special treatment is necessary
778cdf0e10cSrcweir         if( GetGraphic().IsLink() &&
779cdf0e10cSrcweir             rSz.Width() > 0L &&
780cdf0e10cSrcweir             rSz.Height() > 0L &&
781cdf0e10cSrcweir             !aGrfAttr.IsSpecialDrawMode() &&
782cdf0e10cSrcweir             !aGrfAttr.IsMirrored() &&
783cdf0e10cSrcweir             !aGrfAttr.IsRotated() &&
784cdf0e10cSrcweir             !aGrfAttr.IsAdjusted() )
785cdf0e10cSrcweir         {
786cdf0e10cSrcweir             bWritingPdfLinkedGraphic = true;
787cdf0e10cSrcweir 
788cdf0e10cSrcweir             if( aGrfAttr.IsCropped() )
789cdf0e10cSrcweir             {
790cdf0e10cSrcweir                 PolyPolygon aClipPolyPoly;
791cdf0e10cSrcweir                 sal_Bool bRectClip;
792cdf0e10cSrcweir                 const sal_Bool bCrop = ImplGetCropParams( &rOutDev,
793cdf0e10cSrcweir                                                       aPt, aSz,
794cdf0e10cSrcweir                                                       &aGrfAttr,
795cdf0e10cSrcweir                                                       aClipPolyPoly,
796cdf0e10cSrcweir                                                       bRectClip );
797cdf0e10cSrcweir                 if ( bCrop && bRectClip )
798cdf0e10cSrcweir                 {
799cdf0e10cSrcweir                     aCropRect = aClipPolyPoly.GetBoundRect();
800cdf0e10cSrcweir                 }
801cdf0e10cSrcweir             }
802cdf0e10cSrcweir 
803cdf0e10cSrcweir             pPDFExtOutDevData->BeginGroup();
804cdf0e10cSrcweir         }
805cdf0e10cSrcweir     }
806cdf0e10cSrcweir 
807cdf0e10cSrcweir     sal_Bool bRet = Draw( &rOutDev, rPt, rSz, &aGrfAttr, nFlags );
808cdf0e10cSrcweir 
809cdf0e10cSrcweir     // Notify PDF writer about linked graphic (if any)
810cdf0e10cSrcweir     if( bWritingPdfLinkedGraphic )
811cdf0e10cSrcweir     {
812cdf0e10cSrcweir         pPDFExtOutDevData->EndGroup( const_cast< Graphic& >(GetGraphic()),
813cdf0e10cSrcweir                                      aGrfAttr.GetTransparency(),
814cdf0e10cSrcweir                                      Rectangle( aPt, aSz ),
815cdf0e10cSrcweir                                      aCropRect );
816cdf0e10cSrcweir     }
817cdf0e10cSrcweir 
818cdf0e10cSrcweir     return bRet;
819cdf0e10cSrcweir }
820cdf0e10cSrcweir // <--
821cdf0e10cSrcweir 
822cdf0e10cSrcweir // -----------------------------------------------------------------------------
823cdf0e10cSrcweir 
DrawTiled(OutputDevice * pOut,const Rectangle & rArea,const Size & rSize,const Size & rOffset,const GraphicAttr * pAttr,sal_uLong nFlags,int nTileCacheSize1D)824cdf0e10cSrcweir sal_Bool GraphicObject::DrawTiled( OutputDevice* pOut, const Rectangle& rArea, const Size& rSize,
825cdf0e10cSrcweir                                const Size& rOffset, const GraphicAttr* pAttr, sal_uLong nFlags, int nTileCacheSize1D )
826cdf0e10cSrcweir {
827cdf0e10cSrcweir     if( pOut == NULL || rSize.Width() == 0 || rSize.Height() == 0 )
828cdf0e10cSrcweir         return sal_False;
829cdf0e10cSrcweir 
830cdf0e10cSrcweir     const MapMode 	aOutMapMode( pOut->GetMapMode() );
831cdf0e10cSrcweir     const MapMode	aMapMode( aOutMapMode.GetMapUnit(), Point(), aOutMapMode.GetScaleX(), aOutMapMode.GetScaleY() );
832cdf0e10cSrcweir     // #106258# Clamp size to 1 for zero values. This is okay, since
833cdf0e10cSrcweir     // logical size of zero is handled above already
834cdf0e10cSrcweir     const Size		aOutTileSize( ::std::max( 1L, pOut->LogicToPixel( rSize, aOutMapMode ).Width() ),
835cdf0e10cSrcweir                                   ::std::max( 1L, pOut->LogicToPixel( rSize, aOutMapMode ).Height() ) );
836cdf0e10cSrcweir 
837cdf0e10cSrcweir 	//#i69780 clip final tile size to a sane max size
838cdf0e10cSrcweir     while (((sal_Int64)rSize.Width() * nTileCacheSize1D) > SAL_MAX_UINT16)
839cdf0e10cSrcweir         nTileCacheSize1D /= 2;
840cdf0e10cSrcweir     while (((sal_Int64)rSize.Height() * nTileCacheSize1D) > SAL_MAX_UINT16)
841cdf0e10cSrcweir         nTileCacheSize1D /= 2;
842cdf0e10cSrcweir 
843cdf0e10cSrcweir     return ImplDrawTiled( pOut, rArea, aOutTileSize, rOffset, pAttr, nFlags, nTileCacheSize1D );
844cdf0e10cSrcweir }
845cdf0e10cSrcweir 
846cdf0e10cSrcweir // -----------------------------------------------------------------------------
847cdf0e10cSrcweir 
StartAnimation(OutputDevice * pOut,const Point & rPt,const Size & rSz,long nExtraData,const GraphicAttr * pAttr,sal_uLong,OutputDevice * pFirstFrameOutDev)848cdf0e10cSrcweir sal_Bool GraphicObject::StartAnimation( OutputDevice* pOut, const Point& rPt, const Size& rSz,
849cdf0e10cSrcweir 									long nExtraData, const GraphicAttr* pAttr, sal_uLong /*nFlags*/,
850cdf0e10cSrcweir 									OutputDevice* pFirstFrameOutDev )
851cdf0e10cSrcweir {
852cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
853cdf0e10cSrcweir 
854cdf0e10cSrcweir 	GetGraphic();
855cdf0e10cSrcweir 
856cdf0e10cSrcweir 	if( !IsSwappedOut() )
857cdf0e10cSrcweir 	{
858cdf0e10cSrcweir     	const GraphicAttr aAttr( pAttr ? *pAttr : GetAttr() );
859cdf0e10cSrcweir 
860cdf0e10cSrcweir 		if( mbAnimated )
861cdf0e10cSrcweir 		{
862cdf0e10cSrcweir 			Point   aPt( rPt );
863cdf0e10cSrcweir 			Size	aSz( rSz );
864cdf0e10cSrcweir 			sal_Bool	bCropped = aAttr.IsCropped();
865cdf0e10cSrcweir 
866cdf0e10cSrcweir 			if( bCropped )
867cdf0e10cSrcweir 			{
868cdf0e10cSrcweir 				PolyPolygon aClipPolyPoly;
869cdf0e10cSrcweir 				sal_Bool		bRectClip;
870cdf0e10cSrcweir 				const sal_Bool	bCrop = ImplGetCropParams( pOut, aPt, aSz, &aAttr, aClipPolyPoly, bRectClip );
871cdf0e10cSrcweir 
872cdf0e10cSrcweir 				pOut->Push( PUSH_CLIPREGION );
873cdf0e10cSrcweir 
874cdf0e10cSrcweir 				if( bCrop )
875cdf0e10cSrcweir 				{
876cdf0e10cSrcweir 					if( bRectClip )
877cdf0e10cSrcweir 						pOut->IntersectClipRegion( aClipPolyPoly.GetBoundRect() );
878cdf0e10cSrcweir 					else
879cdf0e10cSrcweir 						pOut->IntersectClipRegion( aClipPolyPoly );
880cdf0e10cSrcweir 				}
881cdf0e10cSrcweir 			}
882cdf0e10cSrcweir 
883cdf0e10cSrcweir 			if( !mpSimpleCache || ( mpSimpleCache->maAttr != aAttr ) || pFirstFrameOutDev )
884cdf0e10cSrcweir 			{
885cdf0e10cSrcweir 				if( mpSimpleCache )
886cdf0e10cSrcweir 					delete mpSimpleCache;
887cdf0e10cSrcweir 
888cdf0e10cSrcweir 				mpSimpleCache = new GrfSimpleCacheObj( GetTransformedGraphic( &aAttr ), aAttr );
889cdf0e10cSrcweir 				mpSimpleCache->maGraphic.SetAnimationNotifyHdl( GetAnimationNotifyHdl() );
890cdf0e10cSrcweir 			}
891cdf0e10cSrcweir 
892cdf0e10cSrcweir 			mpSimpleCache->maGraphic.StartAnimation( pOut, aPt, aSz, nExtraData, pFirstFrameOutDev );
893cdf0e10cSrcweir 
894cdf0e10cSrcweir 			if( bCropped )
895cdf0e10cSrcweir 				pOut->Pop();
896cdf0e10cSrcweir 
897cdf0e10cSrcweir 			bRet = sal_True;
898cdf0e10cSrcweir 		}
899cdf0e10cSrcweir 		else
900cdf0e10cSrcweir 			bRet = Draw( pOut, rPt, rSz, &aAttr, GRFMGR_DRAW_STANDARD );
901cdf0e10cSrcweir 	}
902cdf0e10cSrcweir 
903cdf0e10cSrcweir 	return bRet;
904cdf0e10cSrcweir }
905cdf0e10cSrcweir 
906cdf0e10cSrcweir // -----------------------------------------------------------------------------
907cdf0e10cSrcweir 
StopAnimation(OutputDevice * pOut,long nExtraData)908cdf0e10cSrcweir void GraphicObject::StopAnimation( OutputDevice* pOut, long nExtraData )
909cdf0e10cSrcweir {
910cdf0e10cSrcweir 	if( mpSimpleCache )
911cdf0e10cSrcweir 		mpSimpleCache->maGraphic.StopAnimation( pOut, nExtraData );
912cdf0e10cSrcweir }
913cdf0e10cSrcweir 
914cdf0e10cSrcweir // -----------------------------------------------------------------------------
915cdf0e10cSrcweir 
GetGraphic() const916cdf0e10cSrcweir const Graphic& GraphicObject::GetGraphic() const
917cdf0e10cSrcweir {
918cdf0e10cSrcweir 	if( mbAutoSwapped )
919cdf0e10cSrcweir 		( (GraphicObject*) this )->ImplAutoSwapIn();
920cdf0e10cSrcweir 
921cdf0e10cSrcweir 	return maGraphic;
922cdf0e10cSrcweir }
923cdf0e10cSrcweir 
924cdf0e10cSrcweir // -----------------------------------------------------------------------------
925cdf0e10cSrcweir 
SetGraphic(const Graphic & rGraphic,const GraphicObject * pCopyObj)926cdf0e10cSrcweir void GraphicObject::SetGraphic( const Graphic& rGraphic, const GraphicObject* pCopyObj )
927cdf0e10cSrcweir {
928cdf0e10cSrcweir 	mpMgr->ImplUnregisterObj( *this );
929cdf0e10cSrcweir 
930cdf0e10cSrcweir 	if( mpSwapOutTimer )
931cdf0e10cSrcweir 		mpSwapOutTimer->Stop();
932cdf0e10cSrcweir 
933cdf0e10cSrcweir 	maGraphic = rGraphic;
934cdf0e10cSrcweir 	mbAutoSwapped = sal_False;
935cdf0e10cSrcweir 	ImplAssignGraphicData();
936cdf0e10cSrcweir 	delete mpLink, mpLink = NULL;
937cdf0e10cSrcweir 	delete mpSimpleCache, mpSimpleCache = NULL;
938cdf0e10cSrcweir 
939cdf0e10cSrcweir 	mpMgr->ImplRegisterObj( *this, maGraphic, 0, pCopyObj);
940cdf0e10cSrcweir 
941cdf0e10cSrcweir 	if( mpSwapOutTimer )
942cdf0e10cSrcweir 		mpSwapOutTimer->Start();
943d327e58aSArmin Le Grand 
944d327e58aSArmin Le Grand     // Handle evtl. needed AfterDataChanges
945d327e58aSArmin Le Grand     ImplAfterDataChange();
946cdf0e10cSrcweir }
947cdf0e10cSrcweir 
948cdf0e10cSrcweir // -----------------------------------------------------------------------------
949cdf0e10cSrcweir 
SetGraphic(const Graphic & rGraphic,const String & rLink)950cdf0e10cSrcweir void GraphicObject::SetGraphic( const Graphic& rGraphic, const String& rLink )
951cdf0e10cSrcweir {
952cdf0e10cSrcweir 	SetGraphic( rGraphic );
953cdf0e10cSrcweir 	mpLink = new String( rLink );
954cdf0e10cSrcweir }
955cdf0e10cSrcweir 
956cdf0e10cSrcweir // -----------------------------------------------------------------------------
957cdf0e10cSrcweir 
GetTransformedGraphic(const Size & rDestSize,const MapMode & rDestMap,const GraphicAttr & rAttr) const958cdf0e10cSrcweir Graphic GraphicObject::GetTransformedGraphic( const Size& rDestSize, const MapMode& rDestMap, const GraphicAttr& rAttr ) const
959cdf0e10cSrcweir {
960cdf0e10cSrcweir     // #104550# Extracted from svx/source/svdraw/svdograf.cxx
961cdf0e10cSrcweir 	Graphic		    	aTransGraphic( maGraphic );
962cdf0e10cSrcweir 	const GraphicType	eType = GetType();
963cdf0e10cSrcweir     const Size      	aSrcSize( aTransGraphic.GetPrefSize() );
964cdf0e10cSrcweir 
965cdf0e10cSrcweir     // #104115# Convert the crop margins to graphic object mapmode
966cdf0e10cSrcweir     const MapMode aMapGraph( aTransGraphic.GetPrefMapMode() );
967cdf0e10cSrcweir     const MapMode aMap100( MAP_100TH_MM );
968cdf0e10cSrcweir 
969cdf0e10cSrcweir     Size aCropLeftTop;
970cdf0e10cSrcweir     Size aCropRightBottom;
971cdf0e10cSrcweir 
972cdf0e10cSrcweir     if( GRAPHIC_GDIMETAFILE == eType )
973cdf0e10cSrcweir     {
974cdf0e10cSrcweir         GDIMetaFile aMtf( aTransGraphic.GetGDIMetaFile() );
975cdf0e10cSrcweir 
976cdf0e10cSrcweir         if( aMapGraph == MAP_PIXEL )
977cdf0e10cSrcweir         {
978a409c94eSArmin Le Grand             // crops are in 1/100th mm -> to aMapGraph -> to MAP_PIXEL
979a409c94eSArmin Le Grand             aCropLeftTop = Application::GetDefaultDevice()->LogicToPixel(
980a409c94eSArmin Le Grand                 Size(rAttr.GetLeftCrop(), rAttr.GetTopCrop()),
981cdf0e10cSrcweir                 aMap100);
982a409c94eSArmin Le Grand             aCropRightBottom = Application::GetDefaultDevice()->LogicToPixel(
983a409c94eSArmin Le Grand                 Size(rAttr.GetRightCrop(), rAttr.GetBottomCrop()),
984cdf0e10cSrcweir                 aMap100);
985cdf0e10cSrcweir         }
986cdf0e10cSrcweir         else
987cdf0e10cSrcweir         {
988a409c94eSArmin Le Grand             // crops are in GraphicObject units -> to aMapGraph
989a409c94eSArmin Le Grand             aCropLeftTop = OutputDevice::LogicToLogic(
990a409c94eSArmin Le Grand                 Size(rAttr.GetLeftCrop(), rAttr.GetTopCrop()),
991cdf0e10cSrcweir                 aMap100,
992cdf0e10cSrcweir                 aMapGraph);
993a409c94eSArmin Le Grand             aCropRightBottom = OutputDevice::LogicToLogic(
994a409c94eSArmin Le Grand                 Size(rAttr.GetRightCrop(), rAttr.GetBottomCrop()),
995cdf0e10cSrcweir                 aMap100,
996cdf0e10cSrcweir                 aMapGraph);
997cdf0e10cSrcweir         }
998cdf0e10cSrcweir 
999cdf0e10cSrcweir         // #104115# If the metafile is cropped, give it a special
1000cdf0e10cSrcweir         // treatment: clip against the remaining area, scale up such
1001cdf0e10cSrcweir         // that this area later fills the desired size, and move the
1002cdf0e10cSrcweir         // origin to the upper left edge of that area.
1003cdf0e10cSrcweir         if( rAttr.IsCropped() )
1004cdf0e10cSrcweir         {
1005cdf0e10cSrcweir             const MapMode aMtfMapMode( aMtf.GetPrefMapMode() );
1006cdf0e10cSrcweir 
1007cdf0e10cSrcweir             Rectangle aClipRect( aMtfMapMode.GetOrigin().X() + aCropLeftTop.Width(),
1008cdf0e10cSrcweir                                  aMtfMapMode.GetOrigin().Y() + aCropLeftTop.Height(),
1009cdf0e10cSrcweir                                  aMtfMapMode.GetOrigin().X() + aSrcSize.Width() - aCropRightBottom.Width(),
1010cdf0e10cSrcweir                                  aMtfMapMode.GetOrigin().Y() + aSrcSize.Height() - aCropRightBottom.Height() );
1011cdf0e10cSrcweir 
1012cdf0e10cSrcweir             // #104115# To correctly crop rotated metafiles, clip by view rectangle
1013cdf0e10cSrcweir             aMtf.AddAction( new MetaISectRectClipRegionAction( aClipRect ), 0 );
1014cdf0e10cSrcweir 
1015cdf0e10cSrcweir             // #104115# To crop the metafile, scale larger than the output rectangle
1016cdf0e10cSrcweir             aMtf.Scale( (double)rDestSize.Width() / (aSrcSize.Width() - aCropLeftTop.Width() - aCropRightBottom.Width()),
1017cdf0e10cSrcweir                         (double)rDestSize.Height() / (aSrcSize.Height() - aCropLeftTop.Height() - aCropRightBottom.Height()) );
1018cdf0e10cSrcweir 
1019cdf0e10cSrcweir             // #104115# Adapt the pref size by hand (scale changes it
1020cdf0e10cSrcweir             // proportionally, but we want it to be smaller than the
1021cdf0e10cSrcweir             // former size, to crop the excess out)
1022cdf0e10cSrcweir             aMtf.SetPrefSize( Size( (long)((double)rDestSize.Width() *  (1.0 + (aCropLeftTop.Width() + aCropRightBottom.Width()) / aSrcSize.Width())  + .5),
1023cdf0e10cSrcweir                                     (long)((double)rDestSize.Height() * (1.0 + (aCropLeftTop.Height() + aCropRightBottom.Height()) / aSrcSize.Height()) + .5) ) );
1024cdf0e10cSrcweir 
1025cdf0e10cSrcweir             // #104115# Adapt the origin of the new mapmode, such that it
1026cdf0e10cSrcweir             // is shifted to the place where the cropped output starts
1027cdf0e10cSrcweir             Point aNewOrigin( (long)((double)aMtfMapMode.GetOrigin().X() + rDestSize.Width() * aCropLeftTop.Width() / (aSrcSize.Width() - aCropLeftTop.Width() - aCropRightBottom.Width()) + .5),
1028cdf0e10cSrcweir                               (long)((double)aMtfMapMode.GetOrigin().Y() + rDestSize.Height() * aCropLeftTop.Height() / (aSrcSize.Height() - aCropLeftTop.Height() - aCropRightBottom.Height()) + .5) );
1029cdf0e10cSrcweir             MapMode aNewMap( rDestMap );
1030cdf0e10cSrcweir             aNewMap.SetOrigin( OutputDevice::LogicToLogic(aNewOrigin, aMtfMapMode, rDestMap) );
1031cdf0e10cSrcweir             aMtf.SetPrefMapMode( aNewMap );
1032cdf0e10cSrcweir         }
1033cdf0e10cSrcweir         else
1034cdf0e10cSrcweir         {
1035cdf0e10cSrcweir             aMtf.Scale( Fraction( rDestSize.Width(), aSrcSize.Width() ), Fraction( rDestSize.Height(), aSrcSize.Height() ) );
1036cdf0e10cSrcweir             aMtf.SetPrefMapMode( rDestMap );
1037cdf0e10cSrcweir         }
1038cdf0e10cSrcweir 
1039cdf0e10cSrcweir         aTransGraphic = aMtf;
1040cdf0e10cSrcweir     }
1041cdf0e10cSrcweir     else if( GRAPHIC_BITMAP == eType )
1042cdf0e10cSrcweir     {
1043cdf0e10cSrcweir         BitmapEx aBitmapEx( aTransGraphic.GetBitmapEx() );
10442376739dSArmin Le Grand         Rectangle aCropRect;
1045cdf0e10cSrcweir 
1046a409c94eSArmin Le Grand         // convert crops to pixel
10472376739dSArmin Le Grand         if(rAttr.IsCropped())
10482376739dSArmin Le Grand         {
1049a409c94eSArmin Le Grand             if( aMapGraph == MAP_PIXEL )
1050a409c94eSArmin Le Grand             {
1051a409c94eSArmin Le Grand                 // crops are in 1/100th mm -> to MAP_PIXEL
1052a409c94eSArmin Le Grand                 aCropLeftTop = Application::GetDefaultDevice()->LogicToPixel(
1053a409c94eSArmin Le Grand                     Size(rAttr.GetLeftCrop(), rAttr.GetTopCrop()),
1054a409c94eSArmin Le Grand                     aMap100);
1055a409c94eSArmin Le Grand                 aCropRightBottom = Application::GetDefaultDevice()->LogicToPixel(
1056a409c94eSArmin Le Grand                     Size(rAttr.GetRightCrop(), rAttr.GetBottomCrop()),
1057a409c94eSArmin Le Grand                     aMap100);
1058a409c94eSArmin Le Grand             }
1059a409c94eSArmin Le Grand             else
1060a409c94eSArmin Le Grand             {
1061a409c94eSArmin Le Grand                 // crops are in GraphicObject units -> to MAP_PIXEL
10622376739dSArmin Le Grand                 aCropLeftTop = Application::GetDefaultDevice()->LogicToPixel(
10632376739dSArmin Le Grand                     Size(rAttr.GetLeftCrop(), rAttr.GetTopCrop()),
10642376739dSArmin Le Grand                     aMapGraph);
10652376739dSArmin Le Grand                 aCropRightBottom = Application::GetDefaultDevice()->LogicToPixel(
10662376739dSArmin Le Grand                     Size(rAttr.GetRightCrop(), rAttr.GetBottomCrop()),
10672376739dSArmin Le Grand                     aMapGraph);
1068a409c94eSArmin Le Grand             }
1069cdf0e10cSrcweir 
1070cdf0e10cSrcweir             // convert from prefmapmode to pixel
10712376739dSArmin Le Grand             Size aSrcSizePixel(
10722376739dSArmin Le Grand                 Application::GetDefaultDevice()->LogicToPixel(
10732376739dSArmin Le Grand                     aSrcSize,
1074cdf0e10cSrcweir                     aMapGraph));
1075cdf0e10cSrcweir 
10762376739dSArmin Le Grand             if(rAttr.IsCropped()
10772376739dSArmin Le Grand                 && (aSrcSizePixel.Width() != aBitmapEx.GetSizePixel().Width() || aSrcSizePixel.Height() != aBitmapEx.GetSizePixel().Height())
10782376739dSArmin Le Grand                 && aSrcSizePixel.Width())
10792376739dSArmin Le Grand             {
10802376739dSArmin Le Grand                 // the size in pixels calculated from Graphic's internal MapMode (aTransGraphic.GetPrefMapMode())
10812376739dSArmin Le Grand                 // and it's internal size (aTransGraphic.GetPrefSize()) is different from it's real pixel size.
10822376739dSArmin Le Grand                 // This can be interpreted as this values to be set wrong, but needs to be corrected since e.g.
10832376739dSArmin Le Grand                 // existing cropping is calculated based on this logic values already.
10842376739dSArmin Le Grand                 // aBitmapEx.Scale(aSrcSizePixel);
10852376739dSArmin Le Grand 
10862376739dSArmin Le Grand                 // another possibility is to adapt the values created so far with a factor; this
10872376739dSArmin Le Grand                 // will keep the original Bitmap untouched and thus quality will not change
1088a409c94eSArmin Le Grand                 // caution: convert to double first, else pretty big errors may occurr
1089a409c94eSArmin Le Grand                 const double fFactorX((double)aBitmapEx.GetSizePixel().Width() / aSrcSizePixel.Width());
1090a409c94eSArmin Le Grand                 const double fFactorY((double)aBitmapEx.GetSizePixel().Height() / aSrcSizePixel.Height());
10912376739dSArmin Le Grand 
10922376739dSArmin Le Grand                 aCropLeftTop.Width() = basegfx::fround(aCropLeftTop.Width() * fFactorX);
10932376739dSArmin Le Grand                 aCropLeftTop.Height() = basegfx::fround(aCropLeftTop.Height() * fFactorY);
10942376739dSArmin Le Grand                 aCropRightBottom.Width() = basegfx::fround(aCropRightBottom.Width() * fFactorX);
10952376739dSArmin Le Grand                 aCropRightBottom.Height() = basegfx::fround(aCropRightBottom.Height() * fFactorY);
10962376739dSArmin Le Grand 
10972376739dSArmin Le Grand                 aSrcSizePixel = aBitmapEx.GetSizePixel();
10982376739dSArmin Le Grand             }
10992376739dSArmin Le Grand 
1100cdf0e10cSrcweir             // setup crop rectangle in pixel
11012376739dSArmin Le Grand             aCropRect = Rectangle( aCropLeftTop.Width(), aCropLeftTop.Height(),
1102cdf0e10cSrcweir                                  aSrcSizePixel.Width() - aCropRightBottom.Width(),
1103cdf0e10cSrcweir                                  aSrcSizePixel.Height() - aCropRightBottom.Height() );
11042376739dSArmin Le Grand         }
1105cdf0e10cSrcweir 
1106cdf0e10cSrcweir         // #105641# Also crop animations
1107cdf0e10cSrcweir         if( aTransGraphic.IsAnimated() )
1108cdf0e10cSrcweir         {
1109cdf0e10cSrcweir             sal_uInt16 nFrame;
1110cdf0e10cSrcweir             Animation aAnim( aTransGraphic.GetAnimation() );
1111cdf0e10cSrcweir 
1112cdf0e10cSrcweir             for( nFrame=0; nFrame<aAnim.Count(); ++nFrame )
1113cdf0e10cSrcweir             {
1114cdf0e10cSrcweir                 AnimationBitmap aAnimBmp( aAnim.Get( nFrame ) );
1115cdf0e10cSrcweir 
1116cdf0e10cSrcweir                 if( !aCropRect.IsInside( Rectangle(aAnimBmp.aPosPix, aAnimBmp.aSizePix) ) )
1117cdf0e10cSrcweir                 {
1118cdf0e10cSrcweir                     // setup actual cropping (relative to frame position)
1119cdf0e10cSrcweir                     Rectangle aCropRectRel( aCropRect );
1120cdf0e10cSrcweir                     aCropRectRel.Move( -aAnimBmp.aPosPix.X(),
1121cdf0e10cSrcweir                                        -aAnimBmp.aPosPix.Y() );
1122cdf0e10cSrcweir 
1123cdf0e10cSrcweir                     // cropping affects this frame, apply it then
1124cdf0e10cSrcweir                     // do _not_ apply enlargement, this is done below
1125cdf0e10cSrcweir                     ImplTransformBitmap( aAnimBmp.aBmpEx, rAttr, Size(), Size(),
1126cdf0e10cSrcweir                                          aCropRectRel, rDestSize, sal_False );
1127cdf0e10cSrcweir 
1128cdf0e10cSrcweir                     aAnim.Replace( aAnimBmp, nFrame );
1129cdf0e10cSrcweir                 }
1130cdf0e10cSrcweir                 // else: bitmap completely within crop area,
1131cdf0e10cSrcweir                 // i.e. nothing is cropped away
1132cdf0e10cSrcweir             }
1133cdf0e10cSrcweir 
1134cdf0e10cSrcweir             // now, apply enlargement (if any) through global animation size
1135cdf0e10cSrcweir             if( aCropLeftTop.Width() < 0 ||
1136cdf0e10cSrcweir                 aCropLeftTop.Height() < 0 ||
1137cdf0e10cSrcweir                 aCropRightBottom.Width() < 0 ||
1138cdf0e10cSrcweir                 aCropRightBottom.Height() < 0 )
1139cdf0e10cSrcweir             {
1140cdf0e10cSrcweir                 Size aNewSize( aAnim.GetDisplaySizePixel() );
1141cdf0e10cSrcweir                 aNewSize.Width() += aCropRightBottom.Width() < 0 ? -aCropRightBottom.Width() : 0;
1142cdf0e10cSrcweir                 aNewSize.Width() += aCropLeftTop.Width() < 0 ? -aCropLeftTop.Width() : 0;
1143cdf0e10cSrcweir                 aNewSize.Height() += aCropRightBottom.Height() < 0 ? -aCropRightBottom.Height() : 0;
1144cdf0e10cSrcweir                 aNewSize.Height() += aCropLeftTop.Height() < 0 ? -aCropLeftTop.Height() : 0;
1145cdf0e10cSrcweir                 aAnim.SetDisplaySizePixel( aNewSize );
1146cdf0e10cSrcweir             }
1147cdf0e10cSrcweir 
1148cdf0e10cSrcweir             // if topleft has changed, we must move all frames to the
1149cdf0e10cSrcweir             // right and bottom, resp.
1150cdf0e10cSrcweir             if( aCropLeftTop.Width() < 0 ||
1151cdf0e10cSrcweir                 aCropLeftTop.Height() < 0 )
1152cdf0e10cSrcweir             {
1153cdf0e10cSrcweir                 Point aPosOffset( aCropLeftTop.Width() < 0 ? -aCropLeftTop.Width() : 0,
1154cdf0e10cSrcweir                                   aCropLeftTop.Height() < 0 ? -aCropLeftTop.Height() : 0 );
1155cdf0e10cSrcweir 
1156cdf0e10cSrcweir                 for( nFrame=0; nFrame<aAnim.Count(); ++nFrame )
1157cdf0e10cSrcweir                 {
1158cdf0e10cSrcweir                     AnimationBitmap aAnimBmp( aAnim.Get( nFrame ) );
1159cdf0e10cSrcweir 
1160cdf0e10cSrcweir                     aAnimBmp.aPosPix += aPosOffset;
1161cdf0e10cSrcweir 
1162cdf0e10cSrcweir                     aAnim.Replace( aAnimBmp, nFrame );
1163cdf0e10cSrcweir                 }
1164cdf0e10cSrcweir             }
1165cdf0e10cSrcweir 
1166cdf0e10cSrcweir             aTransGraphic = aAnim;
1167cdf0e10cSrcweir         }
1168cdf0e10cSrcweir         else
1169cdf0e10cSrcweir         {
11702376739dSArmin Le Grand             ImplTransformBitmap( aBitmapEx, rAttr, aCropLeftTop, aCropRightBottom,
1171cdf0e10cSrcweir                                  aCropRect, rDestSize, sal_True );
1172cdf0e10cSrcweir 
11732376739dSArmin Le Grand             aTransGraphic = aBitmapEx;
1174cdf0e10cSrcweir         }
1175cdf0e10cSrcweir 
1176cdf0e10cSrcweir         aTransGraphic.SetPrefSize( rDestSize );
1177cdf0e10cSrcweir         aTransGraphic.SetPrefMapMode( rDestMap );
1178cdf0e10cSrcweir     }
1179cdf0e10cSrcweir 
1180cdf0e10cSrcweir     GraphicObject aGrfObj( aTransGraphic );
1181cdf0e10cSrcweir     aTransGraphic = aGrfObj.GetTransformedGraphic( &rAttr );
1182cdf0e10cSrcweir 
1183cdf0e10cSrcweir 	return aTransGraphic;
1184cdf0e10cSrcweir }
1185cdf0e10cSrcweir 
1186cdf0e10cSrcweir // -----------------------------------------------------------------------------
1187cdf0e10cSrcweir 
GetTransformedGraphic(const GraphicAttr * pAttr) const1188cdf0e10cSrcweir Graphic GraphicObject::GetTransformedGraphic( const GraphicAttr* pAttr ) const // TODO: Change to Impl
1189cdf0e10cSrcweir {
1190cdf0e10cSrcweir 	GetGraphic();
1191cdf0e10cSrcweir 
1192cdf0e10cSrcweir 	Graphic     aGraphic;
1193cdf0e10cSrcweir     GraphicAttr aAttr( pAttr ? *pAttr : GetAttr() );
1194cdf0e10cSrcweir 
1195cdf0e10cSrcweir 	if( maGraphic.IsSupportedGraphic() && !maGraphic.IsSwapOut() )
1196cdf0e10cSrcweir 	{
1197cdf0e10cSrcweir 		if( aAttr.IsSpecialDrawMode() || aAttr.IsAdjusted() || aAttr.IsMirrored() || aAttr.IsRotated() || aAttr.IsTransparent() )
1198cdf0e10cSrcweir 		{
1199cdf0e10cSrcweir 			if( GetType() == GRAPHIC_BITMAP )
1200cdf0e10cSrcweir 			{
1201cdf0e10cSrcweir 				if( IsAnimated() )
1202cdf0e10cSrcweir 				{
1203cdf0e10cSrcweir 					Animation aAnimation( maGraphic.GetAnimation() );
1204cdf0e10cSrcweir 					GraphicManager::ImplAdjust( aAnimation, aAttr, ADJUSTMENT_ALL );
1205cdf0e10cSrcweir                     aAnimation.SetLoopCount( mnAnimationLoopCount );
1206cdf0e10cSrcweir 					aGraphic = aAnimation;
1207cdf0e10cSrcweir 				}
1208cdf0e10cSrcweir 				else
1209cdf0e10cSrcweir 				{
1210cdf0e10cSrcweir 					BitmapEx aBmpEx( maGraphic.GetBitmapEx() );
1211cdf0e10cSrcweir 					GraphicManager::ImplAdjust( aBmpEx, aAttr, ADJUSTMENT_ALL );
1212cdf0e10cSrcweir 					aGraphic = aBmpEx;
1213cdf0e10cSrcweir 				}
1214cdf0e10cSrcweir 			}
1215cdf0e10cSrcweir 			else
1216cdf0e10cSrcweir 			{
1217cdf0e10cSrcweir 				GDIMetaFile aMtf( maGraphic.GetGDIMetaFile() );
1218cdf0e10cSrcweir 				GraphicManager::ImplAdjust( aMtf, aAttr, ADJUSTMENT_ALL );
1219cdf0e10cSrcweir 				aGraphic = aMtf;
1220cdf0e10cSrcweir 			}
1221cdf0e10cSrcweir 		}
1222cdf0e10cSrcweir 		else
1223cdf0e10cSrcweir         {
1224cdf0e10cSrcweir 			if( ( GetType() == GRAPHIC_BITMAP ) && IsAnimated() )
1225cdf0e10cSrcweir 			{
1226cdf0e10cSrcweir 				Animation aAnimation( maGraphic.GetAnimation() );
1227cdf0e10cSrcweir                 aAnimation.SetLoopCount( mnAnimationLoopCount );
1228cdf0e10cSrcweir 				aGraphic = aAnimation;
1229cdf0e10cSrcweir 			}
1230cdf0e10cSrcweir             else
1231cdf0e10cSrcweir 			    aGraphic = maGraphic;
1232cdf0e10cSrcweir         }
1233cdf0e10cSrcweir 	}
1234cdf0e10cSrcweir 
1235cdf0e10cSrcweir 	return aGraphic;
1236cdf0e10cSrcweir }
1237cdf0e10cSrcweir 
1238cdf0e10cSrcweir // -----------------------------------------------------------------------------
1239cdf0e10cSrcweir 
ResetAnimationLoopCount()1240cdf0e10cSrcweir void GraphicObject::ResetAnimationLoopCount()
1241cdf0e10cSrcweir {
1242cdf0e10cSrcweir 	if( IsAnimated() && !IsSwappedOut() )
1243cdf0e10cSrcweir 	{
1244cdf0e10cSrcweir 		maGraphic.ResetAnimationLoopCount();
1245cdf0e10cSrcweir 
1246cdf0e10cSrcweir 		if( mpSimpleCache )
1247cdf0e10cSrcweir 			mpSimpleCache->maGraphic.ResetAnimationLoopCount();
1248cdf0e10cSrcweir 	}
1249cdf0e10cSrcweir }
1250cdf0e10cSrcweir 
1251cdf0e10cSrcweir // -----------------------------------------------------------------------------
1252cdf0e10cSrcweir 
SwapOut()1253cdf0e10cSrcweir sal_Bool GraphicObject::SwapOut()
1254cdf0e10cSrcweir {
1255cdf0e10cSrcweir 	sal_Bool bRet = ( !mbAutoSwapped ? maGraphic.SwapOut() : sal_False );
1256cdf0e10cSrcweir 
1257cdf0e10cSrcweir 	if( bRet && mpMgr )
1258cdf0e10cSrcweir 		mpMgr->ImplGraphicObjectWasSwappedOut( *this );
1259cdf0e10cSrcweir 
1260cdf0e10cSrcweir 	return bRet;
1261cdf0e10cSrcweir }
1262cdf0e10cSrcweir 
1263cdf0e10cSrcweir // -----------------------------------------------------------------------------
1264cdf0e10cSrcweir 
SwapOut(SvStream * pOStm)1265cdf0e10cSrcweir sal_Bool GraphicObject::SwapOut( SvStream* pOStm )
1266cdf0e10cSrcweir {
1267cdf0e10cSrcweir 	sal_Bool bRet = ( !mbAutoSwapped ? maGraphic.SwapOut( pOStm ) : sal_False );
1268cdf0e10cSrcweir 
1269cdf0e10cSrcweir 	if( bRet && mpMgr )
1270cdf0e10cSrcweir 		mpMgr->ImplGraphicObjectWasSwappedOut( *this );
1271cdf0e10cSrcweir 
1272cdf0e10cSrcweir 	return bRet;
1273cdf0e10cSrcweir }
1274cdf0e10cSrcweir 
1275cdf0e10cSrcweir // -----------------------------------------------------------------------------
1276cdf0e10cSrcweir 
SwapIn()1277cdf0e10cSrcweir sal_Bool GraphicObject::SwapIn()
1278cdf0e10cSrcweir {
1279cdf0e10cSrcweir 	sal_Bool bRet;
1280cdf0e10cSrcweir 
1281cdf0e10cSrcweir 	if( mbAutoSwapped )
1282cdf0e10cSrcweir 	{
1283cdf0e10cSrcweir 		ImplAutoSwapIn();
1284cdf0e10cSrcweir 		bRet = sal_True;
1285cdf0e10cSrcweir 	}
1286cdf0e10cSrcweir 	else if( mpMgr && mpMgr->ImplFillSwappedGraphicObject( *this, maGraphic ) )
1287d327e58aSArmin Le Grand     {
1288cdf0e10cSrcweir 		bRet = sal_True;
1289d327e58aSArmin Le Grand     }
1290cdf0e10cSrcweir 	else
1291cdf0e10cSrcweir 	{
1292cdf0e10cSrcweir 		bRet = maGraphic.SwapIn();
1293cdf0e10cSrcweir 
1294cdf0e10cSrcweir 		if( bRet && mpMgr )
1295cdf0e10cSrcweir 			mpMgr->ImplGraphicObjectWasSwappedIn( *this );
1296cdf0e10cSrcweir 	}
1297cdf0e10cSrcweir 
1298cdf0e10cSrcweir 	if( bRet )
1299d327e58aSArmin Le Grand     {
1300cdf0e10cSrcweir 		ImplAssignGraphicData();
1301cdf0e10cSrcweir 
1302d327e58aSArmin Le Grand         // Handle evtl. needed AfterDataChanges
1303d327e58aSArmin Le Grand         ImplAfterDataChange();
1304d327e58aSArmin Le Grand     }
1305d327e58aSArmin Le Grand 
1306cdf0e10cSrcweir 	return bRet;
1307cdf0e10cSrcweir }
1308cdf0e10cSrcweir 
1309cdf0e10cSrcweir // -----------------------------------------------------------------------------
1310cdf0e10cSrcweir 
SwapIn(SvStream * pIStm)1311cdf0e10cSrcweir sal_Bool GraphicObject::SwapIn( SvStream* pIStm )
1312cdf0e10cSrcweir {
1313cdf0e10cSrcweir 	sal_Bool bRet;
1314cdf0e10cSrcweir 
1315cdf0e10cSrcweir 	if( mbAutoSwapped )
1316cdf0e10cSrcweir 	{
1317cdf0e10cSrcweir 		ImplAutoSwapIn();
1318cdf0e10cSrcweir 		bRet = sal_True;
1319cdf0e10cSrcweir 	}
1320cdf0e10cSrcweir 	else if( mpMgr && mpMgr->ImplFillSwappedGraphicObject( *this, maGraphic ) )
1321d327e58aSArmin Le Grand     {
1322cdf0e10cSrcweir 		bRet = sal_True;
1323d327e58aSArmin Le Grand     }
1324cdf0e10cSrcweir 	else
1325cdf0e10cSrcweir 	{
1326cdf0e10cSrcweir 		bRet = maGraphic.SwapIn( pIStm );
1327cdf0e10cSrcweir 
1328cdf0e10cSrcweir 		if( bRet && mpMgr )
1329cdf0e10cSrcweir 			mpMgr->ImplGraphicObjectWasSwappedIn( *this );
1330cdf0e10cSrcweir 	}
1331cdf0e10cSrcweir 
1332cdf0e10cSrcweir 	if( bRet )
1333d327e58aSArmin Le Grand     {
1334cdf0e10cSrcweir 		ImplAssignGraphicData();
1335cdf0e10cSrcweir 
1336d327e58aSArmin Le Grand         //
1337d327e58aSArmin Le Grand         ImplAfterDataChange();
1338d327e58aSArmin Le Grand     }
1339d327e58aSArmin Le Grand 
1340cdf0e10cSrcweir 	return bRet;
1341cdf0e10cSrcweir }
1342cdf0e10cSrcweir 
1343cdf0e10cSrcweir // -----------------------------------------------------------------------------
1344cdf0e10cSrcweir 
SetSwapState()1345cdf0e10cSrcweir void GraphicObject::SetSwapState()
1346cdf0e10cSrcweir {
1347cdf0e10cSrcweir 	if( !IsSwappedOut() )
1348cdf0e10cSrcweir 	{
1349cdf0e10cSrcweir 		mbAutoSwapped = sal_True;
1350cdf0e10cSrcweir 
1351cdf0e10cSrcweir 		if( mpMgr )
1352cdf0e10cSrcweir 			mpMgr->ImplGraphicObjectWasSwappedOut( *this );
1353cdf0e10cSrcweir 	}
1354cdf0e10cSrcweir }
1355cdf0e10cSrcweir 
1356cdf0e10cSrcweir // -----------------------------------------------------------------------------
1357cdf0e10cSrcweir 
IMPL_LINK(GraphicObject,ImplAutoSwapOutHdl,void *,EMPTYARG)1358cdf0e10cSrcweir IMPL_LINK( GraphicObject, ImplAutoSwapOutHdl, void*, EMPTYARG )
1359cdf0e10cSrcweir {
1360cdf0e10cSrcweir 	if( !IsSwappedOut() )
1361cdf0e10cSrcweir 	{
1362cdf0e10cSrcweir 		mbIsInSwapOut = sal_True;
1363cdf0e10cSrcweir 
1364cdf0e10cSrcweir 		SvStream* pStream = GetSwapStream();
1365cdf0e10cSrcweir 
1366cdf0e10cSrcweir 		if( GRFMGR_AUTOSWAPSTREAM_NONE != pStream )
1367cdf0e10cSrcweir 		{
1368cdf0e10cSrcweir 			if( GRFMGR_AUTOSWAPSTREAM_LINK == pStream )
1369cdf0e10cSrcweir 				mbAutoSwapped = SwapOut( NULL );
1370cdf0e10cSrcweir 			else
1371cdf0e10cSrcweir 			{
1372cdf0e10cSrcweir 				if( GRFMGR_AUTOSWAPSTREAM_TEMP == pStream )
1373cdf0e10cSrcweir 					mbAutoSwapped = SwapOut();
1374cdf0e10cSrcweir 				else
1375cdf0e10cSrcweir 				{
1376cdf0e10cSrcweir 					mbAutoSwapped = SwapOut( pStream );
1377cdf0e10cSrcweir 					delete pStream;
1378cdf0e10cSrcweir 				}
1379cdf0e10cSrcweir 			}
1380cdf0e10cSrcweir 		}
1381cdf0e10cSrcweir 
1382cdf0e10cSrcweir 		mbIsInSwapOut = sal_False;
1383cdf0e10cSrcweir 	}
1384cdf0e10cSrcweir 
1385cdf0e10cSrcweir 	if( mpSwapOutTimer )
1386cdf0e10cSrcweir 		mpSwapOutTimer->Start();
1387cdf0e10cSrcweir 
1388cdf0e10cSrcweir 	return 0L;
1389cdf0e10cSrcweir }
1390cdf0e10cSrcweir 
1391cdf0e10cSrcweir // ------------------------------------------------------------------------
1392cdf0e10cSrcweir 
operator >>(SvStream & rIStm,GraphicObject & rGraphicObj)1393cdf0e10cSrcweir SvStream& operator>>( SvStream& rIStm, GraphicObject& rGraphicObj )
1394cdf0e10cSrcweir {
1395cdf0e10cSrcweir 	VersionCompat	aCompat( rIStm, STREAM_READ );
1396cdf0e10cSrcweir 	Graphic			aGraphic;
1397cdf0e10cSrcweir 	GraphicAttr		aAttr;
1398cdf0e10cSrcweir 	ByteString		aLink;
1399cdf0e10cSrcweir 	sal_Bool			bLink;
1400cdf0e10cSrcweir 
1401cdf0e10cSrcweir 	rIStm >> aGraphic >> aAttr >> bLink;
1402cdf0e10cSrcweir 
1403cdf0e10cSrcweir 	rGraphicObj.SetGraphic( aGraphic );
1404cdf0e10cSrcweir 	rGraphicObj.SetAttr( aAttr );
1405cdf0e10cSrcweir 
1406cdf0e10cSrcweir 	if( bLink )
1407cdf0e10cSrcweir 	{
1408cdf0e10cSrcweir 		rIStm >> aLink;
1409cdf0e10cSrcweir 		rGraphicObj.SetLink( UniString( aLink, RTL_TEXTENCODING_UTF8 ) );
1410cdf0e10cSrcweir 	}
1411cdf0e10cSrcweir 	else
1412cdf0e10cSrcweir 		rGraphicObj.SetLink();
1413cdf0e10cSrcweir 
1414cdf0e10cSrcweir 	rGraphicObj.SetSwapStreamHdl();
1415cdf0e10cSrcweir 
1416cdf0e10cSrcweir 	return rIStm;
1417cdf0e10cSrcweir }
1418cdf0e10cSrcweir 
1419cdf0e10cSrcweir // ------------------------------------------------------------------------
1420cdf0e10cSrcweir 
operator <<(SvStream & rOStm,const GraphicObject & rGraphicObj)1421cdf0e10cSrcweir SvStream& operator<<( SvStream& rOStm, const GraphicObject& rGraphicObj )
1422cdf0e10cSrcweir {
1423cdf0e10cSrcweir 	VersionCompat	aCompat( rOStm, STREAM_WRITE, 1 );
1424cdf0e10cSrcweir 	const sal_Bool		bLink =  rGraphicObj.HasLink();
1425cdf0e10cSrcweir 
1426cdf0e10cSrcweir 	rOStm << rGraphicObj.GetGraphic() << rGraphicObj.GetAttr() << bLink;
1427cdf0e10cSrcweir 
1428cdf0e10cSrcweir 	if( bLink )
1429cdf0e10cSrcweir 		rOStm << ByteString( rGraphicObj.GetLink(), RTL_TEXTENCODING_UTF8 );
1430cdf0e10cSrcweir 
1431cdf0e10cSrcweir 	return rOStm;
1432cdf0e10cSrcweir }
1433cdf0e10cSrcweir 
1434cdf0e10cSrcweir #define UNO_NAME_GRAPHOBJ_URLPREFIX "vnd.sun.star.GraphicObject:"
1435cdf0e10cSrcweir 
CreateGraphicObjectFromURL(const::rtl::OUString & rURL)1436cdf0e10cSrcweir GraphicObject GraphicObject::CreateGraphicObjectFromURL( const ::rtl::OUString &rURL )
1437cdf0e10cSrcweir {
1438cdf0e10cSrcweir 	const String aURL( rURL ), aPrefix( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_GRAPHOBJ_URLPREFIX) );
1439cdf0e10cSrcweir 	if( aURL.Search( aPrefix ) == 0 )
1440cdf0e10cSrcweir 	{
1441cdf0e10cSrcweir 		// graphic manager url
1442cdf0e10cSrcweir 		ByteString aUniqueID( String(rURL.copy( sizeof( UNO_NAME_GRAPHOBJ_URLPREFIX ) - 1 )), RTL_TEXTENCODING_UTF8 );
1443cdf0e10cSrcweir 		return GraphicObject( aUniqueID );
1444cdf0e10cSrcweir 	}
1445cdf0e10cSrcweir 	else
1446cdf0e10cSrcweir 	{
1447cdf0e10cSrcweir 		Graphic		aGraphic;
1448cdf0e10cSrcweir 		if ( aURL.Len() )
1449cdf0e10cSrcweir 		{
1450*58b03506SArrigo Marchiori 			/* We must obtain authorization from the current document, and we
1451*58b03506SArrigo Marchiori 			   need a ServiceManager to access it. Because utl::UcbStreamHelper
1452*58b03506SArrigo Marchiori 			   relies on the ::ucbhelper::ContentBroker instance, we will
1453*58b03506SArrigo Marchiori 			   use its ServiceManager. */
1454*58b03506SArrigo Marchiori 			::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get();
1455*58b03506SArrigo Marchiori 			if ( pBroker ) {
1456*58b03506SArrigo Marchiori 				uno::Reference< lang::XMultiServiceFactory > xFactory = pBroker->getServiceManager();
1457*58b03506SArrigo Marchiori 				uno::Any desktop( xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ) );
1458*58b03506SArrigo Marchiori 				uno::Reference< com::sun::star::frame::XDesktop > xDesktop( desktop, uno::UNO_QUERY );
1459*58b03506SArrigo Marchiori 				if ( xDesktop.is() ) {
1460*58b03506SArrigo Marchiori 					uno::Reference< ::com::sun::star::frame::XFrame > xFrame = xDesktop->getCurrentFrame();
1461*58b03506SArrigo Marchiori 					if ( xFrame.is() ) {
1462*58b03506SArrigo Marchiori 						uno::Reference< ::com::sun::star::frame::XController > xController = xFrame->getController();
1463*58b03506SArrigo Marchiori 						if ( xController.is() ) {
1464*58b03506SArrigo Marchiori 							uno::Reference< ::com::sun::star::frame::XModel > xModel = xController->getModel();
1465*58b03506SArrigo Marchiori 							if ( xModel.is() ) {
1466*58b03506SArrigo Marchiori 								uno::Reference< com::sun::star::document::XLinkAuthorizer > xLinkAuthorizer( xModel, uno::UNO_QUERY);
1467*58b03506SArrigo Marchiori 								if ( xLinkAuthorizer.is() ) {
1468*58b03506SArrigo Marchiori 									if ( !xLinkAuthorizer->authorizeLinks( aURL ) )
1469*58b03506SArrigo Marchiori 										return GraphicObject( aGraphic );
1470*58b03506SArrigo Marchiori 								}
1471*58b03506SArrigo Marchiori 							}
1472*58b03506SArrigo Marchiori 						}
1473*58b03506SArrigo Marchiori 					}
1474*58b03506SArrigo Marchiori 				}
1475*58b03506SArrigo Marchiori 			}
1476*58b03506SArrigo Marchiori 
1477cdf0e10cSrcweir 			SvStream*	pStream = utl::UcbStreamHelper::CreateStream( aURL, STREAM_READ );
1478cdf0e10cSrcweir 			if( pStream )
1479cdf0e10cSrcweir 				GraphicConverter::Import( *pStream, aGraphic );
1480cdf0e10cSrcweir 		}
1481cdf0e10cSrcweir 
1482cdf0e10cSrcweir 		return GraphicObject( aGraphic );
1483cdf0e10cSrcweir 	}
1484cdf0e10cSrcweir }
14852376739dSArmin Le Grand 
14862376739dSArmin Le Grand // calculate scalings between real image size and logic object size. This
14872376739dSArmin Le Grand // is necessary since the crop values are relative to original bitmap size
calculateCropScaling(double fWidth,double fHeight,double fLeftCrop,double fTopCrop,double fRightCrop,double fBottomCrop) const14882376739dSArmin Le Grand basegfx::B2DVector GraphicObject::calculateCropScaling(
14892376739dSArmin Le Grand     double fWidth,
14902376739dSArmin Le Grand     double fHeight,
14912376739dSArmin Le Grand     double fLeftCrop,
14922376739dSArmin Le Grand     double fTopCrop,
14932376739dSArmin Le Grand     double fRightCrop,
14942376739dSArmin Le Grand     double fBottomCrop) const
14952376739dSArmin Le Grand {
14962376739dSArmin Le Grand     const MapMode aMapMode100thmm(MAP_100TH_MM);
14972376739dSArmin Le Grand     Size aBitmapSize(GetPrefSize());
14982376739dSArmin Le Grand     double fFactorX(1.0);
14992376739dSArmin Le Grand     double fFactorY(1.0);
15002376739dSArmin Le Grand 
15012376739dSArmin Le Grand     if(MAP_PIXEL == GetPrefMapMode().GetMapUnit())
15022376739dSArmin Le Grand     {
15032376739dSArmin Le Grand         aBitmapSize = Application::GetDefaultDevice()->PixelToLogic(aBitmapSize, aMapMode100thmm);
15042376739dSArmin Le Grand     }
15052376739dSArmin Le Grand     else
15062376739dSArmin Le Grand     {
15072376739dSArmin Le Grand         aBitmapSize = Application::GetDefaultDevice()->LogicToLogic(aBitmapSize, GetPrefMapMode(), aMapMode100thmm);
15082376739dSArmin Le Grand     }
15092376739dSArmin Le Grand 
15102376739dSArmin Le Grand     const double fDivX(aBitmapSize.Width() - fLeftCrop - fRightCrop);
15112376739dSArmin Le Grand     const double fDivY(aBitmapSize.Height() - fTopCrop - fBottomCrop);
15122376739dSArmin Le Grand 
15132376739dSArmin Le Grand     if(!basegfx::fTools::equalZero(fDivX))
15142376739dSArmin Le Grand     {
15152376739dSArmin Le Grand         fFactorX = fabs(fWidth) / fDivX;
15162376739dSArmin Le Grand     }
15172376739dSArmin Le Grand 
15182376739dSArmin Le Grand     if(!basegfx::fTools::equalZero(fDivY))
15192376739dSArmin Le Grand     {
15202376739dSArmin Le Grand         fFactorY = fabs(fHeight) / fDivY;
15212376739dSArmin Le Grand     }
15222376739dSArmin Le Grand 
15232376739dSArmin Le Grand     return basegfx::B2DVector(fFactorX,fFactorY);
15242376739dSArmin Le Grand }
15252376739dSArmin Le Grand 
1526d327e58aSArmin Le Grand // ------------------------------------------------------------------------
1527d327e58aSArmin Le Grand // restart SwapOut timer
1528d327e58aSArmin Le Grand 
restartSwapOutTimer() const1529d327e58aSArmin Le Grand void GraphicObject::restartSwapOutTimer() const
1530d327e58aSArmin Le Grand {
1531d327e58aSArmin Le Grand     if( mpSwapOutTimer && mpSwapOutTimer->IsActive() )
1532d327e58aSArmin Le Grand     {
1533d327e58aSArmin Le Grand         mpSwapOutTimer->Start();
1534d327e58aSArmin Le Grand     }
1535d327e58aSArmin Le Grand }
1536d327e58aSArmin Le Grand 
15372376739dSArmin Le Grand // eof
1538