1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_slideshow.hxx"
26 
27 // must be first
28 #include <canvas/debug.hxx>
29 #include <tools/diagnose_ex.h>
30 #include <slidebitmap.hxx>
31 
32 #include <com/sun/star/rendering/XCanvas.hpp>
33 #include <com/sun/star/rendering/XBitmap.hpp>
34 #include <comphelper/anytostring.hxx>
35 #include <cppuhelper/exc_hlp.hxx>
36 
37 #include <basegfx/matrix/b2dhommatrix.hxx>
38 #include <basegfx/matrix/b2dhommatrixtools.hxx>
39 
40 #include <canvas/canvastools.hxx>
41 #include <basegfx/tools/canvastools.hxx>
42 
43 
44 using namespace ::com::sun::star;
45 
46 namespace slideshow
47 {
48     namespace internal
49     {
50 
SlideBitmap(const::cppcanvas::BitmapSharedPtr & rBitmap)51         SlideBitmap::SlideBitmap( const ::cppcanvas::BitmapSharedPtr& rBitmap ) :
52             maOutputPos(),
53             maClipPoly(),
54             mxBitmap()
55         {
56             if( rBitmap )
57                 mxBitmap = rBitmap->getUNOBitmap();
58 
59             ENSURE_OR_THROW( mxBitmap.is(), "SlideBitmap::SlideBitmap(): Invalid bitmap" );
60         }
61 
draw(const::cppcanvas::CanvasSharedPtr & rCanvas) const62         bool SlideBitmap::draw( const ::cppcanvas::CanvasSharedPtr& rCanvas ) const
63         {
64             ENSURE_OR_RETURN_FALSE( rCanvas && rCanvas->getUNOCanvas().is(),
65                                "SlideBitmap::draw(): Invalid canvas" );
66 
67             // selectively only copy the transformation from current viewstate,
68             // don't want no clipping here.
69             rendering::ViewState aViewState;
70             aViewState.AffineTransform = rCanvas->getViewState().AffineTransform;
71 
72             rendering::RenderState aRenderState;
73             ::canvas::tools::initRenderState( aRenderState );
74 
75             const basegfx::B2DHomMatrix aTranslation(basegfx::tools::createTranslateB2DHomMatrix(maOutputPos));
76             ::canvas::tools::setRenderStateTransform( aRenderState, aTranslation );
77 
78             try
79             {
80                 if( maClipPoly.count() )
81                 {
82                     // TODO(P1): Buffer the clip polygon
83                     aRenderState.Clip =
84                         ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
85                             rCanvas->getUNOCanvas()->getDevice(),
86                             maClipPoly );
87                 }
88 
89                 rCanvas->getUNOCanvas()->drawBitmap( mxBitmap,
90                                                      aViewState,
91                                                      aRenderState );
92             }
93             catch( uno::Exception& )
94             {
95                 OSL_ENSURE( false,
96                             rtl::OUStringToOString(
97                                 comphelper::anyToString( cppu::getCaughtException() ),
98                                 RTL_TEXTENCODING_UTF8 ).getStr() );
99 
100                 return false;
101             }
102 
103             return true;
104         }
105 
getSize() const106         ::basegfx::B2ISize SlideBitmap::getSize() const
107         {
108             return ::basegfx::unotools::b2ISizeFromIntegerSize2D( mxBitmap->getSize() );
109         }
110 
move(const::basegfx::B2DPoint & rNewPos)111         void SlideBitmap::move( const ::basegfx::B2DPoint& rNewPos )
112         {
113             maOutputPos = rNewPos;
114         }
115 
clip(const::basegfx::B2DPolyPolygon & rClipPoly)116         void SlideBitmap::clip( const ::basegfx::B2DPolyPolygon& rClipPoly )
117         {
118             maClipPoly = rClipPoly;
119         }
120 
121         ::com::sun::star::uno::Reference<
getXBitmap()122                 ::com::sun::star::rendering::XBitmap >    SlideBitmap::getXBitmap()
123         {
124         return mxBitmap;
125         }
126 
127     }
128 }
129