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