merge the formfield patch from ooo-build
[ooovba.git] / slideshow / source / engine / slidebitmap.cxx
blobb33f90a33291704924d45c91418fa8de058c71ad
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: slidebitmap.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_slideshow.hxx"
34 // must be first
35 #include <canvas/debug.hxx>
36 #include <tools/diagnose_ex.h>
37 #include <slidebitmap.hxx>
39 #include <com/sun/star/rendering/XCanvas.hpp>
40 #include <com/sun/star/rendering/XBitmap.hpp>
41 #include <comphelper/anytostring.hxx>
42 #include <cppuhelper/exc_hlp.hxx>
44 #include <basegfx/matrix/b2dhommatrix.hxx>
46 #include <canvas/canvastools.hxx>
47 #include <basegfx/tools/canvastools.hxx>
50 using namespace ::com::sun::star;
52 namespace slideshow
54 namespace internal
57 SlideBitmap::SlideBitmap( const ::cppcanvas::BitmapSharedPtr& rBitmap ) :
58 maOutputPos(),
59 maClipPoly(),
60 mxBitmap()
62 if( rBitmap )
63 mxBitmap = rBitmap->getUNOBitmap();
65 ENSURE_OR_THROW( mxBitmap.is(), "SlideBitmap::SlideBitmap(): Invalid bitmap" );
68 bool SlideBitmap::draw( const ::cppcanvas::CanvasSharedPtr& rCanvas ) const
70 ENSURE_OR_RETURN( rCanvas && rCanvas->getUNOCanvas().is(),
71 "SlideBitmap::draw(): Invalid canvas" );
73 // selectively only copy the transformation from current viewstate,
74 // don't want no clipping here.
75 rendering::ViewState aViewState;
76 aViewState.AffineTransform = rCanvas->getViewState().AffineTransform;
78 rendering::RenderState aRenderState;
79 ::canvas::tools::initRenderState( aRenderState );
81 ::basegfx::B2DHomMatrix aTranslation;
82 aTranslation.translate( maOutputPos.getX(),
83 maOutputPos.getY() );
84 ::canvas::tools::setRenderStateTransform( aRenderState, aTranslation );
86 try
88 if( maClipPoly.count() )
90 // TODO(P1): Buffer the clip polygon
91 aRenderState.Clip =
92 ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
93 rCanvas->getUNOCanvas()->getDevice(),
94 maClipPoly );
97 rCanvas->getUNOCanvas()->drawBitmap( mxBitmap,
98 aViewState,
99 aRenderState );
101 catch( uno::Exception& )
103 OSL_ENSURE( false,
104 rtl::OUStringToOString(
105 comphelper::anyToString( cppu::getCaughtException() ),
106 RTL_TEXTENCODING_UTF8 ).getStr() );
108 return false;
111 return true;
114 ::basegfx::B2ISize SlideBitmap::getSize() const
116 return ::basegfx::unotools::b2ISizeFromIntegerSize2D( mxBitmap->getSize() );
119 void SlideBitmap::move( const ::basegfx::B2DPoint& rNewPos )
121 maOutputPos = rNewPos;
124 void SlideBitmap::clip( const ::basegfx::B2DPolyPolygon& rClipPoly )
126 maClipPoly = rClipPoly;
129 ::com::sun::star::uno::Reference<
130 ::com::sun::star::rendering::XBitmap > SlideBitmap::getXBitmap()
132 return mxBitmap;