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_cppcanvas.hxx"
30 
31 #include "implbitmap.hxx"
32 #include "implbitmapcanvas.hxx"
33 
34 #include <basegfx/matrix/b2dhommatrix.hxx>
35 #include <canvas/canvastools.hxx>
36 
37 
38 using namespace ::com::sun::star;
39 
40 namespace cppcanvas
41 {
42 
43     namespace internal
44     {
45 
46         ImplBitmap::ImplBitmap( const CanvasSharedPtr& 						rParentCanvas,
47                                 const uno::Reference< rendering::XBitmap >& rBitmap ) :
48             CanvasGraphicHelper( rParentCanvas ),
49             mxBitmap( rBitmap ),
50             mpBitmapCanvas()
51         {
52             OSL_ENSURE( mxBitmap.is(), "ImplBitmap::ImplBitmap: no valid bitmap" );
53 
54             uno::Reference< rendering::XBitmapCanvas > xBitmapCanvas( rBitmap,
55                                                                       uno::UNO_QUERY );
56             if( xBitmapCanvas.is() )
57                 mpBitmapCanvas.reset( new ImplBitmapCanvas(
58                                           uno::Reference< rendering::XBitmapCanvas >(rBitmap,
59                                                                                      uno::UNO_QUERY) ) );
60         }
61 
62         ImplBitmap::~ImplBitmap()
63         {
64         }
65 
66         bool ImplBitmap::draw() const
67         {
68             CanvasSharedPtr pCanvas( getCanvas() );
69 
70             OSL_ENSURE( pCanvas.get() != NULL &&
71                         pCanvas->getUNOCanvas().is(),
72                         "ImplBitmap::draw: invalid canvas" );
73 
74             if( pCanvas.get() == NULL ||
75                 !pCanvas->getUNOCanvas().is() )
76             {
77                 return false;
78             }
79 
80             // TODO(P1): implement caching
81             pCanvas->getUNOCanvas()->drawBitmap( mxBitmap,
82                                                  pCanvas->getViewState(),
83                                                  getRenderState() );
84 
85             return true;
86         }
87 
88         bool ImplBitmap::drawAlphaModulated( double nAlphaModulation ) const
89         {
90             CanvasSharedPtr pCanvas( getCanvas() );
91 
92             OSL_ENSURE( pCanvas.get() != NULL &&
93                         pCanvas->getUNOCanvas().is(),
94                         "ImplBitmap::drawAlphaModulated(): invalid canvas" );
95 
96             if( pCanvas.get() == NULL ||
97                 !pCanvas->getUNOCanvas().is() )
98             {
99                 return false;
100             }
101 
102             rendering::RenderState aLocalState( getRenderState() );
103             uno::Sequence<rendering::ARGBColor> aCol(1);
104             aCol[0] = rendering::ARGBColor( nAlphaModulation, 1.0, 1.0, 1.0 );
105             aLocalState.DeviceColor =
106                 pCanvas->getUNOCanvas()->getDevice()->getDeviceColorSpace()->convertFromARGB(aCol);
107 
108             // TODO(P1): implement caching
109             pCanvas->getUNOCanvas()->drawBitmapModulated( mxBitmap,
110                                                           pCanvas->getViewState(),
111                                                           aLocalState );
112 
113             return true;
114         }
115 
116         BitmapCanvasSharedPtr ImplBitmap::getBitmapCanvas() const
117         {
118             return mpBitmapCanvas;
119         }
120 
121         uno::Reference< rendering::XBitmap > ImplBitmap::getUNOBitmap() const
122         {
123             return mxBitmap;
124         }
125     }
126 }
127