1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_slideshow.hxx"
30 
31 // must be first
32 #include <canvas/debug.hxx>
33 #include <tools/diagnose_ex.h>
34 #include <slidebitmap.hxx>
35 
36 #include <com/sun/star/rendering/XCanvas.hpp>
37 #include <com/sun/star/rendering/XBitmap.hpp>
38 #include <comphelper/anytostring.hxx>
39 #include <cppuhelper/exc_hlp.hxx>
40 
41 #include <basegfx/matrix/b2dhommatrix.hxx>
42 #include <basegfx/matrix/b2dhommatrixtools.hxx>
43 
44 #include <canvas/canvastools.hxx>
45 #include <basegfx/tools/canvastools.hxx>
46 
47 
48 using namespace ::com::sun::star;
49 
50 namespace slideshow
51 {
52     namespace internal
53     {
54 
55         SlideBitmap::SlideBitmap( const ::cppcanvas::BitmapSharedPtr& rBitmap ) :
56             maOutputPos(),
57             maClipPoly(),
58             mxBitmap()
59         {
60             if( rBitmap )
61                 mxBitmap = rBitmap->getUNOBitmap();
62 
63             ENSURE_OR_THROW( mxBitmap.is(), "SlideBitmap::SlideBitmap(): Invalid bitmap" );
64         }
65 
66         bool SlideBitmap::draw( const ::cppcanvas::CanvasSharedPtr& rCanvas ) const
67         {
68             ENSURE_OR_RETURN_FALSE( rCanvas && rCanvas->getUNOCanvas().is(),
69                                "SlideBitmap::draw(): Invalid canvas" );
70 
71             // selectively only copy the transformation from current viewstate,
72             // don't want no clipping here.
73             rendering::ViewState aViewState;
74             aViewState.AffineTransform = rCanvas->getViewState().AffineTransform;
75 
76             rendering::RenderState aRenderState;
77             ::canvas::tools::initRenderState( aRenderState );
78 
79             const basegfx::B2DHomMatrix aTranslation(basegfx::tools::createTranslateB2DHomMatrix(maOutputPos));
80             ::canvas::tools::setRenderStateTransform( aRenderState, aTranslation );
81 
82             try
83             {
84                 if( maClipPoly.count() )
85                 {
86                     // TODO(P1): Buffer the clip polygon
87                     aRenderState.Clip =
88                         ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
89                             rCanvas->getUNOCanvas()->getDevice(),
90                             maClipPoly );
91                 }
92 
93                 rCanvas->getUNOCanvas()->drawBitmap( mxBitmap,
94                                                      aViewState,
95                                                      aRenderState );
96             }
97             catch( uno::Exception& )
98             {
99                 OSL_ENSURE( false,
100                             rtl::OUStringToOString(
101                                 comphelper::anyToString( cppu::getCaughtException() ),
102                                 RTL_TEXTENCODING_UTF8 ).getStr() );
103 
104                 return false;
105             }
106 
107             return true;
108         }
109 
110         ::basegfx::B2ISize SlideBitmap::getSize() const
111         {
112             return ::basegfx::unotools::b2ISizeFromIntegerSize2D( mxBitmap->getSize() );
113         }
114 
115         void SlideBitmap::move( const ::basegfx::B2DPoint& rNewPos )
116         {
117             maOutputPos = rNewPos;
118         }
119 
120         void SlideBitmap::clip( const ::basegfx::B2DPolyPolygon& rClipPoly )
121         {
122             maClipPoly = rClipPoly;
123         }
124 
125         ::com::sun::star::uno::Reference<
126                 ::com::sun::star::rendering::XBitmap >    SlideBitmap::getXBitmap()
127         {
128         return mxBitmap;
129         }
130 
131     }
132 }
133