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