1*70f497fbSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*70f497fbSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*70f497fbSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*70f497fbSAndrew Rist * distributed with this work for additional information 6*70f497fbSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*70f497fbSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*70f497fbSAndrew Rist * "License"); you may not use this file except in compliance 9*70f497fbSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*70f497fbSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*70f497fbSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*70f497fbSAndrew Rist * software distributed under the License is distributed on an 15*70f497fbSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*70f497fbSAndrew Rist * KIND, either express or implied. See the License for the 17*70f497fbSAndrew Rist * specific language governing permissions and limitations 18*70f497fbSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*70f497fbSAndrew Rist *************************************************************/ 21*70f497fbSAndrew Rist 22*70f497fbSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_slideshow.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir // must be first 28cdf0e10cSrcweir #include <canvas/debug.hxx> 29cdf0e10cSrcweir #include <tools/diagnose_ex.h> 30cdf0e10cSrcweir #include <gdimtftools.hxx> 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <com/sun/star/document/XExporter.hpp> 33cdf0e10cSrcweir #include <com/sun/star/document/XFilter.hpp> 34cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphic.hpp> 35cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphicRenderer.hpp> 36cdf0e10cSrcweir #include <com/sun/star/drawing/XShape.hpp> 37cdf0e10cSrcweir 38cdf0e10cSrcweir #include <cppuhelper/basemutex.hxx> 39cdf0e10cSrcweir #include <cppuhelper/compbase1.hxx> 40cdf0e10cSrcweir 41cdf0e10cSrcweir #include <comphelper/uno3.hxx> 42cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 43cdf0e10cSrcweir 44cdf0e10cSrcweir #include <tools/stream.hxx> 45cdf0e10cSrcweir #include <vcl/svapp.hxx> 46cdf0e10cSrcweir #include <vcl/canvastools.hxx> 47cdf0e10cSrcweir #include <vcl/metaact.hxx> 48cdf0e10cSrcweir #include <vcl/virdev.hxx> 49cdf0e10cSrcweir #include <vcl/gdimtf.hxx> 50cdf0e10cSrcweir #include <vcl/metaact.hxx> 51cdf0e10cSrcweir #include <vcl/animate.hxx> 52cdf0e10cSrcweir #include <vcl/graph.hxx> 53cdf0e10cSrcweir 54cdf0e10cSrcweir #include <unotools/streamwrap.hxx> 55cdf0e10cSrcweir 56cdf0e10cSrcweir #include "tools.hxx" 57cdf0e10cSrcweir 58cdf0e10cSrcweir using namespace ::com::sun::star; 59cdf0e10cSrcweir 60cdf0e10cSrcweir 61cdf0e10cSrcweir // free support functions 62cdf0e10cSrcweir // ====================== 63cdf0e10cSrcweir 64cdf0e10cSrcweir namespace slideshow 65cdf0e10cSrcweir { 66cdf0e10cSrcweir namespace internal 67cdf0e10cSrcweir { 68cdf0e10cSrcweir // TODO(E2): Detect the case when svx/drawing layer is not 69cdf0e10cSrcweir // in-process, or even not on the same machine, and 70cdf0e10cSrcweir // fallback to metafile streaming! 71cdf0e10cSrcweir 72cdf0e10cSrcweir // For fixing #i48102#, have to be a _lot_ more selective 73cdf0e10cSrcweir // on which metafiles to convert to bitmaps. The problem 74cdf0e10cSrcweir // here is that we _always_ get the shape content as a 75cdf0e10cSrcweir // metafile, even if we have a bitmap graphic shape. Thus, 76cdf0e10cSrcweir // calling GetBitmapEx on such a Graphic (see below) will 77cdf0e10cSrcweir // result in one poorly scaled bitmap into another, 78cdf0e10cSrcweir // somewhat arbitrarily sized bitmap. 79cdf0e10cSrcweir bool hasUnsupportedActions( const GDIMetaFile& rMtf ) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir // search metafile for RasterOp action 82cdf0e10cSrcweir MetaAction* pCurrAct; 83cdf0e10cSrcweir 84cdf0e10cSrcweir // TODO(Q3): avoid const-cast 85cdf0e10cSrcweir for( pCurrAct = const_cast<GDIMetaFile&>(rMtf).FirstAction(); 86cdf0e10cSrcweir pCurrAct; 87cdf0e10cSrcweir pCurrAct = const_cast<GDIMetaFile&>(rMtf).NextAction() ) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir switch( pCurrAct->GetType() ) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir case META_RASTEROP_ACTION: 92cdf0e10cSrcweir // overpaint is okay - that's the default, anyway 93cdf0e10cSrcweir if( ROP_OVERPAINT == 94cdf0e10cSrcweir static_cast<MetaRasterOpAction*>(pCurrAct)->GetRasterOp() ) 95cdf0e10cSrcweir { 96cdf0e10cSrcweir break; 97cdf0e10cSrcweir } 98cdf0e10cSrcweir // FALLTHROUGH intended 99cdf0e10cSrcweir case META_MOVECLIPREGION_ACTION: 100cdf0e10cSrcweir // FALLTHROUGH intended 101cdf0e10cSrcweir case META_REFPOINT_ACTION: 102cdf0e10cSrcweir // FALLTHROUGH intended 103cdf0e10cSrcweir case META_WALLPAPER_ACTION: 104cdf0e10cSrcweir return true; // at least one unsupported 105cdf0e10cSrcweir // action encountered 106cdf0e10cSrcweir } 107cdf0e10cSrcweir } 108cdf0e10cSrcweir 109cdf0e10cSrcweir return false; // no unsupported action found 110cdf0e10cSrcweir } 111cdf0e10cSrcweir 112cdf0e10cSrcweir namespace { 113cdf0e10cSrcweir 114cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelper1< graphic::XGraphicRenderer > DummyRenderer_Base; 115cdf0e10cSrcweir 116cdf0e10cSrcweir class DummyRenderer : 117cdf0e10cSrcweir public DummyRenderer_Base, 118cdf0e10cSrcweir public cppu::BaseMutex 119cdf0e10cSrcweir { 120cdf0e10cSrcweir public: 121cdf0e10cSrcweir DummyRenderer() : 122cdf0e10cSrcweir DummyRenderer_Base( m_aMutex ), 123cdf0e10cSrcweir mxGraphic() 124cdf0e10cSrcweir { 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir //--- XGraphicRenderer ----------------------------------- 128cdf0e10cSrcweir virtual void SAL_CALL render( const uno::Reference< graphic::XGraphic >& rGraphic ) throw (uno::RuntimeException) 129cdf0e10cSrcweir { 130cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 131cdf0e10cSrcweir mxGraphic = rGraphic; 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir /** Retrieve GDIMetaFile from renderer 135cdf0e10cSrcweir 136cdf0e10cSrcweir @param bForeignSource 137cdf0e10cSrcweir When true, the source of the metafile might be a 138cdf0e10cSrcweir foreign application. The metafile is checked 139cdf0e10cSrcweir against unsupported content, and, if necessary, 140cdf0e10cSrcweir returned as a pre-rendererd bitmap. 141cdf0e10cSrcweir */ 142cdf0e10cSrcweir GDIMetaFile getMtf( bool bForeignSource ) const 143cdf0e10cSrcweir { 144cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 145cdf0e10cSrcweir 146cdf0e10cSrcweir Graphic aGraphic( mxGraphic ); 147cdf0e10cSrcweir 148cdf0e10cSrcweir if( aGraphic.GetType() == GRAPHIC_BITMAP || 149cdf0e10cSrcweir (bForeignSource && 150cdf0e10cSrcweir hasUnsupportedActions(aGraphic.GetGDIMetaFile()) ) ) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir // wrap bitmap into GDIMetafile 153cdf0e10cSrcweir GDIMetaFile aMtf; 154cdf0e10cSrcweir ::Point aEmptyPoint; 155cdf0e10cSrcweir 156cdf0e10cSrcweir ::BitmapEx aBmpEx( aGraphic.GetBitmapEx() ); 157cdf0e10cSrcweir 158cdf0e10cSrcweir aMtf.AddAction( new MetaBmpExAction( aEmptyPoint, 159cdf0e10cSrcweir aBmpEx ) ); 160cdf0e10cSrcweir aMtf.SetPrefSize( aBmpEx.GetPrefSize() ); 161cdf0e10cSrcweir aMtf.SetPrefMapMode( aBmpEx.GetPrefMapMode() ); 162cdf0e10cSrcweir 163cdf0e10cSrcweir return aMtf; 164cdf0e10cSrcweir } 165cdf0e10cSrcweir else 166cdf0e10cSrcweir { 167cdf0e10cSrcweir return aGraphic.GetGDIMetaFile(); 168cdf0e10cSrcweir } 169cdf0e10cSrcweir } 170cdf0e10cSrcweir 171cdf0e10cSrcweir private: 172cdf0e10cSrcweir uno::Reference< graphic::XGraphic > mxGraphic; 173cdf0e10cSrcweir }; 174cdf0e10cSrcweir 175cdf0e10cSrcweir } // anon namespace 176cdf0e10cSrcweir 177cdf0e10cSrcweir // Quick'n'dirty way: tunnel Graphic (only works for 178cdf0e10cSrcweir // in-process slideshow, of course) 179cdf0e10cSrcweir bool getMetaFile( const uno::Reference< lang::XComponent >& xSource, 180cdf0e10cSrcweir const uno::Reference< drawing::XDrawPage >& xContainingPage, 181cdf0e10cSrcweir GDIMetaFile& rMtf, 182cdf0e10cSrcweir int mtfLoadFlags, 183cdf0e10cSrcweir const uno::Reference< uno::XComponentContext >& rxContext ) 184cdf0e10cSrcweir { 185cdf0e10cSrcweir ENSURE_OR_RETURN_FALSE( rxContext.is(), 186cdf0e10cSrcweir "getMetaFile(): Invalid context" ); 187cdf0e10cSrcweir 188cdf0e10cSrcweir // create dummy XGraphicRenderer, which receives the 189cdf0e10cSrcweir // generated XGraphic from the GraphicExporter 190cdf0e10cSrcweir 191cdf0e10cSrcweir // TODO(P3): Move creation of DummyRenderer out of the 192cdf0e10cSrcweir // loop! Either by making it static, or transforming 193cdf0e10cSrcweir // the whole thing here into a class. 194cdf0e10cSrcweir DummyRenderer* pRenderer( new DummyRenderer() ); 195cdf0e10cSrcweir uno::Reference< graphic::XGraphicRenderer > xRenderer( pRenderer ); 196cdf0e10cSrcweir 197cdf0e10cSrcweir // -> stuff that into UnoGraphicExporter. 198cdf0e10cSrcweir uno::Reference<lang::XMultiComponentFactory> xFactory( 199cdf0e10cSrcweir rxContext->getServiceManager() ); 200cdf0e10cSrcweir 201cdf0e10cSrcweir OSL_ENSURE( xFactory.is(), "### no UNO?!" ); 202cdf0e10cSrcweir if( !xFactory.is() ) 203cdf0e10cSrcweir return false; 204cdf0e10cSrcweir 205cdf0e10cSrcweir // creating the graphic exporter 206cdf0e10cSrcweir uno::Reference< document::XExporter > xExporter( 207cdf0e10cSrcweir xFactory->createInstanceWithContext( 208cdf0e10cSrcweir OUSTR("com.sun.star.drawing.GraphicExportFilter"), 209cdf0e10cSrcweir rxContext), 210cdf0e10cSrcweir uno::UNO_QUERY ); 211cdf0e10cSrcweir uno::Reference< document::XFilter > xFilter( xExporter, uno::UNO_QUERY ); 212cdf0e10cSrcweir 213cdf0e10cSrcweir OSL_ENSURE( xExporter.is() && xFilter.is(), "### no graphic exporter?!" ); 214cdf0e10cSrcweir if( !xExporter.is() || !xFilter.is() ) 215cdf0e10cSrcweir return false; 216cdf0e10cSrcweir 217cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aProps(3); 218cdf0e10cSrcweir aProps[0].Name = OUSTR("FilterName"); 219cdf0e10cSrcweir aProps[0].Value <<= OUSTR("SVM"); 220cdf0e10cSrcweir 221cdf0e10cSrcweir aProps[1].Name = OUSTR("GraphicRenderer"); 222cdf0e10cSrcweir aProps[1].Value <<= xRenderer; 223cdf0e10cSrcweir 224cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aFilterData(5); 225cdf0e10cSrcweir aFilterData[0].Name = OUSTR("VerboseComments"); 226cdf0e10cSrcweir aFilterData[0].Value <<= ((mtfLoadFlags & MTF_LOAD_VERBOSE_COMMENTS) != 0); 227cdf0e10cSrcweir 228cdf0e10cSrcweir aFilterData[1].Name = OUSTR("ScrollText"); 229cdf0e10cSrcweir aFilterData[1].Value <<= ((mtfLoadFlags & MTF_LOAD_SCROLL_TEXT_MTF) != 0); 230cdf0e10cSrcweir 231cdf0e10cSrcweir aFilterData[2].Name = OUSTR("ExportOnlyBackground"); 232cdf0e10cSrcweir aFilterData[2].Value <<= ((mtfLoadFlags & MTF_LOAD_BACKGROUND_ONLY) != 0); 233cdf0e10cSrcweir 234cdf0e10cSrcweir aFilterData[3].Name = OUSTR("Version"); 235cdf0e10cSrcweir aFilterData[3].Value <<= static_cast<sal_Int32>( SOFFICE_FILEFORMAT_50 ); 236cdf0e10cSrcweir 237cdf0e10cSrcweir aFilterData[4].Name = OUSTR("CurrentPage"); 238cdf0e10cSrcweir aFilterData[4].Value <<= uno::Reference< uno::XInterface >( xContainingPage, 239cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 240cdf0e10cSrcweir 241cdf0e10cSrcweir aProps[2].Name = OUSTR("FilterData"); 242cdf0e10cSrcweir aProps[2].Value <<= aFilterData; 243cdf0e10cSrcweir 244cdf0e10cSrcweir xExporter->setSourceDocument( xSource ); 245cdf0e10cSrcweir if( !xFilter->filter( aProps ) ) 246cdf0e10cSrcweir return false; 247cdf0e10cSrcweir 248cdf0e10cSrcweir rMtf = pRenderer->getMtf( (mtfLoadFlags & MTF_LOAD_FOREIGN_SOURCE) != 0 ); 249cdf0e10cSrcweir 250cdf0e10cSrcweir // pRenderer is automatically destroyed when xRenderer 251cdf0e10cSrcweir // goes out of scope 252cdf0e10cSrcweir 253cdf0e10cSrcweir // TODO(E3): Error handling. Exporter might have 254cdf0e10cSrcweir // generated nothing, a bitmap, threw an exception, 255cdf0e10cSrcweir // whatever. 256cdf0e10cSrcweir return true; 257cdf0e10cSrcweir } 258cdf0e10cSrcweir 259cdf0e10cSrcweir void removeTextActions( GDIMetaFile& rMtf ) 260cdf0e10cSrcweir { 261cdf0e10cSrcweir // search metafile for text output 262cdf0e10cSrcweir MetaAction* pCurrAct; 263cdf0e10cSrcweir 264cdf0e10cSrcweir int nActionIndex(0); 265cdf0e10cSrcweir pCurrAct = rMtf.FirstAction(); 266cdf0e10cSrcweir while( pCurrAct ) 267cdf0e10cSrcweir { 268cdf0e10cSrcweir switch( pCurrAct->GetType() ) 269cdf0e10cSrcweir { 270cdf0e10cSrcweir case META_TEXTCOLOR_ACTION: 271cdf0e10cSrcweir case META_TEXTFILLCOLOR_ACTION: 272cdf0e10cSrcweir case META_TEXTLINECOLOR_ACTION: 273cdf0e10cSrcweir case META_TEXTALIGN_ACTION: 274cdf0e10cSrcweir case META_FONT_ACTION: 275cdf0e10cSrcweir case META_LAYOUTMODE_ACTION: 276cdf0e10cSrcweir case META_TEXT_ACTION: 277cdf0e10cSrcweir case META_TEXTARRAY_ACTION: 278cdf0e10cSrcweir case META_TEXTRECT_ACTION: 279cdf0e10cSrcweir case META_STRETCHTEXT_ACTION: 280cdf0e10cSrcweir case META_TEXTLINE_ACTION: 281cdf0e10cSrcweir { 282cdf0e10cSrcweir // remove every text-related actions 283cdf0e10cSrcweir pCurrAct = rMtf.NextAction(); 284cdf0e10cSrcweir 285cdf0e10cSrcweir rMtf.RemoveAction( nActionIndex ); 286cdf0e10cSrcweir break; 287cdf0e10cSrcweir } 288cdf0e10cSrcweir 289cdf0e10cSrcweir default: 290cdf0e10cSrcweir pCurrAct = rMtf.NextAction(); 291cdf0e10cSrcweir ++nActionIndex; 292cdf0e10cSrcweir break; 293cdf0e10cSrcweir } 294cdf0e10cSrcweir } 295cdf0e10cSrcweir } 296cdf0e10cSrcweir 297cdf0e10cSrcweir sal_Int32 getNextActionOffset( MetaAction * pCurrAct ) 298cdf0e10cSrcweir { 299cdf0e10cSrcweir // Special handling for actions that represent 300cdf0e10cSrcweir // more than one indexable action 301cdf0e10cSrcweir // =========================================== 302cdf0e10cSrcweir 303cdf0e10cSrcweir switch (pCurrAct->GetType()) { 304cdf0e10cSrcweir case META_TEXT_ACTION: { 305cdf0e10cSrcweir MetaTextAction * pAct = static_cast<MetaTextAction *>(pCurrAct); 306cdf0e10cSrcweir return (pAct->GetLen() == (sal_uInt16)STRING_LEN 307cdf0e10cSrcweir ? pAct->GetText().Len() - pAct->GetIndex() : pAct->GetLen()); 308cdf0e10cSrcweir } 309cdf0e10cSrcweir case META_TEXTARRAY_ACTION: { 310cdf0e10cSrcweir MetaTextArrayAction * pAct = 311cdf0e10cSrcweir static_cast<MetaTextArrayAction *>(pCurrAct); 312cdf0e10cSrcweir return (pAct->GetLen() == (sal_uInt16)STRING_LEN 313cdf0e10cSrcweir ? pAct->GetText().Len() - pAct->GetIndex() : pAct->GetLen()); 314cdf0e10cSrcweir } 315cdf0e10cSrcweir case META_STRETCHTEXT_ACTION: { 316cdf0e10cSrcweir MetaStretchTextAction * pAct = 317cdf0e10cSrcweir static_cast<MetaStretchTextAction *>(pCurrAct); 318cdf0e10cSrcweir return (pAct->GetLen() == (sal_uInt16)STRING_LEN 319cdf0e10cSrcweir ? pAct->GetText().Len() - pAct->GetIndex() : pAct->GetLen()); 320cdf0e10cSrcweir } 321cdf0e10cSrcweir case META_FLOATTRANSPARENT_ACTION: { 322cdf0e10cSrcweir MetaFloatTransparentAction * pAct = 323cdf0e10cSrcweir static_cast<MetaFloatTransparentAction*>(pCurrAct); 324cdf0e10cSrcweir // TODO(F2): Recurse into action metafile 325cdf0e10cSrcweir // (though this is currently not used from the 326cdf0e10cSrcweir // DrawingLayer - shape transparency gradients 327cdf0e10cSrcweir // don't affect shape text) 328cdf0e10cSrcweir return pAct->GetGDIMetaFile().GetActionCount(); 329cdf0e10cSrcweir } 330cdf0e10cSrcweir default: 331cdf0e10cSrcweir return 1; 332cdf0e10cSrcweir } 333cdf0e10cSrcweir } 334cdf0e10cSrcweir 335cdf0e10cSrcweir bool getAnimationFromGraphic( VectorOfMtfAnimationFrames& o_rFrames, 336cdf0e10cSrcweir ::std::size_t& o_rLoopCount, 337cdf0e10cSrcweir CycleMode& o_eCycleMode, 338cdf0e10cSrcweir const Graphic& rGraphic ) 339cdf0e10cSrcweir { 340cdf0e10cSrcweir o_rFrames.clear(); 341cdf0e10cSrcweir 342cdf0e10cSrcweir if( !rGraphic.IsAnimated() ) 343cdf0e10cSrcweir return false; 344cdf0e10cSrcweir 345cdf0e10cSrcweir // some loop invariants 346cdf0e10cSrcweir Animation aAnimation( rGraphic.GetAnimation() ); 347cdf0e10cSrcweir const Point aEmptyPoint; 348cdf0e10cSrcweir const Size aAnimSize( aAnimation.GetDisplaySizePixel() ); 349cdf0e10cSrcweir 350cdf0e10cSrcweir // setup VDev, into which all bitmaps are painted (want to 351cdf0e10cSrcweir // normalize animations to n bitmaps of same size. An Animation, 352cdf0e10cSrcweir // though, can contain bitmaps of varying sizes and different 353cdf0e10cSrcweir // update modes) 354cdf0e10cSrcweir VirtualDevice aVDev; 355cdf0e10cSrcweir aVDev.SetOutputSizePixel( aAnimSize ); 356cdf0e10cSrcweir aVDev.EnableMapMode( sal_False ); 357cdf0e10cSrcweir 358cdf0e10cSrcweir // setup mask VDev (alpha VDev is currently rather slow) 359cdf0e10cSrcweir VirtualDevice aVDevMask; 360cdf0e10cSrcweir aVDevMask.SetOutputSizePixel( aAnimSize ); 361cdf0e10cSrcweir aVDevMask.EnableMapMode( sal_False ); 362cdf0e10cSrcweir 363cdf0e10cSrcweir switch( aAnimation.GetCycleMode() ) 364cdf0e10cSrcweir { 365cdf0e10cSrcweir case CYCLE_NOT: 366cdf0e10cSrcweir o_rLoopCount = 1; 367cdf0e10cSrcweir o_eCycleMode = CYCLE_LOOP; 368cdf0e10cSrcweir break; 369cdf0e10cSrcweir 370cdf0e10cSrcweir case CYCLE_FALLBACK: 371cdf0e10cSrcweir // FALLTHROUGH intended 372cdf0e10cSrcweir case CYCLE_NORMAL: 373cdf0e10cSrcweir o_rLoopCount = aAnimation.GetLoopCount(); 374cdf0e10cSrcweir o_eCycleMode = CYCLE_LOOP; 375cdf0e10cSrcweir break; 376cdf0e10cSrcweir 377cdf0e10cSrcweir case CYCLE_REVERS: 378cdf0e10cSrcweir // FALLTHROUGH intended 379cdf0e10cSrcweir case CYCLE_REVERS_FALLBACK: 380cdf0e10cSrcweir o_rLoopCount = aAnimation.GetLoopCount(); 381cdf0e10cSrcweir o_eCycleMode = CYCLE_PINGPONGLOOP; 382cdf0e10cSrcweir break; 383cdf0e10cSrcweir 384cdf0e10cSrcweir default: 385cdf0e10cSrcweir ENSURE_OR_RETURN_FALSE(false, 386cdf0e10cSrcweir "getAnimationFromGraphic(): Unexpected case" ); 387cdf0e10cSrcweir break; 388cdf0e10cSrcweir } 389cdf0e10cSrcweir 390cdf0e10cSrcweir for( sal_uInt16 i=0, nCount=aAnimation.Count(); i<nCount; ++i ) 391cdf0e10cSrcweir { 392cdf0e10cSrcweir const AnimationBitmap& rAnimBmp( aAnimation.Get(i) ); 393cdf0e10cSrcweir switch(rAnimBmp.eDisposal) 394cdf0e10cSrcweir { 395cdf0e10cSrcweir case DISPOSE_NOT: 396cdf0e10cSrcweir { 397cdf0e10cSrcweir aVDev.DrawBitmapEx(rAnimBmp.aPosPix, 398cdf0e10cSrcweir rAnimBmp.aBmpEx); 399cdf0e10cSrcweir Bitmap aMask = rAnimBmp.aBmpEx.GetMask(); 400cdf0e10cSrcweir 401cdf0e10cSrcweir if( aMask.IsEmpty() ) 402cdf0e10cSrcweir { 403cdf0e10cSrcweir const Point aEmpty; 404cdf0e10cSrcweir const Rectangle aRect(aEmptyPoint, 405cdf0e10cSrcweir aVDevMask.GetOutputSizePixel()); 406cdf0e10cSrcweir const Wallpaper aWallpaper(COL_BLACK); 407cdf0e10cSrcweir aVDevMask.DrawWallpaper(aRect, 408cdf0e10cSrcweir aWallpaper); 409cdf0e10cSrcweir } 410cdf0e10cSrcweir else 411cdf0e10cSrcweir { 412cdf0e10cSrcweir BitmapEx aTmpMask = BitmapEx(aMask, 413cdf0e10cSrcweir aMask); 414cdf0e10cSrcweir aVDevMask.DrawBitmapEx(rAnimBmp.aPosPix, 415cdf0e10cSrcweir aTmpMask ); 416cdf0e10cSrcweir } 417cdf0e10cSrcweir break; 418cdf0e10cSrcweir } 419cdf0e10cSrcweir 420cdf0e10cSrcweir case DISPOSE_BACK: 421cdf0e10cSrcweir { 422cdf0e10cSrcweir // #i70772# react on no mask 423cdf0e10cSrcweir const Bitmap aMask(rAnimBmp.aBmpEx.GetMask()); 424cdf0e10cSrcweir const Bitmap aContent(rAnimBmp.aBmpEx.GetBitmap()); 425cdf0e10cSrcweir 426cdf0e10cSrcweir aVDevMask.Erase(); 427cdf0e10cSrcweir aVDev.DrawBitmap(rAnimBmp.aPosPix, aContent); 428cdf0e10cSrcweir 429cdf0e10cSrcweir if(aMask.IsEmpty()) 430cdf0e10cSrcweir { 431cdf0e10cSrcweir const Rectangle aRect(rAnimBmp.aPosPix, aContent.GetSizePixel()); 432cdf0e10cSrcweir aVDevMask.SetFillColor(COL_BLACK); 433cdf0e10cSrcweir aVDevMask.SetLineColor(); 434cdf0e10cSrcweir aVDevMask.DrawRect(aRect); 435cdf0e10cSrcweir } 436cdf0e10cSrcweir else 437cdf0e10cSrcweir { 438cdf0e10cSrcweir aVDevMask.DrawBitmap(rAnimBmp.aPosPix, aMask); 439cdf0e10cSrcweir } 440cdf0e10cSrcweir break; 441cdf0e10cSrcweir } 442cdf0e10cSrcweir 443cdf0e10cSrcweir case DISPOSE_FULL: 444cdf0e10cSrcweir { 445cdf0e10cSrcweir aVDev.DrawBitmapEx(rAnimBmp.aPosPix, 446cdf0e10cSrcweir rAnimBmp.aBmpEx); 447cdf0e10cSrcweir break; 448cdf0e10cSrcweir } 449cdf0e10cSrcweir 450cdf0e10cSrcweir case DISPOSE_PREVIOUS : 451cdf0e10cSrcweir { 452cdf0e10cSrcweir aVDev.DrawBitmapEx(rAnimBmp.aPosPix, 453cdf0e10cSrcweir rAnimBmp.aBmpEx); 454cdf0e10cSrcweir aVDevMask.DrawBitmap(rAnimBmp.aPosPix, 455cdf0e10cSrcweir rAnimBmp.aBmpEx.GetMask()); 456cdf0e10cSrcweir break; 457cdf0e10cSrcweir } 458cdf0e10cSrcweir } 459cdf0e10cSrcweir 460cdf0e10cSrcweir // extract current aVDev content into a new animation 461cdf0e10cSrcweir // frame 462cdf0e10cSrcweir GDIMetaFileSharedPtr pMtf( new GDIMetaFile() ); 463cdf0e10cSrcweir pMtf->AddAction( 464cdf0e10cSrcweir new MetaBmpExAction( aEmptyPoint, 465cdf0e10cSrcweir BitmapEx( 466cdf0e10cSrcweir aVDev.GetBitmap( 467cdf0e10cSrcweir aEmptyPoint, 468cdf0e10cSrcweir aAnimSize ), 469cdf0e10cSrcweir aVDevMask.GetBitmap( 470cdf0e10cSrcweir aEmptyPoint, 471cdf0e10cSrcweir aAnimSize )))); 472cdf0e10cSrcweir 473cdf0e10cSrcweir // setup mtf dimensions and pref map mode (for 474cdf0e10cSrcweir // simplicity, keep it all in pixel. the metafile 475cdf0e10cSrcweir // renderer scales it down to (1, 1) box anyway) 476cdf0e10cSrcweir pMtf->SetPrefMapMode( MapMode() ); 477cdf0e10cSrcweir pMtf->SetPrefSize( aAnimSize ); 478cdf0e10cSrcweir 479cdf0e10cSrcweir // #115934# 480cdf0e10cSrcweir // Take care of special value for MultiPage TIFFs. ATM these shall just 481cdf0e10cSrcweir // show their first page for _quite_ some time. 482cdf0e10cSrcweir sal_Int32 nWaitTime100thSeconds( rAnimBmp.nWait ); 483cdf0e10cSrcweir if( ANIMATION_TIMEOUT_ON_CLICK == nWaitTime100thSeconds ) 484cdf0e10cSrcweir { 485cdf0e10cSrcweir // ATM the huge value would block the timer, so use a long 486cdf0e10cSrcweir // time to show first page (whole day) 487cdf0e10cSrcweir nWaitTime100thSeconds = 100 * 60 * 60 * 24; 488cdf0e10cSrcweir } 489cdf0e10cSrcweir 490cdf0e10cSrcweir // There are animated GIFs with no WaitTime set. Take 0.1 sec, the 491cdf0e10cSrcweir // same duration that is used by the edit view. 492cdf0e10cSrcweir if( nWaitTime100thSeconds == 0 ) 493cdf0e10cSrcweir nWaitTime100thSeconds = 10; 494cdf0e10cSrcweir 495cdf0e10cSrcweir o_rFrames.push_back( MtfAnimationFrame( pMtf, 496cdf0e10cSrcweir nWaitTime100thSeconds / 100.0 ) ); 497cdf0e10cSrcweir } 498cdf0e10cSrcweir 499cdf0e10cSrcweir return !o_rFrames.empty(); 500cdf0e10cSrcweir } 501cdf0e10cSrcweir 502cdf0e10cSrcweir bool getRectanglesFromScrollMtf( ::basegfx::B2DRectangle& o_rScrollRect, 503cdf0e10cSrcweir ::basegfx::B2DRectangle& o_rPaintRect, 504cdf0e10cSrcweir const GDIMetaFileSharedPtr& rMtf ) 505cdf0e10cSrcweir { 506cdf0e10cSrcweir // extract bounds: scroll rect, paint rect 507cdf0e10cSrcweir bool bScrollRectSet(false); 508cdf0e10cSrcweir bool bPaintRectSet(false); 509cdf0e10cSrcweir 510cdf0e10cSrcweir for ( MetaAction * pCurrAct = rMtf->FirstAction(); 511cdf0e10cSrcweir pCurrAct != 0; pCurrAct = rMtf->NextAction() ) 512cdf0e10cSrcweir { 513cdf0e10cSrcweir if (pCurrAct->GetType() == META_COMMENT_ACTION) 514cdf0e10cSrcweir { 515cdf0e10cSrcweir MetaCommentAction * pAct = 516cdf0e10cSrcweir static_cast<MetaCommentAction *>(pCurrAct); 517cdf0e10cSrcweir // skip comment if not a special XTEXT comment 518cdf0e10cSrcweir if (pAct->GetComment().CompareIgnoreCaseToAscii( 519cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("XTEXT") ) == COMPARE_EQUAL) 520cdf0e10cSrcweir { 521cdf0e10cSrcweir if (pAct->GetComment().CompareIgnoreCaseToAscii( 522cdf0e10cSrcweir "XTEXT_SCROLLRECT" ) == COMPARE_EQUAL) { 523cdf0e10cSrcweir o_rScrollRect = ::vcl::unotools::b2DRectangleFromRectangle( 524cdf0e10cSrcweir *reinterpret_cast<Rectangle const *>( 525cdf0e10cSrcweir pAct->GetData() ) ); 526cdf0e10cSrcweir 527cdf0e10cSrcweir bScrollRectSet = true; 528cdf0e10cSrcweir } 529cdf0e10cSrcweir else if (pAct->GetComment().CompareIgnoreCaseToAscii( 530cdf0e10cSrcweir "XTEXT_PAINTRECT" ) == COMPARE_EQUAL) { 531cdf0e10cSrcweir o_rPaintRect = ::vcl::unotools::b2DRectangleFromRectangle( 532cdf0e10cSrcweir *reinterpret_cast<Rectangle const *>( 533cdf0e10cSrcweir pAct->GetData() ) ); 534cdf0e10cSrcweir 535cdf0e10cSrcweir bPaintRectSet = true; 536cdf0e10cSrcweir } 537cdf0e10cSrcweir } 538cdf0e10cSrcweir } 539cdf0e10cSrcweir } 540cdf0e10cSrcweir 541cdf0e10cSrcweir return bScrollRectSet && bPaintRectSet; 542cdf0e10cSrcweir } 543cdf0e10cSrcweir 544cdf0e10cSrcweir } 545cdf0e10cSrcweir } 546cdf0e10cSrcweir 547