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