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 10*70f497fbSAndrew Rist * 11*70f497fbSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*70f497fbSAndrew Rist * 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. 19*70f497fbSAndrew Rist * 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 <slidebitmap.hxx> 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <com/sun/star/rendering/XCanvas.hpp> 33cdf0e10cSrcweir #include <com/sun/star/rendering/XBitmap.hpp> 34cdf0e10cSrcweir #include <comphelper/anytostring.hxx> 35cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx> 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx> 38cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx> 39cdf0e10cSrcweir 40cdf0e10cSrcweir #include <canvas/canvastools.hxx> 41cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx> 42cdf0e10cSrcweir 43cdf0e10cSrcweir 44cdf0e10cSrcweir using namespace ::com::sun::star; 45cdf0e10cSrcweir 46cdf0e10cSrcweir namespace slideshow 47cdf0e10cSrcweir { 48cdf0e10cSrcweir namespace internal 49cdf0e10cSrcweir { 50cdf0e10cSrcweir SlideBitmap(const::cppcanvas::BitmapSharedPtr & rBitmap)51cdf0e10cSrcweir SlideBitmap::SlideBitmap( const ::cppcanvas::BitmapSharedPtr& rBitmap ) : 52cdf0e10cSrcweir maOutputPos(), 53cdf0e10cSrcweir maClipPoly(), 54cdf0e10cSrcweir mxBitmap() 55cdf0e10cSrcweir { 56cdf0e10cSrcweir if( rBitmap ) 57cdf0e10cSrcweir mxBitmap = rBitmap->getUNOBitmap(); 58cdf0e10cSrcweir 59cdf0e10cSrcweir ENSURE_OR_THROW( mxBitmap.is(), "SlideBitmap::SlideBitmap(): Invalid bitmap" ); 60cdf0e10cSrcweir } 61cdf0e10cSrcweir draw(const::cppcanvas::CanvasSharedPtr & rCanvas) const62cdf0e10cSrcweir bool SlideBitmap::draw( const ::cppcanvas::CanvasSharedPtr& rCanvas ) const 63cdf0e10cSrcweir { 64cdf0e10cSrcweir ENSURE_OR_RETURN_FALSE( rCanvas && rCanvas->getUNOCanvas().is(), 65cdf0e10cSrcweir "SlideBitmap::draw(): Invalid canvas" ); 66cdf0e10cSrcweir 67cdf0e10cSrcweir // selectively only copy the transformation from current viewstate, 68cdf0e10cSrcweir // don't want no clipping here. 69cdf0e10cSrcweir rendering::ViewState aViewState; 70cdf0e10cSrcweir aViewState.AffineTransform = rCanvas->getViewState().AffineTransform; 71cdf0e10cSrcweir 72cdf0e10cSrcweir rendering::RenderState aRenderState; 73cdf0e10cSrcweir ::canvas::tools::initRenderState( aRenderState ); 74cdf0e10cSrcweir 75cdf0e10cSrcweir const basegfx::B2DHomMatrix aTranslation(basegfx::tools::createTranslateB2DHomMatrix(maOutputPos)); 76cdf0e10cSrcweir ::canvas::tools::setRenderStateTransform( aRenderState, aTranslation ); 77cdf0e10cSrcweir 78cdf0e10cSrcweir try 79cdf0e10cSrcweir { 80cdf0e10cSrcweir if( maClipPoly.count() ) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir // TODO(P1): Buffer the clip polygon 83cdf0e10cSrcweir aRenderState.Clip = 84cdf0e10cSrcweir ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( 85cdf0e10cSrcweir rCanvas->getUNOCanvas()->getDevice(), 86cdf0e10cSrcweir maClipPoly ); 87cdf0e10cSrcweir } 88cdf0e10cSrcweir 89cdf0e10cSrcweir rCanvas->getUNOCanvas()->drawBitmap( mxBitmap, 90cdf0e10cSrcweir aViewState, 91cdf0e10cSrcweir aRenderState ); 92cdf0e10cSrcweir } 93cdf0e10cSrcweir catch( uno::Exception& ) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir OSL_ENSURE( false, 96cdf0e10cSrcweir rtl::OUStringToOString( 97cdf0e10cSrcweir comphelper::anyToString( cppu::getCaughtException() ), 98cdf0e10cSrcweir RTL_TEXTENCODING_UTF8 ).getStr() ); 99cdf0e10cSrcweir 100cdf0e10cSrcweir return false; 101cdf0e10cSrcweir } 102cdf0e10cSrcweir 103cdf0e10cSrcweir return true; 104cdf0e10cSrcweir } 105cdf0e10cSrcweir getSize() const106cdf0e10cSrcweir ::basegfx::B2ISize SlideBitmap::getSize() const 107cdf0e10cSrcweir { 108cdf0e10cSrcweir return ::basegfx::unotools::b2ISizeFromIntegerSize2D( mxBitmap->getSize() ); 109cdf0e10cSrcweir } 110cdf0e10cSrcweir move(const::basegfx::B2DPoint & rNewPos)111cdf0e10cSrcweir void SlideBitmap::move( const ::basegfx::B2DPoint& rNewPos ) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir maOutputPos = rNewPos; 114cdf0e10cSrcweir } 115cdf0e10cSrcweir clip(const::basegfx::B2DPolyPolygon & rClipPoly)116cdf0e10cSrcweir void SlideBitmap::clip( const ::basegfx::B2DPolyPolygon& rClipPoly ) 117cdf0e10cSrcweir { 118cdf0e10cSrcweir maClipPoly = rClipPoly; 119cdf0e10cSrcweir } 120cdf0e10cSrcweir 121cdf0e10cSrcweir ::com::sun::star::uno::Reference< getXBitmap()122cdf0e10cSrcweir ::com::sun::star::rendering::XBitmap > SlideBitmap::getXBitmap() 123cdf0e10cSrcweir { 124cdf0e10cSrcweir return mxBitmap; 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir } 128cdf0e10cSrcweir } 129