19f62ea84SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 39f62ea84SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 49f62ea84SAndrew Rist * or more contributor license agreements. See the NOTICE file 59f62ea84SAndrew Rist * distributed with this work for additional information 69f62ea84SAndrew Rist * regarding copyright ownership. The ASF licenses this file 79f62ea84SAndrew Rist * to you under the Apache License, Version 2.0 (the 89f62ea84SAndrew Rist * "License"); you may not use this file except in compliance 99f62ea84SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 119f62ea84SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 139f62ea84SAndrew Rist * Unless required by applicable law or agreed to in writing, 149f62ea84SAndrew Rist * software distributed under the License is distributed on an 159f62ea84SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 169f62ea84SAndrew Rist * KIND, either express or implied. See the License for the 179f62ea84SAndrew Rist * specific language governing permissions and limitations 189f62ea84SAndrew Rist * under the License. 19cdf0e10cSrcweir * 209f62ea84SAndrew Rist *************************************************************/ 219f62ea84SAndrew Rist 229f62ea84SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_vcl.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <tools/vcompat.hxx> 28cdf0e10cSrcweir #include <tools/urlobj.hxx> 29cdf0e10cSrcweir #include <tools/debug.hxx> 30cdf0e10cSrcweir #include <tools/stream.hxx> 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <ucbhelper/content.hxx> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx> 35cdf0e10cSrcweir #include <unotools/tempfile.hxx> 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include <vcl/outdev.hxx> 38cdf0e10cSrcweir #include <vcl/virdev.hxx> 39cdf0e10cSrcweir #include <vcl/gfxlink.hxx> 40cdf0e10cSrcweir #include <vcl/cvtgrf.hxx> 41cdf0e10cSrcweir #include <vcl/salbtype.hxx> 42cdf0e10cSrcweir #include <vcl/graph.hxx> 43cdf0e10cSrcweir #include <vcl/metaact.hxx> 44cdf0e10cSrcweir 45cdf0e10cSrcweir #include <impgraph.hxx> 46cdf0e10cSrcweir 47cdf0e10cSrcweir #include <com/sun/star/ucb/CommandAbortedException.hpp> 48cdf0e10cSrcweir 49cdf0e10cSrcweir // ----------- 50cdf0e10cSrcweir // - Defines - 51cdf0e10cSrcweir // ----------- 52cdf0e10cSrcweir 53cdf0e10cSrcweir #define GRAPHIC_MAXPARTLEN 256000L 54cdf0e10cSrcweir #define GRAPHIC_MTFTOBMP_MAXEXT 2048 55cdf0e10cSrcweir #define GRAPHIC_STREAMBUFSIZE 8192UL 56cdf0e10cSrcweir 57cdf0e10cSrcweir #define SYS_WINMETAFILE 0x00000003L 58cdf0e10cSrcweir #define SYS_WNTMETAFILE 0x00000004L 59cdf0e10cSrcweir #define SYS_OS2METAFILE 0x00000005L 60cdf0e10cSrcweir #define SYS_MACMETAFILE 0x00000006L 61cdf0e10cSrcweir 62cdf0e10cSrcweir #define GRAPHIC_FORMAT_50 static_cast<sal_uInt32>(COMPAT_FORMAT( 'G', 'R', 'F', '5' )) 63cdf0e10cSrcweir #define NATIVE_FORMAT_50 static_cast<sal_uInt32>(COMPAT_FORMAT( 'N', 'A', 'T', '5' )) 64cdf0e10cSrcweir 65cdf0e10cSrcweir // --------------- 66cdf0e10cSrcweir // - ImpSwapFile - 67cdf0e10cSrcweir // --------------- 68cdf0e10cSrcweir 69cdf0e10cSrcweir struct ImpSwapFile 70cdf0e10cSrcweir { 71cdf0e10cSrcweir INetURLObject aSwapURL; 72cdf0e10cSrcweir sal_uLong nRefCount; 73cdf0e10cSrcweir }; 74cdf0e10cSrcweir 75cdf0e10cSrcweir // ----------------- 76cdf0e10cSrcweir // - Graphicreader - 77cdf0e10cSrcweir // ----------------- 78cdf0e10cSrcweir 79cdf0e10cSrcweir class ReaderData 80cdf0e10cSrcweir { 81cdf0e10cSrcweir public: 82cdf0e10cSrcweir Size maPreviewSize; 83cdf0e10cSrcweir }; 84cdf0e10cSrcweir 85cdf0e10cSrcweir GraphicReader::~GraphicReader() 86cdf0e10cSrcweir { 87cdf0e10cSrcweir delete mpReaderData; 88cdf0e10cSrcweir } 89cdf0e10cSrcweir 90cdf0e10cSrcweir // ------------------------------------------------------------------------ 91cdf0e10cSrcweir 92cdf0e10cSrcweir sal_Bool GraphicReader::IsPreviewModeEnabled() const 93cdf0e10cSrcweir { 94cdf0e10cSrcweir if( !mpReaderData ) 95cdf0e10cSrcweir return sal_False; 96cdf0e10cSrcweir if( mpReaderData->maPreviewSize.Width() ) 97cdf0e10cSrcweir return sal_True; 98cdf0e10cSrcweir if( mpReaderData->maPreviewSize.Height() ) 99cdf0e10cSrcweir return sal_True; 100cdf0e10cSrcweir return sal_False; 101cdf0e10cSrcweir } 102cdf0e10cSrcweir 103cdf0e10cSrcweir // ------------------------------------------------------------------------ 104cdf0e10cSrcweir 105cdf0e10cSrcweir void GraphicReader::DisablePreviewMode() 106cdf0e10cSrcweir { 107cdf0e10cSrcweir if( mpReaderData ) 108cdf0e10cSrcweir mpReaderData->maPreviewSize = Size( 0, 0 ); 109cdf0e10cSrcweir } 110cdf0e10cSrcweir 111cdf0e10cSrcweir // ------------------------------------------------------------------------ 112cdf0e10cSrcweir 113cdf0e10cSrcweir void GraphicReader::SetPreviewSize( const Size& rSize ) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir if( !mpReaderData ) 116cdf0e10cSrcweir mpReaderData = new ReaderData; 117cdf0e10cSrcweir mpReaderData->maPreviewSize = rSize; 118cdf0e10cSrcweir } 119cdf0e10cSrcweir 120cdf0e10cSrcweir // ------------------------------------------------------------------------ 121cdf0e10cSrcweir 122cdf0e10cSrcweir Size GraphicReader::GetPreviewSize() const 123cdf0e10cSrcweir { 124cdf0e10cSrcweir Size aSize( 0, 0 ); 125cdf0e10cSrcweir if( mpReaderData ) 126cdf0e10cSrcweir aSize = mpReaderData->maPreviewSize; 127cdf0e10cSrcweir return aSize; 128cdf0e10cSrcweir } 129cdf0e10cSrcweir 130cdf0e10cSrcweir // -------------- 131cdf0e10cSrcweir // - ImpGraphic - 132cdf0e10cSrcweir // -------------- 133cdf0e10cSrcweir 134cdf0e10cSrcweir ImpGraphic::ImpGraphic() : 135cdf0e10cSrcweir mpAnimation ( NULL ), 136cdf0e10cSrcweir mpContext ( NULL ), 137cdf0e10cSrcweir mpSwapFile ( NULL ), 138cdf0e10cSrcweir mpGfxLink ( NULL ), 139cdf0e10cSrcweir meType ( GRAPHIC_NONE ), 140cdf0e10cSrcweir mnDocFilePos ( 0UL ), 141cdf0e10cSrcweir mnSizeBytes ( 0UL ), 142cdf0e10cSrcweir mnRefCount ( 1UL ), 143cdf0e10cSrcweir mbSwapOut ( sal_False ), 144cdf0e10cSrcweir mbSwapUnderway ( sal_False ) 145cdf0e10cSrcweir { 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 148cdf0e10cSrcweir // ------------------------------------------------------------------------ 149cdf0e10cSrcweir 150cdf0e10cSrcweir ImpGraphic::ImpGraphic( const ImpGraphic& rImpGraphic ) : 151cdf0e10cSrcweir maMetaFile ( rImpGraphic.maMetaFile ), 152cdf0e10cSrcweir maEx ( rImpGraphic.maEx ), 153cdf0e10cSrcweir mpContext ( NULL ), 154cdf0e10cSrcweir mpSwapFile ( rImpGraphic.mpSwapFile ), 155cdf0e10cSrcweir meType ( rImpGraphic.meType ), 156cdf0e10cSrcweir maDocFileURLStr ( rImpGraphic.maDocFileURLStr ), 157cdf0e10cSrcweir mnDocFilePos ( rImpGraphic.mnDocFilePos ), 158cdf0e10cSrcweir mnSizeBytes ( rImpGraphic.mnSizeBytes ), 159cdf0e10cSrcweir mnRefCount ( 1UL ), 160cdf0e10cSrcweir mbSwapOut ( rImpGraphic.mbSwapOut ), 161cdf0e10cSrcweir mbSwapUnderway ( sal_False ) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir if( mpSwapFile ) 164cdf0e10cSrcweir mpSwapFile->nRefCount++; 165cdf0e10cSrcweir 166cdf0e10cSrcweir if( rImpGraphic.mpGfxLink ) 167cdf0e10cSrcweir mpGfxLink = new GfxLink( *rImpGraphic.mpGfxLink ); 168cdf0e10cSrcweir else 169cdf0e10cSrcweir mpGfxLink = NULL; 170cdf0e10cSrcweir 171cdf0e10cSrcweir if( rImpGraphic.mpAnimation ) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir mpAnimation = new Animation( *rImpGraphic.mpAnimation ); 174cdf0e10cSrcweir maEx = mpAnimation->GetBitmapEx(); 175cdf0e10cSrcweir } 176cdf0e10cSrcweir else 177cdf0e10cSrcweir mpAnimation = NULL; 178*ddde725dSArmin Le Grand 179*ddde725dSArmin Le Grand maSvgData = rImpGraphic.maSvgData; 180cdf0e10cSrcweir } 181cdf0e10cSrcweir 182cdf0e10cSrcweir // ------------------------------------------------------------------------ 183cdf0e10cSrcweir 184cdf0e10cSrcweir ImpGraphic::ImpGraphic( const Bitmap& rBitmap ) : 185cdf0e10cSrcweir maEx ( rBitmap ), 186cdf0e10cSrcweir mpAnimation ( NULL ), 187cdf0e10cSrcweir mpContext ( NULL ), 188cdf0e10cSrcweir mpSwapFile ( NULL ), 189cdf0e10cSrcweir mpGfxLink ( NULL ), 190cdf0e10cSrcweir meType ( !rBitmap ? GRAPHIC_NONE : GRAPHIC_BITMAP ), 191cdf0e10cSrcweir mnDocFilePos ( 0UL ), 192cdf0e10cSrcweir mnSizeBytes ( 0UL ), 193cdf0e10cSrcweir mnRefCount ( 1UL ), 194cdf0e10cSrcweir mbSwapOut ( sal_False ), 195cdf0e10cSrcweir mbSwapUnderway ( sal_False ) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir } 198cdf0e10cSrcweir 199cdf0e10cSrcweir // ------------------------------------------------------------------------ 200cdf0e10cSrcweir 201cdf0e10cSrcweir ImpGraphic::ImpGraphic( const BitmapEx& rBitmapEx ) : 202cdf0e10cSrcweir maEx ( rBitmapEx ), 203cdf0e10cSrcweir mpAnimation ( NULL ), 204cdf0e10cSrcweir mpContext ( NULL ), 205cdf0e10cSrcweir mpSwapFile ( NULL ), 206cdf0e10cSrcweir mpGfxLink ( NULL ), 207cdf0e10cSrcweir meType ( !rBitmapEx ? GRAPHIC_NONE : GRAPHIC_BITMAP ), 208cdf0e10cSrcweir mnDocFilePos ( 0UL ), 209cdf0e10cSrcweir mnSizeBytes ( 0UL ), 210cdf0e10cSrcweir mnRefCount ( 1UL ), 211cdf0e10cSrcweir mbSwapOut ( sal_False ), 212cdf0e10cSrcweir mbSwapUnderway ( sal_False ) 213cdf0e10cSrcweir { 214cdf0e10cSrcweir } 215cdf0e10cSrcweir 216cdf0e10cSrcweir // ------------------------------------------------------------------------ 217cdf0e10cSrcweir 218*ddde725dSArmin Le Grand ImpGraphic::ImpGraphic(const SvgDataPtr& rSvgDataPtr) 219*ddde725dSArmin Le Grand : mpAnimation( NULL ), 220*ddde725dSArmin Le Grand mpContext( NULL ), 221*ddde725dSArmin Le Grand mpSwapFile( NULL ), 222*ddde725dSArmin Le Grand mpGfxLink( NULL ), 223*ddde725dSArmin Le Grand meType( rSvgDataPtr.get() ? GRAPHIC_BITMAP : GRAPHIC_NONE ), 224*ddde725dSArmin Le Grand mnDocFilePos( 0UL ), 225*ddde725dSArmin Le Grand mnSizeBytes( 0UL ), 226*ddde725dSArmin Le Grand mnRefCount( 1UL ), 227*ddde725dSArmin Le Grand mbSwapOut( sal_False ), 228*ddde725dSArmin Le Grand mbSwapUnderway( sal_False ), 229*ddde725dSArmin Le Grand maSvgData(rSvgDataPtr) 230*ddde725dSArmin Le Grand { 231*ddde725dSArmin Le Grand } 232*ddde725dSArmin Le Grand 233*ddde725dSArmin Le Grand // ------------------------------------------------------------------------ 234*ddde725dSArmin Le Grand 235cdf0e10cSrcweir ImpGraphic::ImpGraphic( const Animation& rAnimation ) : 236cdf0e10cSrcweir maEx ( rAnimation.GetBitmapEx() ), 237cdf0e10cSrcweir mpAnimation ( new Animation( rAnimation ) ), 238cdf0e10cSrcweir mpContext ( NULL ), 239cdf0e10cSrcweir mpSwapFile ( NULL ), 240cdf0e10cSrcweir mpGfxLink ( NULL ), 241cdf0e10cSrcweir meType ( GRAPHIC_BITMAP ), 242cdf0e10cSrcweir mnDocFilePos ( 0UL ), 243cdf0e10cSrcweir mnSizeBytes ( 0UL ), 244cdf0e10cSrcweir mnRefCount ( 1UL ), 245cdf0e10cSrcweir mbSwapOut ( sal_False ), 246cdf0e10cSrcweir mbSwapUnderway ( sal_False ) 247cdf0e10cSrcweir { 248cdf0e10cSrcweir } 249cdf0e10cSrcweir 250cdf0e10cSrcweir // ------------------------------------------------------------------------ 251cdf0e10cSrcweir 252cdf0e10cSrcweir ImpGraphic::ImpGraphic( const GDIMetaFile& rMtf ) : 253cdf0e10cSrcweir maMetaFile ( rMtf ), 254cdf0e10cSrcweir mpAnimation ( NULL ), 255cdf0e10cSrcweir mpContext ( NULL ), 256cdf0e10cSrcweir mpSwapFile ( NULL ), 257cdf0e10cSrcweir mpGfxLink ( NULL ), 258cdf0e10cSrcweir meType ( GRAPHIC_GDIMETAFILE ), 259cdf0e10cSrcweir mnDocFilePos ( 0UL ), 260cdf0e10cSrcweir mnSizeBytes ( 0UL ), 261cdf0e10cSrcweir mnRefCount ( 1UL ), 262cdf0e10cSrcweir mbSwapOut ( sal_False ), 263cdf0e10cSrcweir mbSwapUnderway ( sal_False ) 264cdf0e10cSrcweir { 265cdf0e10cSrcweir } 266cdf0e10cSrcweir 267cdf0e10cSrcweir // ------------------------------------------------------------------------ 268cdf0e10cSrcweir 269cdf0e10cSrcweir ImpGraphic::~ImpGraphic() 270cdf0e10cSrcweir { 271cdf0e10cSrcweir ImplClear(); 272cdf0e10cSrcweir 273cdf0e10cSrcweir if( (sal_uLong) mpContext > 1UL ) 274cdf0e10cSrcweir delete mpContext; 275cdf0e10cSrcweir } 276cdf0e10cSrcweir 277cdf0e10cSrcweir // ------------------------------------------------------------------------ 278cdf0e10cSrcweir 279cdf0e10cSrcweir ImpGraphic& ImpGraphic::operator=( const ImpGraphic& rImpGraphic ) 280cdf0e10cSrcweir { 281cdf0e10cSrcweir if( &rImpGraphic != this ) 282cdf0e10cSrcweir { 283cdf0e10cSrcweir if( !mbSwapUnderway ) 284cdf0e10cSrcweir ImplClear(); 285cdf0e10cSrcweir 286cdf0e10cSrcweir maMetaFile = rImpGraphic.maMetaFile; 287cdf0e10cSrcweir meType = rImpGraphic.meType; 288cdf0e10cSrcweir mnSizeBytes = rImpGraphic.mnSizeBytes; 289cdf0e10cSrcweir 290cdf0e10cSrcweir delete mpAnimation; 291cdf0e10cSrcweir 292cdf0e10cSrcweir if ( rImpGraphic.mpAnimation ) 293cdf0e10cSrcweir { 294cdf0e10cSrcweir mpAnimation = new Animation( *rImpGraphic.mpAnimation ); 295cdf0e10cSrcweir maEx = mpAnimation->GetBitmapEx(); 296cdf0e10cSrcweir } 297cdf0e10cSrcweir else 298cdf0e10cSrcweir { 299cdf0e10cSrcweir mpAnimation = NULL; 300cdf0e10cSrcweir maEx = rImpGraphic.maEx; 301cdf0e10cSrcweir } 302cdf0e10cSrcweir 303cdf0e10cSrcweir if( !mbSwapUnderway ) 304cdf0e10cSrcweir { 305cdf0e10cSrcweir maDocFileURLStr = rImpGraphic.maDocFileURLStr; 306cdf0e10cSrcweir mnDocFilePos = rImpGraphic.mnDocFilePos; 307cdf0e10cSrcweir mbSwapOut = rImpGraphic.mbSwapOut; 308cdf0e10cSrcweir mpSwapFile = rImpGraphic.mpSwapFile; 309cdf0e10cSrcweir 310cdf0e10cSrcweir if( mpSwapFile ) 311cdf0e10cSrcweir mpSwapFile->nRefCount++; 312cdf0e10cSrcweir } 313cdf0e10cSrcweir 314cdf0e10cSrcweir delete mpGfxLink; 315cdf0e10cSrcweir 316cdf0e10cSrcweir if( rImpGraphic.mpGfxLink ) 317cdf0e10cSrcweir mpGfxLink = new GfxLink( *rImpGraphic.mpGfxLink ); 318cdf0e10cSrcweir else 319cdf0e10cSrcweir mpGfxLink = NULL; 320*ddde725dSArmin Le Grand 321*ddde725dSArmin Le Grand maSvgData = rImpGraphic.maSvgData; 322cdf0e10cSrcweir } 323cdf0e10cSrcweir 324cdf0e10cSrcweir return *this; 325cdf0e10cSrcweir } 326cdf0e10cSrcweir 327cdf0e10cSrcweir // ------------------------------------------------------------------------ 328cdf0e10cSrcweir 329cdf0e10cSrcweir sal_Bool ImpGraphic::operator==( const ImpGraphic& rImpGraphic ) const 330cdf0e10cSrcweir { 331cdf0e10cSrcweir sal_Bool bRet = sal_False; 332cdf0e10cSrcweir 333cdf0e10cSrcweir if( this == &rImpGraphic ) 334cdf0e10cSrcweir bRet = sal_True; 335cdf0e10cSrcweir else if( !ImplIsSwapOut() && ( rImpGraphic.meType == meType ) ) 336cdf0e10cSrcweir { 337cdf0e10cSrcweir switch( meType ) 338cdf0e10cSrcweir { 339cdf0e10cSrcweir case( GRAPHIC_NONE ): 340cdf0e10cSrcweir bRet = sal_True; 341cdf0e10cSrcweir break; 342cdf0e10cSrcweir 343cdf0e10cSrcweir case( GRAPHIC_GDIMETAFILE ): 344cdf0e10cSrcweir { 345cdf0e10cSrcweir if( rImpGraphic.maMetaFile == maMetaFile ) 346cdf0e10cSrcweir bRet = sal_True; 347cdf0e10cSrcweir } 348cdf0e10cSrcweir break; 349cdf0e10cSrcweir 350cdf0e10cSrcweir case( GRAPHIC_BITMAP ): 351cdf0e10cSrcweir { 352*ddde725dSArmin Le Grand if(maSvgData.get()) 353*ddde725dSArmin Le Grand { 354*ddde725dSArmin Le Grand if(maSvgData == rImpGraphic.maSvgData) 355*ddde725dSArmin Le Grand { 356*ddde725dSArmin Le Grand bRet = sal_True; 357*ddde725dSArmin Le Grand } 358*ddde725dSArmin Le Grand else if(rImpGraphic.maSvgData) 359*ddde725dSArmin Le Grand { 360*ddde725dSArmin Le Grand if(maSvgData->getSvgDataArrayLength() == rImpGraphic.maSvgData->getSvgDataArrayLength()) 361*ddde725dSArmin Le Grand { 362*ddde725dSArmin Le Grand if(0 == memcmp( 363*ddde725dSArmin Le Grand maSvgData->getSvgDataArray().get(), 364*ddde725dSArmin Le Grand rImpGraphic.maSvgData->getSvgDataArray().get(), 365*ddde725dSArmin Le Grand maSvgData->getSvgDataArrayLength())) 366*ddde725dSArmin Le Grand { 367*ddde725dSArmin Le Grand bRet = sal_True; 368*ddde725dSArmin Le Grand } 369*ddde725dSArmin Le Grand } 370*ddde725dSArmin Le Grand } 371*ddde725dSArmin Le Grand } 372*ddde725dSArmin Le Grand else if( mpAnimation ) 373cdf0e10cSrcweir { 374cdf0e10cSrcweir if( rImpGraphic.mpAnimation && ( *rImpGraphic.mpAnimation == *mpAnimation ) ) 375cdf0e10cSrcweir bRet = sal_True; 376cdf0e10cSrcweir } 377cdf0e10cSrcweir else if( !rImpGraphic.mpAnimation && ( rImpGraphic.maEx == maEx ) ) 378*ddde725dSArmin Le Grand { 379cdf0e10cSrcweir bRet = sal_True; 380cdf0e10cSrcweir } 381*ddde725dSArmin Le Grand } 382cdf0e10cSrcweir break; 383cdf0e10cSrcweir 384cdf0e10cSrcweir default: 385cdf0e10cSrcweir break; 386cdf0e10cSrcweir } 387cdf0e10cSrcweir } 388cdf0e10cSrcweir 389cdf0e10cSrcweir return bRet; 390cdf0e10cSrcweir } 391cdf0e10cSrcweir 392cdf0e10cSrcweir // ------------------------------------------------------------------------ 393cdf0e10cSrcweir 394cdf0e10cSrcweir void ImpGraphic::ImplClearGraphics( sal_Bool bCreateSwapInfo ) 395cdf0e10cSrcweir { 396cdf0e10cSrcweir if( bCreateSwapInfo && !ImplIsSwapOut() ) 397cdf0e10cSrcweir { 398cdf0e10cSrcweir maSwapInfo.maPrefMapMode = ImplGetPrefMapMode(); 399cdf0e10cSrcweir maSwapInfo.maPrefSize = ImplGetPrefSize(); 400cdf0e10cSrcweir } 401cdf0e10cSrcweir 402cdf0e10cSrcweir maEx.Clear(); 403cdf0e10cSrcweir maMetaFile.Clear(); 404cdf0e10cSrcweir 405cdf0e10cSrcweir if( mpAnimation ) 406cdf0e10cSrcweir { 407cdf0e10cSrcweir mpAnimation->Clear(); 408cdf0e10cSrcweir delete mpAnimation; 409cdf0e10cSrcweir mpAnimation = NULL; 410cdf0e10cSrcweir } 411cdf0e10cSrcweir 412cdf0e10cSrcweir if( mpGfxLink ) 413cdf0e10cSrcweir { 414cdf0e10cSrcweir delete mpGfxLink; 415cdf0e10cSrcweir mpGfxLink = NULL; 416cdf0e10cSrcweir } 417*ddde725dSArmin Le Grand 418*ddde725dSArmin Le Grand maSvgData.reset(); 419cdf0e10cSrcweir } 420cdf0e10cSrcweir 421cdf0e10cSrcweir // ------------------------------------------------------------------------ 422cdf0e10cSrcweir 423cdf0e10cSrcweir void ImpGraphic::ImplClear() 424cdf0e10cSrcweir { 425cdf0e10cSrcweir if( mpSwapFile ) 426cdf0e10cSrcweir { 427cdf0e10cSrcweir if( mpSwapFile->nRefCount > 1 ) 428cdf0e10cSrcweir mpSwapFile->nRefCount--; 429cdf0e10cSrcweir else 430cdf0e10cSrcweir { 431cdf0e10cSrcweir try 432cdf0e10cSrcweir { 433cdf0e10cSrcweir ::ucbhelper::Content aCnt( mpSwapFile->aSwapURL.GetMainURL( INetURLObject::NO_DECODE ), 434cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >() ); 435cdf0e10cSrcweir 436cdf0e10cSrcweir aCnt.executeCommand( ::rtl::OUString::createFromAscii( "delete" ), 437cdf0e10cSrcweir ::com::sun::star::uno::makeAny( sal_Bool( sal_True ) ) ); 438cdf0e10cSrcweir } 439cdf0e10cSrcweir catch( const ::com::sun::star::ucb::ContentCreationException& ) 440cdf0e10cSrcweir { 441cdf0e10cSrcweir } 442cdf0e10cSrcweir catch( const ::com::sun::star::uno::RuntimeException& ) 443cdf0e10cSrcweir { 444cdf0e10cSrcweir } 445cdf0e10cSrcweir catch( const ::com::sun::star::ucb::CommandAbortedException& ) 446cdf0e10cSrcweir { 447cdf0e10cSrcweir } 448cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 449cdf0e10cSrcweir { 450cdf0e10cSrcweir } 451cdf0e10cSrcweir 452cdf0e10cSrcweir delete mpSwapFile; 453cdf0e10cSrcweir } 454cdf0e10cSrcweir 455cdf0e10cSrcweir mpSwapFile = NULL; 456cdf0e10cSrcweir } 457cdf0e10cSrcweir 458cdf0e10cSrcweir mbSwapOut = sal_False; 459cdf0e10cSrcweir mnDocFilePos = 0UL; 460cdf0e10cSrcweir maDocFileURLStr.Erase(); 461cdf0e10cSrcweir 462cdf0e10cSrcweir // cleanup 463cdf0e10cSrcweir ImplClearGraphics( sal_False ); 464cdf0e10cSrcweir meType = GRAPHIC_NONE; 465cdf0e10cSrcweir mnSizeBytes = 0; 466cdf0e10cSrcweir } 467cdf0e10cSrcweir 468cdf0e10cSrcweir // ------------------------------------------------------------------------ 469cdf0e10cSrcweir 470cdf0e10cSrcweir GraphicType ImpGraphic::ImplGetType() const 471cdf0e10cSrcweir { 472cdf0e10cSrcweir return meType; 473cdf0e10cSrcweir } 474cdf0e10cSrcweir 475cdf0e10cSrcweir // ------------------------------------------------------------------------ 476cdf0e10cSrcweir 477cdf0e10cSrcweir void ImpGraphic::ImplSetDefaultType() 478cdf0e10cSrcweir { 479cdf0e10cSrcweir ImplClear(); 480cdf0e10cSrcweir meType = GRAPHIC_DEFAULT; 481cdf0e10cSrcweir } 482cdf0e10cSrcweir 483cdf0e10cSrcweir // ------------------------------------------------------------------------ 484cdf0e10cSrcweir 485cdf0e10cSrcweir sal_Bool ImpGraphic::ImplIsSupportedGraphic() const 486cdf0e10cSrcweir { 487cdf0e10cSrcweir return( meType != GRAPHIC_NONE ); 488cdf0e10cSrcweir } 489cdf0e10cSrcweir 490cdf0e10cSrcweir // ------------------------------------------------------------------------ 491cdf0e10cSrcweir 492cdf0e10cSrcweir sal_Bool ImpGraphic::ImplIsTransparent() const 493cdf0e10cSrcweir { 494*ddde725dSArmin Le Grand sal_Bool bRet(sal_True); 495cdf0e10cSrcweir 496*ddde725dSArmin Le Grand if( meType == GRAPHIC_BITMAP && !maSvgData.get()) 497*ddde725dSArmin Le Grand { 498cdf0e10cSrcweir bRet = ( mpAnimation ? mpAnimation->IsTransparent() : maEx.IsTransparent() ); 499*ddde725dSArmin Le Grand } 500cdf0e10cSrcweir 501cdf0e10cSrcweir return bRet; 502cdf0e10cSrcweir } 503cdf0e10cSrcweir 504cdf0e10cSrcweir // ------------------------------------------------------------------------ 505cdf0e10cSrcweir 506cdf0e10cSrcweir sal_Bool ImpGraphic::ImplIsAlpha() const 507cdf0e10cSrcweir { 508*ddde725dSArmin Le Grand sal_Bool bRet(sal_False); 509cdf0e10cSrcweir 510*ddde725dSArmin Le Grand if(maSvgData.get()) 511*ddde725dSArmin Le Grand { 512*ddde725dSArmin Le Grand bRet = sal_True; 513*ddde725dSArmin Le Grand } 514*ddde725dSArmin Le Grand else if( meType == GRAPHIC_BITMAP ) 515*ddde725dSArmin Le Grand { 516cdf0e10cSrcweir bRet = ( NULL == mpAnimation ) && maEx.IsAlpha(); 517*ddde725dSArmin Le Grand } 518cdf0e10cSrcweir 519cdf0e10cSrcweir return bRet; 520cdf0e10cSrcweir } 521cdf0e10cSrcweir 522cdf0e10cSrcweir // ------------------------------------------------------------------------ 523cdf0e10cSrcweir 524cdf0e10cSrcweir sal_Bool ImpGraphic::ImplIsAnimated() const 525cdf0e10cSrcweir { 526cdf0e10cSrcweir return( mpAnimation != NULL ); 527cdf0e10cSrcweir } 528cdf0e10cSrcweir 529cdf0e10cSrcweir // ------------------------------------------------------------------------ 530cdf0e10cSrcweir 531cdf0e10cSrcweir sal_Bool ImpGraphic::ImplIsEPS() const 532cdf0e10cSrcweir { 533cdf0e10cSrcweir return( ( meType == GRAPHIC_GDIMETAFILE ) && 534cdf0e10cSrcweir ( maMetaFile.GetActionCount() > 0 ) && 535cdf0e10cSrcweir ( maMetaFile.GetAction( 0 )->GetType() == META_EPS_ACTION ) ); 536cdf0e10cSrcweir } 537cdf0e10cSrcweir 538cdf0e10cSrcweir // ------------------------------------------------------------------------ 539cdf0e10cSrcweir 540cdf0e10cSrcweir Bitmap ImpGraphic::ImplGetBitmap(const GraphicConversionParameters& rParameters) const 541cdf0e10cSrcweir { 542cdf0e10cSrcweir Bitmap aRetBmp; 543cdf0e10cSrcweir 544cdf0e10cSrcweir if( meType == GRAPHIC_BITMAP ) 545cdf0e10cSrcweir { 546*ddde725dSArmin Le Grand if(maSvgData.get() && maEx.IsEmpty()) 547*ddde725dSArmin Le Grand { 548*ddde725dSArmin Le Grand // use maEx as local buffer for rendered svg 549*ddde725dSArmin Le Grand const_cast< ImpGraphic* >(this)->maEx = maSvgData->getReplacement(); 550*ddde725dSArmin Le Grand } 551*ddde725dSArmin Le Grand 552cdf0e10cSrcweir const BitmapEx& rRetBmpEx = ( mpAnimation ? mpAnimation->GetBitmapEx() : maEx ); 553cdf0e10cSrcweir const Color aReplaceColor( COL_WHITE ); 554cdf0e10cSrcweir 555cdf0e10cSrcweir aRetBmp = rRetBmpEx.GetBitmap( &aReplaceColor ); 556cdf0e10cSrcweir 557cdf0e10cSrcweir if(rParameters.getSizePixel().Width() || rParameters.getSizePixel().Height()) 558cdf0e10cSrcweir aRetBmp.Scale(rParameters.getSizePixel()); 559cdf0e10cSrcweir } 560cdf0e10cSrcweir else if( ( meType != GRAPHIC_DEFAULT ) && ImplIsSupportedGraphic() ) 561cdf0e10cSrcweir { 562cdf0e10cSrcweir // use corner points of graphic to determine the pixel 563cdf0e10cSrcweir // extent of the graphic (rounding errors are possible else) 564cdf0e10cSrcweir VirtualDevice aVDev; 565cdf0e10cSrcweir const Point aNullPt; 566cdf0e10cSrcweir const Point aTLPix( aVDev.LogicToPixel( aNullPt, maMetaFile.GetPrefMapMode() ) ); 567cdf0e10cSrcweir const Point aBRPix( aVDev.LogicToPixel( Point( maMetaFile.GetPrefSize().Width() - 1, maMetaFile.GetPrefSize().Height() - 1 ), maMetaFile.GetPrefMapMode() ) ); 568cdf0e10cSrcweir Size aDrawSize( aVDev.LogicToPixel( maMetaFile.GetPrefSize(), maMetaFile.GetPrefMapMode() ) ); 569cdf0e10cSrcweir Size aSizePix( labs( aBRPix.X() - aTLPix.X() ) + 1, labs( aBRPix.Y() - aTLPix.Y() ) + 1 ); 570cdf0e10cSrcweir 571cdf0e10cSrcweir if(rParameters.getSizePixel().Width() && rParameters.getSizePixel().Height()) 572cdf0e10cSrcweir { 573cdf0e10cSrcweir aDrawSize.Width() = FRound((double)rParameters.getSizePixel().Width() * 574cdf0e10cSrcweir (double)aDrawSize.Width() / (double)aSizePix.Width()); 575cdf0e10cSrcweir aDrawSize.Height() = FRound((double)rParameters.getSizePixel().Height() * 576cdf0e10cSrcweir (double)aDrawSize.Height() / (double)aSizePix.Height()); 577cdf0e10cSrcweir 578cdf0e10cSrcweir aSizePix = rParameters.getSizePixel(); 579cdf0e10cSrcweir } 580cdf0e10cSrcweir 581cdf0e10cSrcweir if( aSizePix.Width() && aSizePix.Height() && !rParameters.getUnlimitedSize() 582cdf0e10cSrcweir && (aSizePix.Width() > GRAPHIC_MTFTOBMP_MAXEXT || aSizePix.Height() > GRAPHIC_MTFTOBMP_MAXEXT)) 583cdf0e10cSrcweir { 584cdf0e10cSrcweir const Size aOldSizePix( aSizePix ); 585cdf0e10cSrcweir double fWH = (double) aSizePix.Width() / aSizePix.Height(); 586cdf0e10cSrcweir 587cdf0e10cSrcweir if( fWH <= 1.0 ) 588cdf0e10cSrcweir aSizePix.Width() = FRound( GRAPHIC_MTFTOBMP_MAXEXT * fWH ), aSizePix.Height() = GRAPHIC_MTFTOBMP_MAXEXT; 589cdf0e10cSrcweir else 590cdf0e10cSrcweir aSizePix.Width() = GRAPHIC_MTFTOBMP_MAXEXT, aSizePix.Height() = FRound( GRAPHIC_MTFTOBMP_MAXEXT / fWH ); 591cdf0e10cSrcweir 592cdf0e10cSrcweir aDrawSize.Width() = FRound( ( (double) aDrawSize.Width() * aSizePix.Width() ) / aOldSizePix.Width() ); 593cdf0e10cSrcweir aDrawSize.Height() = FRound( ( (double) aDrawSize.Height() * aSizePix.Height() ) / aOldSizePix.Height() ); 594cdf0e10cSrcweir } 595cdf0e10cSrcweir 596cdf0e10cSrcweir if( aVDev.SetOutputSizePixel( aSizePix ) ) 597cdf0e10cSrcweir { 598cdf0e10cSrcweir if(rParameters.getAntiAliase()) 599cdf0e10cSrcweir { 600cdf0e10cSrcweir aVDev.SetAntialiasing(aVDev.GetAntialiasing() | ANTIALIASING_ENABLE_B2DDRAW); 601cdf0e10cSrcweir } 602cdf0e10cSrcweir 603cdf0e10cSrcweir if(rParameters.getSnapHorVerLines()) 604cdf0e10cSrcweir { 605cdf0e10cSrcweir aVDev.SetAntialiasing(aVDev.GetAntialiasing() | ANTIALIASING_PIXELSNAPHAIRLINE); 606cdf0e10cSrcweir } 607cdf0e10cSrcweir 608cdf0e10cSrcweir ImplDraw( &aVDev, aNullPt, aDrawSize ); 609cdf0e10cSrcweir aRetBmp = aVDev.GetBitmap( aNullPt, aVDev.GetOutputSizePixel() ); 610cdf0e10cSrcweir } 611cdf0e10cSrcweir } 612cdf0e10cSrcweir 613cdf0e10cSrcweir if( !!aRetBmp ) 614cdf0e10cSrcweir { 615cdf0e10cSrcweir aRetBmp.SetPrefMapMode( ImplGetPrefMapMode() ); 616cdf0e10cSrcweir aRetBmp.SetPrefSize( ImplGetPrefSize() ); 617cdf0e10cSrcweir } 618cdf0e10cSrcweir 619cdf0e10cSrcweir return aRetBmp; 620cdf0e10cSrcweir } 621cdf0e10cSrcweir 622cdf0e10cSrcweir // ------------------------------------------------------------------------ 623cdf0e10cSrcweir 624cdf0e10cSrcweir BitmapEx ImpGraphic::ImplGetBitmapEx(const GraphicConversionParameters& rParameters) const 625cdf0e10cSrcweir { 626cdf0e10cSrcweir BitmapEx aRetBmpEx; 627cdf0e10cSrcweir 628cdf0e10cSrcweir if( meType == GRAPHIC_BITMAP ) 629cdf0e10cSrcweir { 630*ddde725dSArmin Le Grand if(maSvgData.get() && maEx.IsEmpty()) 631*ddde725dSArmin Le Grand { 632*ddde725dSArmin Le Grand // use maEx as local buffer for rendered svg 633*ddde725dSArmin Le Grand const_cast< ImpGraphic* >(this)->maEx = maSvgData->getReplacement(); 634*ddde725dSArmin Le Grand } 635*ddde725dSArmin Le Grand 636cdf0e10cSrcweir aRetBmpEx = ( mpAnimation ? mpAnimation->GetBitmapEx() : maEx ); 637cdf0e10cSrcweir 638cdf0e10cSrcweir if(rParameters.getSizePixel().Width() || rParameters.getSizePixel().Height()) 639cdf0e10cSrcweir aRetBmpEx.Scale(rParameters.getSizePixel()); 640cdf0e10cSrcweir } 641cdf0e10cSrcweir else if( ( meType != GRAPHIC_DEFAULT ) && ImplIsSupportedGraphic() ) 642cdf0e10cSrcweir { 643cdf0e10cSrcweir const ImpGraphic aMonoMask( maMetaFile.GetMonochromeMtf( COL_BLACK ) ); 644cdf0e10cSrcweir aRetBmpEx = BitmapEx(ImplGetBitmap(rParameters), aMonoMask.ImplGetBitmap(rParameters)); 645cdf0e10cSrcweir } 646cdf0e10cSrcweir 647cdf0e10cSrcweir return aRetBmpEx; 648cdf0e10cSrcweir } 649cdf0e10cSrcweir 650cdf0e10cSrcweir // ------------------------------------------------------------------------ 651cdf0e10cSrcweir 652cdf0e10cSrcweir Animation ImpGraphic::ImplGetAnimation() const 653cdf0e10cSrcweir { 654cdf0e10cSrcweir Animation aAnimation; 655cdf0e10cSrcweir 656cdf0e10cSrcweir if( mpAnimation ) 657cdf0e10cSrcweir aAnimation = *mpAnimation; 658cdf0e10cSrcweir 659cdf0e10cSrcweir return aAnimation; 660cdf0e10cSrcweir } 661cdf0e10cSrcweir 662cdf0e10cSrcweir // ------------------------------------------------------------------------ 663cdf0e10cSrcweir 664cdf0e10cSrcweir const GDIMetaFile& ImpGraphic::ImplGetGDIMetaFile() const 665cdf0e10cSrcweir { 666cdf0e10cSrcweir return maMetaFile; 667cdf0e10cSrcweir } 668cdf0e10cSrcweir 669cdf0e10cSrcweir // ------------------------------------------------------------------------ 670cdf0e10cSrcweir 671cdf0e10cSrcweir Size ImpGraphic::ImplGetPrefSize() const 672cdf0e10cSrcweir { 673cdf0e10cSrcweir Size aSize; 674cdf0e10cSrcweir 675cdf0e10cSrcweir if( ImplIsSwapOut() ) 676cdf0e10cSrcweir aSize = maSwapInfo.maPrefSize; 677cdf0e10cSrcweir else 678cdf0e10cSrcweir { 679cdf0e10cSrcweir switch( meType ) 680cdf0e10cSrcweir { 681cdf0e10cSrcweir case( GRAPHIC_NONE ): 682cdf0e10cSrcweir case( GRAPHIC_DEFAULT ): 683cdf0e10cSrcweir break; 684cdf0e10cSrcweir 685cdf0e10cSrcweir case( GRAPHIC_BITMAP ): 686cdf0e10cSrcweir { 687*ddde725dSArmin Le Grand if(maSvgData.get() && maEx.IsEmpty()) 688*ddde725dSArmin Le Grand { 689*ddde725dSArmin Le Grand // svg not yet buffered in maEx, return size derived from range 690*ddde725dSArmin Le Grand const basegfx::B2DRange& rRange = maSvgData->getRange(); 691*ddde725dSArmin Le Grand 692*ddde725dSArmin Le Grand aSize = Size(basegfx::fround(rRange.getWidth()), basegfx::fround(rRange.getHeight())); 693*ddde725dSArmin Le Grand } 694*ddde725dSArmin Le Grand else 695*ddde725dSArmin Le Grand { 696cdf0e10cSrcweir aSize = maEx.GetPrefSize(); 697cdf0e10cSrcweir 698cdf0e10cSrcweir if( !aSize.Width() || !aSize.Height() ) 699*ddde725dSArmin Le Grand { 700cdf0e10cSrcweir aSize = maEx.GetSizePixel(); 701cdf0e10cSrcweir } 702*ddde725dSArmin Le Grand } 703*ddde725dSArmin Le Grand } 704cdf0e10cSrcweir break; 705cdf0e10cSrcweir 706cdf0e10cSrcweir default: 707cdf0e10cSrcweir { 708cdf0e10cSrcweir if( ImplIsSupportedGraphic() ) 709cdf0e10cSrcweir aSize = maMetaFile.GetPrefSize(); 710cdf0e10cSrcweir } 711cdf0e10cSrcweir break; 712cdf0e10cSrcweir } 713cdf0e10cSrcweir } 714cdf0e10cSrcweir 715cdf0e10cSrcweir return aSize; 716cdf0e10cSrcweir } 717cdf0e10cSrcweir 718cdf0e10cSrcweir // ------------------------------------------------------------------------ 719cdf0e10cSrcweir 720cdf0e10cSrcweir void ImpGraphic::ImplSetPrefSize( const Size& rPrefSize ) 721cdf0e10cSrcweir { 722cdf0e10cSrcweir switch( meType ) 723cdf0e10cSrcweir { 724cdf0e10cSrcweir case( GRAPHIC_NONE ): 725cdf0e10cSrcweir case( GRAPHIC_DEFAULT ): 726cdf0e10cSrcweir break; 727cdf0e10cSrcweir 728cdf0e10cSrcweir case( GRAPHIC_BITMAP ): 729*ddde725dSArmin Le Grand { 730cdf0e10cSrcweir // #108077# Push through pref size to animation object, 731cdf0e10cSrcweir // will be lost on copy otherwise 732*ddde725dSArmin Le Grand if(maSvgData.get()) 733*ddde725dSArmin Le Grand { 734*ddde725dSArmin Le Grand // ignore for Svg. If this is really used (except the grfcache) 735*ddde725dSArmin Le Grand // it can be extended by using maEx as buffer for maSvgData->getReplacement() 736*ddde725dSArmin Le Grand } 737*ddde725dSArmin Le Grand else 738*ddde725dSArmin Le Grand { 739cdf0e10cSrcweir if( ImplIsAnimated() ) 740*ddde725dSArmin Le Grand { 741cdf0e10cSrcweir const_cast< BitmapEx& >(mpAnimation->GetBitmapEx()).SetPrefSize( rPrefSize ); 742*ddde725dSArmin Le Grand } 743cdf0e10cSrcweir 744cdf0e10cSrcweir maEx.SetPrefSize( rPrefSize ); 745*ddde725dSArmin Le Grand } 746*ddde725dSArmin Le Grand } 747cdf0e10cSrcweir break; 748cdf0e10cSrcweir 749cdf0e10cSrcweir default: 750cdf0e10cSrcweir { 751cdf0e10cSrcweir if( ImplIsSupportedGraphic() ) 752cdf0e10cSrcweir maMetaFile.SetPrefSize( rPrefSize ); 753cdf0e10cSrcweir } 754cdf0e10cSrcweir break; 755cdf0e10cSrcweir } 756cdf0e10cSrcweir } 757cdf0e10cSrcweir 758cdf0e10cSrcweir // ------------------------------------------------------------------------ 759cdf0e10cSrcweir 760cdf0e10cSrcweir MapMode ImpGraphic::ImplGetPrefMapMode() const 761cdf0e10cSrcweir { 762cdf0e10cSrcweir MapMode aMapMode; 763cdf0e10cSrcweir 764cdf0e10cSrcweir if( ImplIsSwapOut() ) 765cdf0e10cSrcweir aMapMode = maSwapInfo.maPrefMapMode; 766cdf0e10cSrcweir else 767cdf0e10cSrcweir { 768cdf0e10cSrcweir switch( meType ) 769cdf0e10cSrcweir { 770cdf0e10cSrcweir case( GRAPHIC_NONE ): 771cdf0e10cSrcweir case( GRAPHIC_DEFAULT ): 772cdf0e10cSrcweir break; 773cdf0e10cSrcweir 774cdf0e10cSrcweir case( GRAPHIC_BITMAP ): 775cdf0e10cSrcweir { 776*ddde725dSArmin Le Grand if(maSvgData.get() && maEx.IsEmpty()) 777*ddde725dSArmin Le Grand { 778*ddde725dSArmin Le Grand // svg not yet buffered in maEx, return default PrefMapMode 779*ddde725dSArmin Le Grand aMapMode = MapMode(MAP_100TH_MM); 780*ddde725dSArmin Le Grand } 781*ddde725dSArmin Le Grand else 782*ddde725dSArmin Le Grand { 783cdf0e10cSrcweir const Size aSize( maEx.GetPrefSize() ); 784cdf0e10cSrcweir 785cdf0e10cSrcweir if ( aSize.Width() && aSize.Height() ) 786cdf0e10cSrcweir aMapMode = maEx.GetPrefMapMode(); 787cdf0e10cSrcweir } 788*ddde725dSArmin Le Grand } 789cdf0e10cSrcweir break; 790cdf0e10cSrcweir 791cdf0e10cSrcweir default: 792cdf0e10cSrcweir { 793cdf0e10cSrcweir if( ImplIsSupportedGraphic() ) 794cdf0e10cSrcweir return maMetaFile.GetPrefMapMode(); 795cdf0e10cSrcweir } 796cdf0e10cSrcweir break; 797cdf0e10cSrcweir } 798cdf0e10cSrcweir } 799cdf0e10cSrcweir 800cdf0e10cSrcweir return aMapMode; 801cdf0e10cSrcweir } 802cdf0e10cSrcweir 803cdf0e10cSrcweir // ------------------------------------------------------------------------ 804cdf0e10cSrcweir 805cdf0e10cSrcweir void ImpGraphic::ImplSetPrefMapMode( const MapMode& rPrefMapMode ) 806cdf0e10cSrcweir { 807cdf0e10cSrcweir switch( meType ) 808cdf0e10cSrcweir { 809cdf0e10cSrcweir case( GRAPHIC_NONE ): 810cdf0e10cSrcweir case( GRAPHIC_DEFAULT ): 811cdf0e10cSrcweir break; 812cdf0e10cSrcweir 813cdf0e10cSrcweir case( GRAPHIC_BITMAP ): 814*ddde725dSArmin Le Grand { 815*ddde725dSArmin Le Grand if(maSvgData.get()) 816*ddde725dSArmin Le Grand { 817*ddde725dSArmin Le Grand // ignore for Svg. If this is really used (except the grfcache) 818*ddde725dSArmin Le Grand // it can be extended by using maEx as buffer for maSvgData->getReplacement() 819*ddde725dSArmin Le Grand } 820*ddde725dSArmin Le Grand else 821*ddde725dSArmin Le Grand { 822cdf0e10cSrcweir // #108077# Push through pref mapmode to animation object, 823cdf0e10cSrcweir // will be lost on copy otherwise 824cdf0e10cSrcweir if( ImplIsAnimated() ) 825*ddde725dSArmin Le Grand { 826cdf0e10cSrcweir const_cast< BitmapEx& >(mpAnimation->GetBitmapEx()).SetPrefMapMode( rPrefMapMode ); 827*ddde725dSArmin Le Grand } 828cdf0e10cSrcweir 829cdf0e10cSrcweir maEx.SetPrefMapMode( rPrefMapMode ); 830*ddde725dSArmin Le Grand } 831*ddde725dSArmin Le Grand } 832cdf0e10cSrcweir break; 833cdf0e10cSrcweir 834cdf0e10cSrcweir default: 835cdf0e10cSrcweir { 836cdf0e10cSrcweir if( ImplIsSupportedGraphic() ) 837cdf0e10cSrcweir maMetaFile.SetPrefMapMode( rPrefMapMode ); 838cdf0e10cSrcweir } 839cdf0e10cSrcweir break; 840cdf0e10cSrcweir } 841cdf0e10cSrcweir } 842cdf0e10cSrcweir 843cdf0e10cSrcweir // ------------------------------------------------------------------------ 844cdf0e10cSrcweir 845cdf0e10cSrcweir sal_uLong ImpGraphic::ImplGetSizeBytes() const 846cdf0e10cSrcweir { 847cdf0e10cSrcweir if( 0 == mnSizeBytes ) 848cdf0e10cSrcweir { 849cdf0e10cSrcweir if( meType == GRAPHIC_BITMAP ) 850cdf0e10cSrcweir { 851*ddde725dSArmin Le Grand if(maSvgData.get()) 852*ddde725dSArmin Le Grand { 853*ddde725dSArmin Le Grand mnSizeBytes = maSvgData->getSvgDataArrayLength(); 854*ddde725dSArmin Le Grand } 855*ddde725dSArmin Le Grand else 856*ddde725dSArmin Le Grand { 857cdf0e10cSrcweir mnSizeBytes = mpAnimation ? mpAnimation->GetSizeBytes() : maEx.GetSizeBytes(); 858cdf0e10cSrcweir } 859*ddde725dSArmin Le Grand } 860cdf0e10cSrcweir else if( meType == GRAPHIC_GDIMETAFILE ) 861cdf0e10cSrcweir { 862cdf0e10cSrcweir mnSizeBytes = maMetaFile.GetSizeBytes(); 863cdf0e10cSrcweir } 864cdf0e10cSrcweir } 865cdf0e10cSrcweir 866cdf0e10cSrcweir return( mnSizeBytes ); 867cdf0e10cSrcweir } 868cdf0e10cSrcweir 869cdf0e10cSrcweir // ------------------------------------------------------------------------ 870cdf0e10cSrcweir 871cdf0e10cSrcweir void ImpGraphic::ImplDraw( OutputDevice* pOutDev, const Point& rDestPt ) const 872cdf0e10cSrcweir { 873cdf0e10cSrcweir if( ImplIsSupportedGraphic() && !ImplIsSwapOut() ) 874cdf0e10cSrcweir { 875cdf0e10cSrcweir switch( meType ) 876cdf0e10cSrcweir { 877cdf0e10cSrcweir case( GRAPHIC_DEFAULT ): 878cdf0e10cSrcweir break; 879cdf0e10cSrcweir 880cdf0e10cSrcweir case( GRAPHIC_BITMAP ): 881cdf0e10cSrcweir { 882*ddde725dSArmin Le Grand if(maSvgData.get() && !maEx) 883*ddde725dSArmin Le Grand { 884*ddde725dSArmin Le Grand // use maEx as local buffer for rendered svg 885*ddde725dSArmin Le Grand const_cast< ImpGraphic* >(this)->maEx = maSvgData->getReplacement(); 886*ddde725dSArmin Le Grand } 887*ddde725dSArmin Le Grand 888cdf0e10cSrcweir if ( mpAnimation ) 889*ddde725dSArmin Le Grand { 890cdf0e10cSrcweir mpAnimation->Draw( pOutDev, rDestPt ); 891*ddde725dSArmin Le Grand } 892cdf0e10cSrcweir else 893*ddde725dSArmin Le Grand { 894cdf0e10cSrcweir maEx.Draw( pOutDev, rDestPt ); 895cdf0e10cSrcweir } 896*ddde725dSArmin Le Grand } 897cdf0e10cSrcweir break; 898cdf0e10cSrcweir 899cdf0e10cSrcweir default: 900cdf0e10cSrcweir ImplDraw( pOutDev, rDestPt, maMetaFile.GetPrefSize() ); 901cdf0e10cSrcweir break; 902cdf0e10cSrcweir } 903cdf0e10cSrcweir } 904cdf0e10cSrcweir } 905cdf0e10cSrcweir 906cdf0e10cSrcweir // ------------------------------------------------------------------------ 907cdf0e10cSrcweir 908cdf0e10cSrcweir void ImpGraphic::ImplDraw( OutputDevice* pOutDev, 909cdf0e10cSrcweir const Point& rDestPt, const Size& rDestSize ) const 910cdf0e10cSrcweir { 911cdf0e10cSrcweir if( ImplIsSupportedGraphic() && !ImplIsSwapOut() ) 912cdf0e10cSrcweir { 913cdf0e10cSrcweir switch( meType ) 914cdf0e10cSrcweir { 915cdf0e10cSrcweir case( GRAPHIC_DEFAULT ): 916cdf0e10cSrcweir break; 917cdf0e10cSrcweir 918cdf0e10cSrcweir case( GRAPHIC_BITMAP ): 919cdf0e10cSrcweir { 920*ddde725dSArmin Le Grand if(maSvgData.get() && maEx.IsEmpty()) 921*ddde725dSArmin Le Grand { 922*ddde725dSArmin Le Grand // use maEx as local buffer for rendered svg 923*ddde725dSArmin Le Grand const_cast< ImpGraphic* >(this)->maEx = maSvgData->getReplacement(); 924*ddde725dSArmin Le Grand } 925*ddde725dSArmin Le Grand 926cdf0e10cSrcweir if( mpAnimation ) 927*ddde725dSArmin Le Grand { 928cdf0e10cSrcweir mpAnimation->Draw( pOutDev, rDestPt, rDestSize ); 929*ddde725dSArmin Le Grand } 930cdf0e10cSrcweir else 931*ddde725dSArmin Le Grand { 932cdf0e10cSrcweir maEx.Draw( pOutDev, rDestPt, rDestSize ); 933cdf0e10cSrcweir } 934*ddde725dSArmin Le Grand } 935cdf0e10cSrcweir break; 936cdf0e10cSrcweir 937cdf0e10cSrcweir default: 938cdf0e10cSrcweir { 939cdf0e10cSrcweir ( (ImpGraphic*) this )->maMetaFile.WindStart(); 940cdf0e10cSrcweir ( (ImpGraphic*) this )->maMetaFile.Play( pOutDev, rDestPt, rDestSize ); 941cdf0e10cSrcweir ( (ImpGraphic*) this )->maMetaFile.WindStart(); 942cdf0e10cSrcweir } 943cdf0e10cSrcweir break; 944cdf0e10cSrcweir } 945cdf0e10cSrcweir } 946cdf0e10cSrcweir } 947cdf0e10cSrcweir 948cdf0e10cSrcweir // ------------------------------------------------------------------------ 949cdf0e10cSrcweir 950cdf0e10cSrcweir void ImpGraphic::ImplStartAnimation( OutputDevice* pOutDev, 951cdf0e10cSrcweir const Point& rDestPt, 952cdf0e10cSrcweir long nExtraData, 953cdf0e10cSrcweir OutputDevice* pFirstFrameOutDev ) 954cdf0e10cSrcweir { 955cdf0e10cSrcweir if( ImplIsSupportedGraphic() && !ImplIsSwapOut() && mpAnimation ) 956cdf0e10cSrcweir mpAnimation->Start( pOutDev, rDestPt, nExtraData, pFirstFrameOutDev ); 957cdf0e10cSrcweir } 958cdf0e10cSrcweir 959cdf0e10cSrcweir // ------------------------------------------------------------------------ 960cdf0e10cSrcweir 961cdf0e10cSrcweir void ImpGraphic::ImplStartAnimation( OutputDevice* pOutDev, const Point& rDestPt, 962cdf0e10cSrcweir const Size& rDestSize, long nExtraData, 963cdf0e10cSrcweir OutputDevice* pFirstFrameOutDev ) 964cdf0e10cSrcweir { 965cdf0e10cSrcweir if( ImplIsSupportedGraphic() && !ImplIsSwapOut() && mpAnimation ) 966cdf0e10cSrcweir mpAnimation->Start( pOutDev, rDestPt, rDestSize, nExtraData, pFirstFrameOutDev ); 967cdf0e10cSrcweir } 968cdf0e10cSrcweir 969cdf0e10cSrcweir // ------------------------------------------------------------------------ 970cdf0e10cSrcweir 971cdf0e10cSrcweir void ImpGraphic::ImplStopAnimation( OutputDevice* pOutDev, long nExtraData ) 972cdf0e10cSrcweir { 973cdf0e10cSrcweir if( ImplIsSupportedGraphic() && !ImplIsSwapOut() && mpAnimation ) 974cdf0e10cSrcweir mpAnimation->Stop( pOutDev, nExtraData ); 975cdf0e10cSrcweir } 976cdf0e10cSrcweir 977cdf0e10cSrcweir // ------------------------------------------------------------------------ 978cdf0e10cSrcweir 979cdf0e10cSrcweir void ImpGraphic::ImplSetAnimationNotifyHdl( const Link& rLink ) 980cdf0e10cSrcweir { 981cdf0e10cSrcweir if( mpAnimation ) 982cdf0e10cSrcweir mpAnimation->SetNotifyHdl( rLink ); 983cdf0e10cSrcweir } 984cdf0e10cSrcweir 985cdf0e10cSrcweir // ------------------------------------------------------------------------ 986cdf0e10cSrcweir 987cdf0e10cSrcweir Link ImpGraphic::ImplGetAnimationNotifyHdl() const 988cdf0e10cSrcweir { 989cdf0e10cSrcweir Link aLink; 990cdf0e10cSrcweir 991cdf0e10cSrcweir if( mpAnimation ) 992cdf0e10cSrcweir aLink = mpAnimation->GetNotifyHdl(); 993cdf0e10cSrcweir 994cdf0e10cSrcweir return aLink; 995cdf0e10cSrcweir } 996cdf0e10cSrcweir 997cdf0e10cSrcweir // ------------------------------------------------------------------------ 998cdf0e10cSrcweir 999cdf0e10cSrcweir sal_uLong ImpGraphic::ImplGetAnimationLoopCount() const 1000cdf0e10cSrcweir { 1001cdf0e10cSrcweir return( mpAnimation ? mpAnimation->GetLoopCount() : 0UL ); 1002cdf0e10cSrcweir } 1003cdf0e10cSrcweir 1004cdf0e10cSrcweir // ------------------------------------------------------------------------ 1005cdf0e10cSrcweir 1006cdf0e10cSrcweir void ImpGraphic::ImplResetAnimationLoopCount() 1007cdf0e10cSrcweir { 1008cdf0e10cSrcweir if( mpAnimation ) 1009cdf0e10cSrcweir mpAnimation->ResetLoopCount(); 1010cdf0e10cSrcweir } 1011cdf0e10cSrcweir 1012cdf0e10cSrcweir // ------------------------------------------------------------------------ 1013cdf0e10cSrcweir 1014cdf0e10cSrcweir List* ImpGraphic::ImplGetAnimationInfoList() const 1015cdf0e10cSrcweir { 1016cdf0e10cSrcweir return( mpAnimation ? mpAnimation->GetAInfoList() : NULL ); 1017cdf0e10cSrcweir } 1018cdf0e10cSrcweir 1019cdf0e10cSrcweir // ------------------------------------------------------------------------ 1020cdf0e10cSrcweir 1021cdf0e10cSrcweir GraphicReader* ImpGraphic::ImplGetContext() 1022cdf0e10cSrcweir { 1023cdf0e10cSrcweir return mpContext; 1024cdf0e10cSrcweir } 1025cdf0e10cSrcweir 1026cdf0e10cSrcweir // ------------------------------------------------------------------------ 1027cdf0e10cSrcweir 1028cdf0e10cSrcweir void ImpGraphic::ImplSetContext( GraphicReader* pReader ) 1029cdf0e10cSrcweir { 1030cdf0e10cSrcweir mpContext = pReader; 1031cdf0e10cSrcweir } 1032cdf0e10cSrcweir 1033cdf0e10cSrcweir // ------------------------------------------------------------------------ 1034cdf0e10cSrcweir 1035cdf0e10cSrcweir void ImpGraphic::ImplSetDocFileName( const String& rName, sal_uLong nFilePos ) 1036cdf0e10cSrcweir { 1037cdf0e10cSrcweir const INetURLObject aURL( rName ); 1038cdf0e10cSrcweir 1039cdf0e10cSrcweir DBG_ASSERT( !rName.Len() || ( aURL.GetProtocol() != INET_PROT_NOT_VALID ), "Graphic::SetDocFileName(...): invalid URL" ); 1040cdf0e10cSrcweir 1041cdf0e10cSrcweir maDocFileURLStr = aURL.GetMainURL( INetURLObject::NO_DECODE ); 1042cdf0e10cSrcweir mnDocFilePos = nFilePos; 1043cdf0e10cSrcweir } 1044cdf0e10cSrcweir 1045cdf0e10cSrcweir // ------------------------------------------------------------------------ 1046cdf0e10cSrcweir 1047cdf0e10cSrcweir const String& ImpGraphic::ImplGetDocFileName() const 1048cdf0e10cSrcweir { 1049cdf0e10cSrcweir return maDocFileURLStr; 1050cdf0e10cSrcweir } 1051cdf0e10cSrcweir 1052cdf0e10cSrcweir // ------------------------------------------------------------------------ 1053cdf0e10cSrcweir 1054cdf0e10cSrcweir sal_uLong ImpGraphic::ImplGetDocFilePos() const 1055cdf0e10cSrcweir { 1056cdf0e10cSrcweir return mnDocFilePos; 1057cdf0e10cSrcweir } 1058cdf0e10cSrcweir 1059cdf0e10cSrcweir // ------------------------------------------------------------------------ 1060cdf0e10cSrcweir 1061cdf0e10cSrcweir sal_Bool ImpGraphic::ImplReadEmbedded( SvStream& rIStm, sal_Bool bSwap ) 1062cdf0e10cSrcweir { 1063cdf0e10cSrcweir MapMode aMapMode; 1064cdf0e10cSrcweir Size aSize; 1065cdf0e10cSrcweir const sal_uLong nStartPos = rIStm.Tell(); 1066cdf0e10cSrcweir sal_uInt32 nId; 1067cdf0e10cSrcweir sal_uLong nHeaderLen; 1068cdf0e10cSrcweir long nType; 1069cdf0e10cSrcweir long nLen; 1070cdf0e10cSrcweir const sal_uInt16 nOldFormat = rIStm.GetNumberFormatInt(); 1071cdf0e10cSrcweir sal_Bool bRet = sal_False; 1072cdf0e10cSrcweir 1073cdf0e10cSrcweir if( !mbSwapUnderway ) 1074cdf0e10cSrcweir { 1075cdf0e10cSrcweir const String aTempURLStr( maDocFileURLStr ); 1076cdf0e10cSrcweir const sal_uLong nTempPos = mnDocFilePos; 1077cdf0e10cSrcweir 1078cdf0e10cSrcweir ImplClear(); 1079cdf0e10cSrcweir 1080cdf0e10cSrcweir maDocFileURLStr = aTempURLStr; 1081cdf0e10cSrcweir mnDocFilePos = nTempPos; 1082cdf0e10cSrcweir } 1083cdf0e10cSrcweir 1084cdf0e10cSrcweir rIStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); 1085cdf0e10cSrcweir rIStm >> nId; 1086cdf0e10cSrcweir 1087cdf0e10cSrcweir // check version 1088cdf0e10cSrcweir if( GRAPHIC_FORMAT_50 == nId ) 1089cdf0e10cSrcweir { 1090cdf0e10cSrcweir // read new style header 1091cdf0e10cSrcweir VersionCompat* pCompat = new VersionCompat( rIStm, STREAM_READ ); 1092cdf0e10cSrcweir 1093cdf0e10cSrcweir rIStm >> nType; 1094cdf0e10cSrcweir rIStm >> nLen; 1095cdf0e10cSrcweir rIStm >> aSize; 1096cdf0e10cSrcweir rIStm >> aMapMode; 1097cdf0e10cSrcweir 1098cdf0e10cSrcweir delete pCompat; 1099cdf0e10cSrcweir } 1100cdf0e10cSrcweir else 1101cdf0e10cSrcweir { 1102cdf0e10cSrcweir // read old style header 1103cdf0e10cSrcweir long nWidth, nHeight; 1104cdf0e10cSrcweir long nMapMode, nScaleNumX, nScaleDenomX; 1105cdf0e10cSrcweir long nScaleNumY, nScaleDenomY, nOffsX, nOffsY; 1106cdf0e10cSrcweir 1107cdf0e10cSrcweir rIStm.SeekRel( -4L ); 1108cdf0e10cSrcweir 1109cdf0e10cSrcweir rIStm >> nType >> nLen >> nWidth >> nHeight; 1110cdf0e10cSrcweir rIStm >> nMapMode >> nScaleNumX >> nScaleDenomX >> nScaleNumY; 1111cdf0e10cSrcweir rIStm >> nScaleDenomY >> nOffsX >> nOffsY; 1112cdf0e10cSrcweir 1113cdf0e10cSrcweir // swapped 1114cdf0e10cSrcweir if( nType > 100L ) 1115cdf0e10cSrcweir { 1116cdf0e10cSrcweir nType = SWAPLONG( nType ); 1117cdf0e10cSrcweir nLen = SWAPLONG( nLen ); 1118cdf0e10cSrcweir nWidth = SWAPLONG( nWidth ); 1119cdf0e10cSrcweir nHeight = SWAPLONG( nHeight ); 1120cdf0e10cSrcweir nMapMode = SWAPLONG( nMapMode ); 1121cdf0e10cSrcweir nScaleNumX = SWAPLONG( nScaleNumX ); 1122cdf0e10cSrcweir nScaleDenomX = SWAPLONG( nScaleDenomX ); 1123cdf0e10cSrcweir nScaleNumY = SWAPLONG( nScaleNumY ); 1124cdf0e10cSrcweir nScaleDenomY = SWAPLONG( nScaleDenomY ); 1125cdf0e10cSrcweir nOffsX = SWAPLONG( nOffsX ); 1126cdf0e10cSrcweir nOffsY = SWAPLONG( nOffsY ); 1127cdf0e10cSrcweir } 1128cdf0e10cSrcweir 1129cdf0e10cSrcweir aSize = Size( nWidth, nHeight ); 1130cdf0e10cSrcweir aMapMode = MapMode( (MapUnit) nMapMode, Point( nOffsX, nOffsY ), 1131cdf0e10cSrcweir Fraction( nScaleNumX, nScaleDenomX ), 1132cdf0e10cSrcweir Fraction( nScaleNumY, nScaleDenomY ) ); 1133cdf0e10cSrcweir } 1134cdf0e10cSrcweir 1135cdf0e10cSrcweir nHeaderLen = rIStm.Tell() - nStartPos; 1136cdf0e10cSrcweir meType = (GraphicType) nType; 1137cdf0e10cSrcweir 1138cdf0e10cSrcweir if( meType ) 1139cdf0e10cSrcweir { 1140cdf0e10cSrcweir if( meType == GRAPHIC_BITMAP ) 1141cdf0e10cSrcweir { 1142*ddde725dSArmin Le Grand if(maSvgData.get() && maEx.IsEmpty()) 1143*ddde725dSArmin Le Grand { 1144*ddde725dSArmin Le Grand // use maEx as local buffer for rendered svg 1145*ddde725dSArmin Le Grand maEx = maSvgData->getReplacement(); 1146*ddde725dSArmin Le Grand } 1147*ddde725dSArmin Le Grand 1148cdf0e10cSrcweir maEx.aBitmapSize = aSize; 1149cdf0e10cSrcweir 1150cdf0e10cSrcweir if( aMapMode != MapMode() ) 1151cdf0e10cSrcweir { 1152cdf0e10cSrcweir maEx.SetPrefMapMode( aMapMode ); 1153cdf0e10cSrcweir maEx.SetPrefSize( aSize ); 1154cdf0e10cSrcweir } 1155cdf0e10cSrcweir } 1156cdf0e10cSrcweir else 1157cdf0e10cSrcweir { 1158cdf0e10cSrcweir maMetaFile.SetPrefMapMode( aMapMode ); 1159cdf0e10cSrcweir maMetaFile.SetPrefSize( aSize ); 1160cdf0e10cSrcweir } 1161cdf0e10cSrcweir 1162cdf0e10cSrcweir if( bSwap ) 1163cdf0e10cSrcweir { 1164cdf0e10cSrcweir if( maDocFileURLStr.Len() ) 1165cdf0e10cSrcweir { 1166cdf0e10cSrcweir rIStm.Seek( nStartPos + nHeaderLen + nLen ); 1167cdf0e10cSrcweir bRet = mbSwapOut = sal_True; 1168cdf0e10cSrcweir } 1169cdf0e10cSrcweir else 1170cdf0e10cSrcweir { 1171cdf0e10cSrcweir ::utl::TempFile aTempFile; 1172cdf0e10cSrcweir const INetURLObject aTmpURL( aTempFile.GetURL() ); 1173cdf0e10cSrcweir 1174cdf0e10cSrcweir if( aTmpURL.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) 1175cdf0e10cSrcweir { 1176cdf0e10cSrcweir SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( aTmpURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READWRITE | STREAM_SHARE_DENYWRITE ); 1177cdf0e10cSrcweir 1178cdf0e10cSrcweir if( pOStm ) 1179cdf0e10cSrcweir { 1180cdf0e10cSrcweir sal_uLong nFullLen = nHeaderLen + nLen; 1181cdf0e10cSrcweir sal_uLong nPartLen = Min( nFullLen, (sal_uLong) GRAPHIC_MAXPARTLEN ); 1182cdf0e10cSrcweir sal_uInt8* pBuffer = (sal_uInt8*) rtl_allocateMemory( nPartLen ); 1183cdf0e10cSrcweir 1184cdf0e10cSrcweir pOStm->SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); 1185cdf0e10cSrcweir 1186cdf0e10cSrcweir if( pBuffer ) 1187cdf0e10cSrcweir { 1188cdf0e10cSrcweir rIStm.Seek( nStartPos ); 1189cdf0e10cSrcweir 1190cdf0e10cSrcweir while( nFullLen ) 1191cdf0e10cSrcweir { 1192cdf0e10cSrcweir rIStm.Read( (char*) pBuffer, nPartLen ); 1193cdf0e10cSrcweir pOStm->Write( (char*) pBuffer, nPartLen ); 1194cdf0e10cSrcweir 1195cdf0e10cSrcweir nFullLen -= nPartLen; 1196cdf0e10cSrcweir 1197cdf0e10cSrcweir if( nFullLen < GRAPHIC_MAXPARTLEN ) 1198cdf0e10cSrcweir nPartLen = nFullLen; 1199cdf0e10cSrcweir } 1200cdf0e10cSrcweir 1201cdf0e10cSrcweir rtl_freeMemory( pBuffer ); 1202cdf0e10cSrcweir sal_uLong nReadErr = rIStm.GetError(), nWriteErr = pOStm->GetError(); 1203cdf0e10cSrcweir delete pOStm, pOStm = NULL; 1204cdf0e10cSrcweir 1205cdf0e10cSrcweir if( !nReadErr && !nWriteErr ) 1206cdf0e10cSrcweir { 1207cdf0e10cSrcweir bRet = mbSwapOut = sal_True; 1208cdf0e10cSrcweir mpSwapFile = new ImpSwapFile; 1209cdf0e10cSrcweir mpSwapFile->nRefCount = 1; 1210cdf0e10cSrcweir mpSwapFile->aSwapURL = aTmpURL; 1211cdf0e10cSrcweir } 1212cdf0e10cSrcweir else 1213cdf0e10cSrcweir { 1214cdf0e10cSrcweir try 1215cdf0e10cSrcweir { 1216cdf0e10cSrcweir ::ucbhelper::Content aCnt( aTmpURL.GetMainURL( INetURLObject::NO_DECODE ), 1217cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >() ); 1218cdf0e10cSrcweir 1219cdf0e10cSrcweir aCnt.executeCommand( ::rtl::OUString::createFromAscii( "delete" ), 1220cdf0e10cSrcweir ::com::sun::star::uno::makeAny( sal_Bool( sal_True ) ) ); 1221cdf0e10cSrcweir } 1222cdf0e10cSrcweir catch( const ::com::sun::star::ucb::ContentCreationException& ) 1223cdf0e10cSrcweir { 1224cdf0e10cSrcweir } 1225cdf0e10cSrcweir catch( const ::com::sun::star::uno::RuntimeException& ) 1226cdf0e10cSrcweir { 1227cdf0e10cSrcweir } 1228cdf0e10cSrcweir catch( const ::com::sun::star::ucb::CommandAbortedException& ) 1229cdf0e10cSrcweir { 1230cdf0e10cSrcweir } 1231cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 1232cdf0e10cSrcweir { 1233cdf0e10cSrcweir } 1234cdf0e10cSrcweir } 1235cdf0e10cSrcweir } 1236cdf0e10cSrcweir 1237cdf0e10cSrcweir delete pOStm; 1238cdf0e10cSrcweir } 1239cdf0e10cSrcweir } 1240cdf0e10cSrcweir } 1241cdf0e10cSrcweir } 1242cdf0e10cSrcweir else if( meType == GRAPHIC_BITMAP || meType == GRAPHIC_GDIMETAFILE ) 1243cdf0e10cSrcweir { 1244cdf0e10cSrcweir rIStm >> *this; 1245cdf0e10cSrcweir bRet = ( rIStm.GetError() == 0UL ); 1246cdf0e10cSrcweir } 1247cdf0e10cSrcweir else if( meType >= SYS_WINMETAFILE && meType <= SYS_MACMETAFILE ) 1248cdf0e10cSrcweir { 1249cdf0e10cSrcweir Graphic aSysGraphic; 1250cdf0e10cSrcweir sal_uLong nCvtType; 1251cdf0e10cSrcweir 1252cdf0e10cSrcweir switch( sal::static_int_cast<sal_uLong>(meType) ) 1253cdf0e10cSrcweir { 1254cdf0e10cSrcweir case( SYS_WINMETAFILE ): 1255cdf0e10cSrcweir case( SYS_WNTMETAFILE ): nCvtType = CVT_WMF; break; 1256cdf0e10cSrcweir case( SYS_OS2METAFILE ): nCvtType = CVT_MET; break; 1257cdf0e10cSrcweir case( SYS_MACMETAFILE ): nCvtType = CVT_PCT; break; 1258cdf0e10cSrcweir 1259cdf0e10cSrcweir default: 1260cdf0e10cSrcweir nCvtType = CVT_UNKNOWN; 1261cdf0e10cSrcweir break; 1262cdf0e10cSrcweir } 1263cdf0e10cSrcweir 1264cdf0e10cSrcweir if( nType && GraphicConverter::Import( rIStm, aSysGraphic, nCvtType ) == ERRCODE_NONE ) 1265cdf0e10cSrcweir { 1266cdf0e10cSrcweir *this = ImpGraphic( aSysGraphic.GetGDIMetaFile() ); 1267cdf0e10cSrcweir bRet = ( rIStm.GetError() == 0UL ); 1268cdf0e10cSrcweir } 1269cdf0e10cSrcweir else 1270cdf0e10cSrcweir meType = GRAPHIC_DEFAULT; 1271cdf0e10cSrcweir } 1272cdf0e10cSrcweir 1273cdf0e10cSrcweir if( bRet ) 1274cdf0e10cSrcweir { 1275cdf0e10cSrcweir ImplSetPrefMapMode( aMapMode ); 1276cdf0e10cSrcweir ImplSetPrefSize( aSize ); 1277cdf0e10cSrcweir } 1278cdf0e10cSrcweir } 1279cdf0e10cSrcweir else 1280cdf0e10cSrcweir bRet = sal_True; 1281cdf0e10cSrcweir 1282cdf0e10cSrcweir rIStm.SetNumberFormatInt( nOldFormat ); 1283cdf0e10cSrcweir 1284cdf0e10cSrcweir return bRet; 1285cdf0e10cSrcweir } 1286cdf0e10cSrcweir 1287cdf0e10cSrcweir // ------------------------------------------------------------------------ 1288cdf0e10cSrcweir 1289cdf0e10cSrcweir sal_Bool ImpGraphic::ImplWriteEmbedded( SvStream& rOStm ) 1290cdf0e10cSrcweir { 1291cdf0e10cSrcweir sal_Bool bRet = sal_False; 1292cdf0e10cSrcweir 1293cdf0e10cSrcweir if( ( meType != GRAPHIC_NONE ) && ( meType != GRAPHIC_DEFAULT ) && !ImplIsSwapOut() ) 1294cdf0e10cSrcweir { 1295cdf0e10cSrcweir const MapMode aMapMode( ImplGetPrefMapMode() ); 1296cdf0e10cSrcweir const Size aSize( ImplGetPrefSize() ); 1297cdf0e10cSrcweir const sal_uInt16 nOldFormat = rOStm.GetNumberFormatInt(); 1298cdf0e10cSrcweir sal_uLong nDataFieldPos; 1299cdf0e10cSrcweir 1300cdf0e10cSrcweir rOStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); 1301cdf0e10cSrcweir 1302cdf0e10cSrcweir // write correct version ( old style/new style header ) 1303cdf0e10cSrcweir if( rOStm.GetVersion() >= SOFFICE_FILEFORMAT_50 ) 1304cdf0e10cSrcweir { 1305cdf0e10cSrcweir // write ID for new format (5.0) 1306cdf0e10cSrcweir rOStm << GRAPHIC_FORMAT_50; 1307cdf0e10cSrcweir 1308cdf0e10cSrcweir // write new style header 1309cdf0e10cSrcweir VersionCompat* pCompat = new VersionCompat( rOStm, STREAM_WRITE, 1 ); 1310cdf0e10cSrcweir 1311cdf0e10cSrcweir rOStm << (long) meType; 1312cdf0e10cSrcweir 1313cdf0e10cSrcweir // data size is updated later 1314cdf0e10cSrcweir nDataFieldPos = rOStm.Tell(); 1315cdf0e10cSrcweir rOStm << (long) 0; 1316cdf0e10cSrcweir 1317cdf0e10cSrcweir rOStm << aSize; 1318cdf0e10cSrcweir rOStm << aMapMode; 1319cdf0e10cSrcweir 1320cdf0e10cSrcweir delete pCompat; 1321cdf0e10cSrcweir } 1322cdf0e10cSrcweir else 1323cdf0e10cSrcweir { 1324cdf0e10cSrcweir // write old style (<=4.0) header 1325cdf0e10cSrcweir rOStm << (long) meType; 1326cdf0e10cSrcweir 1327cdf0e10cSrcweir // data size is updated later 1328cdf0e10cSrcweir nDataFieldPos = rOStm.Tell(); 1329cdf0e10cSrcweir rOStm << (long) 0; 1330cdf0e10cSrcweir 1331cdf0e10cSrcweir rOStm << (long) aSize.Width(); 1332cdf0e10cSrcweir rOStm << (long) aSize.Height(); 1333cdf0e10cSrcweir rOStm << (long) aMapMode.GetMapUnit(); 1334cdf0e10cSrcweir rOStm << (long) aMapMode.GetScaleX().GetNumerator(); 1335cdf0e10cSrcweir rOStm << (long) aMapMode.GetScaleX().GetDenominator(); 1336cdf0e10cSrcweir rOStm << (long) aMapMode.GetScaleY().GetNumerator(); 1337cdf0e10cSrcweir rOStm << (long) aMapMode.GetScaleY().GetDenominator(); 1338cdf0e10cSrcweir rOStm << (long) aMapMode.GetOrigin().X(); 1339cdf0e10cSrcweir rOStm << (long) aMapMode.GetOrigin().Y(); 1340cdf0e10cSrcweir } 1341cdf0e10cSrcweir 1342cdf0e10cSrcweir // write data block 1343cdf0e10cSrcweir if( !rOStm.GetError() ) 1344cdf0e10cSrcweir { 1345cdf0e10cSrcweir const sal_uLong nDataStart = rOStm.Tell(); 1346cdf0e10cSrcweir 1347cdf0e10cSrcweir if( ImplIsSupportedGraphic() ) 1348cdf0e10cSrcweir rOStm << *this; 1349cdf0e10cSrcweir 1350cdf0e10cSrcweir if( !rOStm.GetError() ) 1351cdf0e10cSrcweir { 1352cdf0e10cSrcweir const sal_uLong nStmPos2 = rOStm.Tell(); 1353cdf0e10cSrcweir rOStm.Seek( nDataFieldPos ); 1354cdf0e10cSrcweir rOStm << (long) ( nStmPos2 - nDataStart ); 1355cdf0e10cSrcweir rOStm.Seek( nStmPos2 ); 1356cdf0e10cSrcweir bRet = sal_True; 1357cdf0e10cSrcweir } 1358cdf0e10cSrcweir } 1359cdf0e10cSrcweir 1360cdf0e10cSrcweir rOStm.SetNumberFormatInt( nOldFormat ); 1361cdf0e10cSrcweir } 1362cdf0e10cSrcweir 1363cdf0e10cSrcweir return bRet; 1364cdf0e10cSrcweir } 1365cdf0e10cSrcweir 1366cdf0e10cSrcweir // ------------------------------------------------------------------------ 1367cdf0e10cSrcweir 1368cdf0e10cSrcweir sal_Bool ImpGraphic::ImplSwapOut() 1369cdf0e10cSrcweir { 1370cdf0e10cSrcweir sal_Bool bRet = sal_False; 1371cdf0e10cSrcweir 1372cdf0e10cSrcweir if( !ImplIsSwapOut() ) 1373cdf0e10cSrcweir { 1374cdf0e10cSrcweir if( !maDocFileURLStr.Len() ) 1375cdf0e10cSrcweir { 1376cdf0e10cSrcweir ::utl::TempFile aTempFile; 1377cdf0e10cSrcweir const INetURLObject aTmpURL( aTempFile.GetURL() ); 1378cdf0e10cSrcweir 1379cdf0e10cSrcweir if( aTmpURL.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) 1380cdf0e10cSrcweir { 1381cdf0e10cSrcweir SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( aTmpURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READWRITE | STREAM_SHARE_DENYWRITE ); 1382cdf0e10cSrcweir 1383cdf0e10cSrcweir if( pOStm ) 1384cdf0e10cSrcweir { 1385cdf0e10cSrcweir pOStm->SetVersion( SOFFICE_FILEFORMAT_50 ); 1386cdf0e10cSrcweir pOStm->SetCompressMode( COMPRESSMODE_NATIVE ); 1387cdf0e10cSrcweir 1388cdf0e10cSrcweir if( ( bRet = ImplSwapOut( pOStm ) ) == sal_True ) 1389cdf0e10cSrcweir { 1390cdf0e10cSrcweir mpSwapFile = new ImpSwapFile; 1391cdf0e10cSrcweir mpSwapFile->nRefCount = 1; 1392cdf0e10cSrcweir mpSwapFile->aSwapURL = aTmpURL; 1393cdf0e10cSrcweir } 1394cdf0e10cSrcweir else 1395cdf0e10cSrcweir { 1396cdf0e10cSrcweir delete pOStm, pOStm = NULL; 1397cdf0e10cSrcweir 1398cdf0e10cSrcweir try 1399cdf0e10cSrcweir { 1400cdf0e10cSrcweir ::ucbhelper::Content aCnt( aTmpURL.GetMainURL( INetURLObject::NO_DECODE ), 1401cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >() ); 1402cdf0e10cSrcweir 1403cdf0e10cSrcweir aCnt.executeCommand( ::rtl::OUString::createFromAscii( "delete" ), 1404cdf0e10cSrcweir ::com::sun::star::uno::makeAny( sal_Bool( sal_True ) ) ); 1405cdf0e10cSrcweir } 1406cdf0e10cSrcweir catch( const ::com::sun::star::ucb::ContentCreationException& ) 1407cdf0e10cSrcweir { 1408cdf0e10cSrcweir } 1409cdf0e10cSrcweir catch( const ::com::sun::star::uno::RuntimeException& ) 1410cdf0e10cSrcweir { 1411cdf0e10cSrcweir } 1412cdf0e10cSrcweir catch( const ::com::sun::star::ucb::CommandAbortedException& ) 1413cdf0e10cSrcweir { 1414cdf0e10cSrcweir } 1415cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 1416cdf0e10cSrcweir { 1417cdf0e10cSrcweir } 1418cdf0e10cSrcweir } 1419cdf0e10cSrcweir 1420cdf0e10cSrcweir delete pOStm; 1421cdf0e10cSrcweir } 1422cdf0e10cSrcweir } 1423cdf0e10cSrcweir } 1424cdf0e10cSrcweir else 1425cdf0e10cSrcweir { 1426cdf0e10cSrcweir ImplClearGraphics( sal_True ); 1427cdf0e10cSrcweir bRet = mbSwapOut = sal_True; 1428cdf0e10cSrcweir } 1429cdf0e10cSrcweir } 1430cdf0e10cSrcweir 1431cdf0e10cSrcweir return bRet; 1432cdf0e10cSrcweir } 1433cdf0e10cSrcweir 1434cdf0e10cSrcweir // ------------------------------------------------------------------------ 1435cdf0e10cSrcweir 1436cdf0e10cSrcweir sal_Bool ImpGraphic::ImplSwapOut( SvStream* pOStm ) 1437cdf0e10cSrcweir { 1438cdf0e10cSrcweir sal_Bool bRet = sal_False; 1439cdf0e10cSrcweir 1440cdf0e10cSrcweir if( pOStm ) 1441cdf0e10cSrcweir { 1442cdf0e10cSrcweir pOStm->SetBufferSize( GRAPHIC_STREAMBUFSIZE ); 1443cdf0e10cSrcweir 1444cdf0e10cSrcweir if( !pOStm->GetError() && ImplWriteEmbedded( *pOStm ) ) 1445cdf0e10cSrcweir { 1446cdf0e10cSrcweir pOStm->Flush(); 1447cdf0e10cSrcweir 1448cdf0e10cSrcweir if( !pOStm->GetError() ) 1449cdf0e10cSrcweir { 1450cdf0e10cSrcweir ImplClearGraphics( sal_True ); 1451cdf0e10cSrcweir bRet = mbSwapOut = sal_True; 1452cdf0e10cSrcweir } 1453cdf0e10cSrcweir } 1454cdf0e10cSrcweir } 1455cdf0e10cSrcweir else 1456cdf0e10cSrcweir { 1457cdf0e10cSrcweir ImplClearGraphics( sal_True ); 1458cdf0e10cSrcweir bRet = mbSwapOut = sal_True; 1459cdf0e10cSrcweir } 1460cdf0e10cSrcweir 1461cdf0e10cSrcweir return bRet; 1462cdf0e10cSrcweir } 1463cdf0e10cSrcweir 1464cdf0e10cSrcweir // ------------------------------------------------------------------------ 1465cdf0e10cSrcweir 1466cdf0e10cSrcweir sal_Bool ImpGraphic::ImplSwapIn() 1467cdf0e10cSrcweir { 1468cdf0e10cSrcweir sal_Bool bRet = sal_False; 1469cdf0e10cSrcweir 1470cdf0e10cSrcweir if( ImplIsSwapOut() ) 1471cdf0e10cSrcweir { 1472cdf0e10cSrcweir String aSwapURL; 1473cdf0e10cSrcweir 1474cdf0e10cSrcweir if( mpSwapFile ) 1475cdf0e10cSrcweir aSwapURL = mpSwapFile->aSwapURL.GetMainURL( INetURLObject::NO_DECODE ); 1476cdf0e10cSrcweir else 1477cdf0e10cSrcweir aSwapURL = maDocFileURLStr; 1478cdf0e10cSrcweir 1479cdf0e10cSrcweir if( aSwapURL.Len() ) 1480cdf0e10cSrcweir { 1481cdf0e10cSrcweir SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aSwapURL, STREAM_READWRITE | STREAM_SHARE_DENYWRITE ); 1482cdf0e10cSrcweir 1483cdf0e10cSrcweir if( pIStm ) 1484cdf0e10cSrcweir { 1485cdf0e10cSrcweir pIStm->SetVersion( SOFFICE_FILEFORMAT_50 ); 1486cdf0e10cSrcweir pIStm->SetCompressMode( COMPRESSMODE_NATIVE ); 1487cdf0e10cSrcweir 1488cdf0e10cSrcweir if( !mpSwapFile ) 1489cdf0e10cSrcweir pIStm->Seek( mnDocFilePos ); 1490cdf0e10cSrcweir 1491cdf0e10cSrcweir bRet = ImplSwapIn( pIStm ); 1492cdf0e10cSrcweir delete pIStm; 1493cdf0e10cSrcweir 1494cdf0e10cSrcweir if( mpSwapFile ) 1495cdf0e10cSrcweir { 1496cdf0e10cSrcweir if( mpSwapFile->nRefCount > 1 ) 1497cdf0e10cSrcweir mpSwapFile->nRefCount--; 1498cdf0e10cSrcweir else 1499cdf0e10cSrcweir { 1500cdf0e10cSrcweir try 1501cdf0e10cSrcweir { 1502cdf0e10cSrcweir ::ucbhelper::Content aCnt( aSwapURL, 1503cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >() ); 1504cdf0e10cSrcweir 1505cdf0e10cSrcweir aCnt.executeCommand( ::rtl::OUString::createFromAscii( "delete" ), 1506cdf0e10cSrcweir ::com::sun::star::uno::makeAny( sal_Bool( sal_True ) ) ); 1507cdf0e10cSrcweir } 1508cdf0e10cSrcweir catch( const ::com::sun::star::ucb::ContentCreationException& ) 1509cdf0e10cSrcweir { 1510cdf0e10cSrcweir } 1511cdf0e10cSrcweir catch( const ::com::sun::star::uno::RuntimeException& ) 1512cdf0e10cSrcweir { 1513cdf0e10cSrcweir } 1514cdf0e10cSrcweir catch( const ::com::sun::star::ucb::CommandAbortedException& ) 1515cdf0e10cSrcweir { 1516cdf0e10cSrcweir } 1517cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 1518cdf0e10cSrcweir { 1519cdf0e10cSrcweir } 1520cdf0e10cSrcweir 1521cdf0e10cSrcweir delete mpSwapFile; 1522cdf0e10cSrcweir } 1523cdf0e10cSrcweir 1524cdf0e10cSrcweir mpSwapFile = NULL; 1525cdf0e10cSrcweir } 1526cdf0e10cSrcweir } 1527cdf0e10cSrcweir } 1528cdf0e10cSrcweir } 1529cdf0e10cSrcweir 1530cdf0e10cSrcweir return bRet; 1531cdf0e10cSrcweir } 1532cdf0e10cSrcweir 1533cdf0e10cSrcweir // ------------------------------------------------------------------------ 1534cdf0e10cSrcweir 1535cdf0e10cSrcweir sal_Bool ImpGraphic::ImplSwapIn( SvStream* pIStm ) 1536cdf0e10cSrcweir { 1537cdf0e10cSrcweir sal_Bool bRet = sal_False; 1538cdf0e10cSrcweir 1539cdf0e10cSrcweir if( pIStm ) 1540cdf0e10cSrcweir { 1541cdf0e10cSrcweir pIStm->SetBufferSize( GRAPHIC_STREAMBUFSIZE ); 1542cdf0e10cSrcweir 1543cdf0e10cSrcweir if( !pIStm->GetError() ) 1544cdf0e10cSrcweir { 1545cdf0e10cSrcweir mbSwapUnderway = sal_True; 1546cdf0e10cSrcweir bRet = ImplReadEmbedded( *pIStm ); 1547cdf0e10cSrcweir mbSwapUnderway = sal_False; 1548cdf0e10cSrcweir 1549cdf0e10cSrcweir if( !bRet ) 1550cdf0e10cSrcweir ImplClear(); 1551cdf0e10cSrcweir else 1552cdf0e10cSrcweir mbSwapOut = sal_False; 1553cdf0e10cSrcweir } 1554cdf0e10cSrcweir } 1555cdf0e10cSrcweir 1556cdf0e10cSrcweir return bRet; 1557cdf0e10cSrcweir } 1558cdf0e10cSrcweir 1559cdf0e10cSrcweir // ------------------------------------------------------------------------ 1560cdf0e10cSrcweir 1561cdf0e10cSrcweir sal_Bool ImpGraphic::ImplIsSwapOut() const 1562cdf0e10cSrcweir { 1563cdf0e10cSrcweir return mbSwapOut; 1564cdf0e10cSrcweir } 1565cdf0e10cSrcweir 1566cdf0e10cSrcweir // ------------------------------------------------------------------------ 1567cdf0e10cSrcweir 1568cdf0e10cSrcweir void ImpGraphic::ImplSetLink( const GfxLink& rGfxLink ) 1569cdf0e10cSrcweir { 1570cdf0e10cSrcweir delete mpGfxLink; 1571cdf0e10cSrcweir mpGfxLink = new GfxLink( rGfxLink ); 1572cdf0e10cSrcweir 1573cdf0e10cSrcweir if( mpGfxLink->IsNative() ) 1574cdf0e10cSrcweir mpGfxLink->SwapOut(); 1575cdf0e10cSrcweir } 1576cdf0e10cSrcweir 1577cdf0e10cSrcweir // ------------------------------------------------------------------------ 1578cdf0e10cSrcweir 1579cdf0e10cSrcweir GfxLink ImpGraphic::ImplGetLink() 1580cdf0e10cSrcweir { 1581cdf0e10cSrcweir return( mpGfxLink ? *mpGfxLink : GfxLink() ); 1582cdf0e10cSrcweir } 1583cdf0e10cSrcweir 1584cdf0e10cSrcweir // ------------------------------------------------------------------------ 1585cdf0e10cSrcweir 1586cdf0e10cSrcweir sal_Bool ImpGraphic::ImplIsLink() const 1587cdf0e10cSrcweir { 1588cdf0e10cSrcweir return ( mpGfxLink != NULL ) ? sal_True : sal_False; 1589cdf0e10cSrcweir } 1590cdf0e10cSrcweir 1591cdf0e10cSrcweir // ------------------------------------------------------------------------ 1592cdf0e10cSrcweir 1593cdf0e10cSrcweir sal_uLong ImpGraphic::ImplGetChecksum() const 1594cdf0e10cSrcweir { 1595cdf0e10cSrcweir sal_uLong nRet = 0; 1596cdf0e10cSrcweir 1597cdf0e10cSrcweir if( ImplIsSupportedGraphic() && !ImplIsSwapOut() ) 1598cdf0e10cSrcweir { 1599cdf0e10cSrcweir switch( meType ) 1600cdf0e10cSrcweir { 1601cdf0e10cSrcweir case( GRAPHIC_DEFAULT ): 1602cdf0e10cSrcweir break; 1603cdf0e10cSrcweir 1604cdf0e10cSrcweir case( GRAPHIC_BITMAP ): 1605cdf0e10cSrcweir { 1606*ddde725dSArmin Le Grand if(maSvgData.get() && maEx.IsEmpty()) 1607*ddde725dSArmin Le Grand { 1608*ddde725dSArmin Le Grand // use maEx as local buffer for rendered svg 1609*ddde725dSArmin Le Grand const_cast< ImpGraphic* >(this)->maEx = maSvgData->getReplacement(); 1610*ddde725dSArmin Le Grand } 1611*ddde725dSArmin Le Grand 1612cdf0e10cSrcweir if( mpAnimation ) 1613*ddde725dSArmin Le Grand { 1614cdf0e10cSrcweir nRet = mpAnimation->GetChecksum(); 1615*ddde725dSArmin Le Grand } 1616cdf0e10cSrcweir else 1617*ddde725dSArmin Le Grand { 1618cdf0e10cSrcweir nRet = maEx.GetChecksum(); 1619cdf0e10cSrcweir } 1620*ddde725dSArmin Le Grand } 1621cdf0e10cSrcweir break; 1622cdf0e10cSrcweir 1623cdf0e10cSrcweir default: 1624cdf0e10cSrcweir nRet = maMetaFile.GetChecksum(); 1625cdf0e10cSrcweir break; 1626cdf0e10cSrcweir } 1627cdf0e10cSrcweir } 1628cdf0e10cSrcweir 1629cdf0e10cSrcweir return nRet; 1630cdf0e10cSrcweir } 1631cdf0e10cSrcweir 1632cdf0e10cSrcweir // ------------------------------------------------------------------------ 1633cdf0e10cSrcweir 1634cdf0e10cSrcweir sal_Bool ImpGraphic::ImplExportNative( SvStream& rOStm ) const 1635cdf0e10cSrcweir { 1636cdf0e10cSrcweir sal_Bool bResult = sal_False; 1637cdf0e10cSrcweir 1638cdf0e10cSrcweir if( !rOStm.GetError() ) 1639cdf0e10cSrcweir { 1640cdf0e10cSrcweir if( !ImplIsSwapOut() ) 1641cdf0e10cSrcweir { 1642cdf0e10cSrcweir if( mpGfxLink && mpGfxLink->IsNative() ) 1643cdf0e10cSrcweir bResult = mpGfxLink->ExportNative( rOStm ); 1644cdf0e10cSrcweir else 1645cdf0e10cSrcweir { 1646cdf0e10cSrcweir rOStm << *this; 1647cdf0e10cSrcweir bResult = ( rOStm.GetError() == ERRCODE_NONE ); 1648cdf0e10cSrcweir } 1649cdf0e10cSrcweir } 1650cdf0e10cSrcweir else 1651cdf0e10cSrcweir rOStm.SetError( SVSTREAM_GENERALERROR ); 1652cdf0e10cSrcweir } 1653cdf0e10cSrcweir 1654cdf0e10cSrcweir return bResult; 1655cdf0e10cSrcweir } 1656cdf0e10cSrcweir 1657cdf0e10cSrcweir // ------------------------------------------------------------------------ 1658cdf0e10cSrcweir 1659*ddde725dSArmin Le Grand const SvgDataPtr& ImpGraphic::getSvgData() const 1660*ddde725dSArmin Le Grand { 1661*ddde725dSArmin Le Grand return maSvgData; 1662*ddde725dSArmin Le Grand } 1663*ddde725dSArmin Le Grand 1664*ddde725dSArmin Le Grand // ------------------------------------------------------------------------ 1665*ddde725dSArmin Le Grand 1666cdf0e10cSrcweir SvStream& operator>>( SvStream& rIStm, ImpGraphic& rImpGraphic ) 1667cdf0e10cSrcweir { 1668cdf0e10cSrcweir if( !rIStm.GetError() ) 1669cdf0e10cSrcweir { 1670cdf0e10cSrcweir const sal_uLong nStmPos1 = rIStm.Tell(); 1671cdf0e10cSrcweir sal_uInt32 nTmp; 1672cdf0e10cSrcweir 1673cdf0e10cSrcweir if ( !rImpGraphic.mbSwapUnderway ) 1674cdf0e10cSrcweir rImpGraphic.ImplClear(); 1675cdf0e10cSrcweir 1676cdf0e10cSrcweir // read Id 1677cdf0e10cSrcweir rIStm >> nTmp; 1678cdf0e10cSrcweir 1679cdf0e10cSrcweir // if there is no more data, avoid further expensive 1680cdf0e10cSrcweir // reading which will create VDevs and other stuff, just to 1681cdf0e10cSrcweir // read nothing. CAUTION: Eof is only true AFTER reading another 1682cdf0e10cSrcweir // byte, a speciality of SvMemoryStream (!) 1683cdf0e10cSrcweir if(!rIStm.GetError() && !rIStm.IsEof()) 1684cdf0e10cSrcweir { 1685cdf0e10cSrcweir if( NATIVE_FORMAT_50 == nTmp ) 1686cdf0e10cSrcweir { 1687cdf0e10cSrcweir Graphic aGraphic; 1688cdf0e10cSrcweir GfxLink aLink; 1689cdf0e10cSrcweir VersionCompat* pCompat; 1690cdf0e10cSrcweir 1691cdf0e10cSrcweir // read compat info 1692cdf0e10cSrcweir pCompat = new VersionCompat( rIStm, STREAM_READ ); 1693cdf0e10cSrcweir delete pCompat; 1694cdf0e10cSrcweir 1695cdf0e10cSrcweir rIStm >> aLink; 1696cdf0e10cSrcweir 1697cdf0e10cSrcweir // set dummy link to avoid creation of additional link after filtering; 1698cdf0e10cSrcweir // we set a default link to avoid unnecessary swapping of native data 1699cdf0e10cSrcweir aGraphic.SetLink( GfxLink() ); 1700cdf0e10cSrcweir 1701cdf0e10cSrcweir if( !rIStm.GetError() && aLink.LoadNative( aGraphic ) ) 1702cdf0e10cSrcweir { 1703cdf0e10cSrcweir // set link only, if no other link was set 1704cdf0e10cSrcweir const sal_Bool bSetLink = ( rImpGraphic.mpGfxLink == NULL ); 1705cdf0e10cSrcweir 1706cdf0e10cSrcweir // assign graphic 1707cdf0e10cSrcweir rImpGraphic = *aGraphic.ImplGetImpGraphic(); 1708cdf0e10cSrcweir 1709cdf0e10cSrcweir if( aLink.IsPrefMapModeValid() ) 1710cdf0e10cSrcweir rImpGraphic.ImplSetPrefMapMode( aLink.GetPrefMapMode() ); 1711cdf0e10cSrcweir 1712cdf0e10cSrcweir if( aLink.IsPrefSizeValid() ) 1713cdf0e10cSrcweir rImpGraphic.ImplSetPrefSize( aLink.GetPrefSize() ); 1714cdf0e10cSrcweir 1715cdf0e10cSrcweir if( bSetLink ) 1716cdf0e10cSrcweir rImpGraphic.ImplSetLink( aLink ); 1717cdf0e10cSrcweir } 1718cdf0e10cSrcweir else 1719cdf0e10cSrcweir { 1720cdf0e10cSrcweir rIStm.Seek( nStmPos1 ); 1721cdf0e10cSrcweir rIStm.SetError( ERRCODE_IO_WRONGFORMAT ); 1722cdf0e10cSrcweir } 1723cdf0e10cSrcweir } 1724cdf0e10cSrcweir else 1725cdf0e10cSrcweir { 1726cdf0e10cSrcweir BitmapEx aBmpEx; 1727cdf0e10cSrcweir const sal_uInt16 nOldFormat = rIStm.GetNumberFormatInt(); 1728cdf0e10cSrcweir 1729cdf0e10cSrcweir rIStm.SeekRel( -4 ); 1730cdf0e10cSrcweir rIStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); 1731cdf0e10cSrcweir rIStm >> aBmpEx; 1732cdf0e10cSrcweir 1733cdf0e10cSrcweir if( !rIStm.GetError() ) 1734cdf0e10cSrcweir { 1735cdf0e10cSrcweir sal_uInt32 nMagic1(0), nMagic2(0); 1736cdf0e10cSrcweir sal_uLong nActPos = rIStm.Tell(); 1737cdf0e10cSrcweir 1738cdf0e10cSrcweir rIStm >> nMagic1 >> nMagic2; 1739cdf0e10cSrcweir rIStm.Seek( nActPos ); 1740cdf0e10cSrcweir 1741cdf0e10cSrcweir rImpGraphic = ImpGraphic( aBmpEx ); 1742cdf0e10cSrcweir 1743cdf0e10cSrcweir if( !rIStm.GetError() && ( 0x5344414e == nMagic1 ) && ( 0x494d4931 == nMagic2 ) ) 1744cdf0e10cSrcweir { 1745cdf0e10cSrcweir delete rImpGraphic.mpAnimation; 1746cdf0e10cSrcweir rImpGraphic.mpAnimation = new Animation; 1747cdf0e10cSrcweir rIStm >> *rImpGraphic.mpAnimation; 1748cdf0e10cSrcweir 1749cdf0e10cSrcweir // #108077# manually set loaded BmpEx to Animation 1750cdf0e10cSrcweir // (which skips loading its BmpEx if already done) 1751cdf0e10cSrcweir rImpGraphic.mpAnimation->SetBitmapEx(aBmpEx); 1752cdf0e10cSrcweir } 1753cdf0e10cSrcweir else 1754cdf0e10cSrcweir rIStm.ResetError(); 1755cdf0e10cSrcweir } 1756cdf0e10cSrcweir else 1757cdf0e10cSrcweir { 1758cdf0e10cSrcweir GDIMetaFile aMtf; 1759cdf0e10cSrcweir 1760cdf0e10cSrcweir rIStm.Seek( nStmPos1 ); 1761cdf0e10cSrcweir rIStm.ResetError(); 1762cdf0e10cSrcweir rIStm >> aMtf; 1763cdf0e10cSrcweir 1764cdf0e10cSrcweir if( !rIStm.GetError() ) 1765cdf0e10cSrcweir rImpGraphic = aMtf; 1766cdf0e10cSrcweir else 1767cdf0e10cSrcweir rIStm.Seek( nStmPos1 ); 1768cdf0e10cSrcweir } 1769cdf0e10cSrcweir 1770cdf0e10cSrcweir rIStm.SetNumberFormatInt( nOldFormat ); 1771cdf0e10cSrcweir } 1772cdf0e10cSrcweir } 1773cdf0e10cSrcweir } 1774cdf0e10cSrcweir 1775cdf0e10cSrcweir return rIStm; 1776cdf0e10cSrcweir } 1777cdf0e10cSrcweir 1778cdf0e10cSrcweir // ------------------------------------------------------------------------ 1779cdf0e10cSrcweir 1780cdf0e10cSrcweir SvStream& operator<<( SvStream& rOStm, const ImpGraphic& rImpGraphic ) 1781cdf0e10cSrcweir { 1782cdf0e10cSrcweir if( !rOStm.GetError() ) 1783cdf0e10cSrcweir { 1784cdf0e10cSrcweir if( !rImpGraphic.ImplIsSwapOut() ) 1785cdf0e10cSrcweir { 1786cdf0e10cSrcweir if( ( rOStm.GetVersion() >= SOFFICE_FILEFORMAT_50 ) && 1787cdf0e10cSrcweir ( rOStm.GetCompressMode() & COMPRESSMODE_NATIVE ) && 1788cdf0e10cSrcweir rImpGraphic.mpGfxLink && rImpGraphic.mpGfxLink->IsNative() ) 1789cdf0e10cSrcweir { 1790cdf0e10cSrcweir VersionCompat* pCompat; 1791cdf0e10cSrcweir 1792cdf0e10cSrcweir // native format 1793cdf0e10cSrcweir rOStm << NATIVE_FORMAT_50; 1794cdf0e10cSrcweir 1795cdf0e10cSrcweir // write compat info 1796cdf0e10cSrcweir pCompat = new VersionCompat( rOStm, STREAM_WRITE, 1 ); 1797cdf0e10cSrcweir delete pCompat; 1798cdf0e10cSrcweir 1799cdf0e10cSrcweir rImpGraphic.mpGfxLink->SetPrefMapMode( rImpGraphic.ImplGetPrefMapMode() ); 1800cdf0e10cSrcweir rImpGraphic.mpGfxLink->SetPrefSize( rImpGraphic.ImplGetPrefSize() ); 1801cdf0e10cSrcweir rOStm << *rImpGraphic.mpGfxLink; 1802cdf0e10cSrcweir } 1803cdf0e10cSrcweir else 1804cdf0e10cSrcweir { 1805cdf0e10cSrcweir // own format 1806cdf0e10cSrcweir const sal_uInt16 nOldFormat = rOStm.GetNumberFormatInt(); 1807cdf0e10cSrcweir rOStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); 1808cdf0e10cSrcweir 1809cdf0e10cSrcweir switch( rImpGraphic.ImplGetType() ) 1810cdf0e10cSrcweir { 1811cdf0e10cSrcweir case( GRAPHIC_NONE ): 1812cdf0e10cSrcweir case( GRAPHIC_DEFAULT ): 1813cdf0e10cSrcweir break; 1814cdf0e10cSrcweir 1815cdf0e10cSrcweir case GRAPHIC_BITMAP: 1816cdf0e10cSrcweir { 1817*ddde725dSArmin Le Grand if(rImpGraphic.getSvgData().get()) 1818*ddde725dSArmin Le Grand { 1819*ddde725dSArmin Le Grand rOStm << rImpGraphic.getSvgData()->getReplacement(); 1820*ddde725dSArmin Le Grand } 1821*ddde725dSArmin Le Grand else if( rImpGraphic.ImplIsAnimated()) 1822*ddde725dSArmin Le Grand { 1823cdf0e10cSrcweir rOStm << *rImpGraphic.mpAnimation; 1824*ddde725dSArmin Le Grand } 1825cdf0e10cSrcweir else 1826*ddde725dSArmin Le Grand { 1827cdf0e10cSrcweir rOStm << rImpGraphic.maEx; 1828cdf0e10cSrcweir } 1829*ddde725dSArmin Le Grand } 1830cdf0e10cSrcweir break; 1831cdf0e10cSrcweir 1832cdf0e10cSrcweir default: 1833cdf0e10cSrcweir { 1834cdf0e10cSrcweir if( rImpGraphic.ImplIsSupportedGraphic() ) 1835cdf0e10cSrcweir rOStm << rImpGraphic.maMetaFile; 1836cdf0e10cSrcweir } 1837cdf0e10cSrcweir break; 1838cdf0e10cSrcweir } 1839cdf0e10cSrcweir 1840cdf0e10cSrcweir rOStm.SetNumberFormatInt( nOldFormat ); 1841cdf0e10cSrcweir } 1842cdf0e10cSrcweir } 1843cdf0e10cSrcweir else 1844cdf0e10cSrcweir rOStm.SetError( SVSTREAM_GENERALERROR ); 1845cdf0e10cSrcweir } 1846cdf0e10cSrcweir 1847cdf0e10cSrcweir return rOStm; 1848cdf0e10cSrcweir } 1849