Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / cppcanvas / source / wrapper / implbitmap.cxx
bloba95a36f250eaa62c55fc35a8510c587aad75bf27
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "implbitmap.hxx"
22 #include "implbitmapcanvas.hxx"
24 #include <basegfx/matrix/b2dhommatrix.hxx>
25 #include <canvas/canvastools.hxx>
28 using namespace ::com::sun::star;
30 namespace cppcanvas
33 namespace internal
36 ImplBitmap::ImplBitmap( const CanvasSharedPtr& rParentCanvas,
37 const uno::Reference< rendering::XBitmap >& rBitmap ) :
38 CanvasGraphicHelper( rParentCanvas ),
39 mxBitmap( rBitmap ),
40 mpBitmapCanvas()
42 OSL_ENSURE( mxBitmap.is(), "ImplBitmap::ImplBitmap: no valid bitmap" );
44 uno::Reference< rendering::XBitmapCanvas > xBitmapCanvas( rBitmap,
45 uno::UNO_QUERY );
46 if( xBitmapCanvas.is() )
47 mpBitmapCanvas.reset( new ImplBitmapCanvas(
48 uno::Reference< rendering::XBitmapCanvas >(rBitmap,
49 uno::UNO_QUERY) ) );
52 ImplBitmap::~ImplBitmap()
56 bool ImplBitmap::draw() const
58 CanvasSharedPtr pCanvas( getCanvas() );
60 OSL_ENSURE( pCanvas.get() != NULL &&
61 pCanvas->getUNOCanvas().is(),
62 "ImplBitmap::draw: invalid canvas" );
64 if( pCanvas.get() == NULL ||
65 !pCanvas->getUNOCanvas().is() )
67 return false;
70 // TODO(P1): implement caching
71 pCanvas->getUNOCanvas()->drawBitmap( mxBitmap,
72 pCanvas->getViewState(),
73 getRenderState() );
75 return true;
78 bool ImplBitmap::drawAlphaModulated( double nAlphaModulation ) const
80 CanvasSharedPtr pCanvas( getCanvas() );
82 OSL_ENSURE( pCanvas.get() != NULL &&
83 pCanvas->getUNOCanvas().is(),
84 "ImplBitmap::drawAlphaModulated(): invalid canvas" );
86 if( pCanvas.get() == NULL ||
87 !pCanvas->getUNOCanvas().is() )
89 return false;
92 rendering::RenderState aLocalState( getRenderState() );
93 uno::Sequence<rendering::ARGBColor> aCol(1);
94 aCol[0] = rendering::ARGBColor( nAlphaModulation, 1.0, 1.0, 1.0 );
95 aLocalState.DeviceColor =
96 pCanvas->getUNOCanvas()->getDevice()->getDeviceColorSpace()->convertFromARGB(aCol);
98 // TODO(P1): implement caching
99 pCanvas->getUNOCanvas()->drawBitmapModulated( mxBitmap,
100 pCanvas->getViewState(),
101 aLocalState );
103 return true;
106 BitmapCanvasSharedPtr ImplBitmap::getBitmapCanvas() const
108 return mpBitmapCanvas;
111 uno::Reference< rendering::XBitmap > ImplBitmap::getUNOBitmap() const
113 return mxBitmap;
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */