Get the style color and number just once
[LibreOffice.git] / cppcanvas / source / wrapper / implbitmap.cxx
blob4b46ecb657b37e0d2ae248e103215591e77950d6
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 <osl/diagnose.h>
27 using namespace ::com::sun::star;
29 namespace cppcanvas::internal
32 ImplBitmap::ImplBitmap( const CanvasSharedPtr& rParentCanvas,
33 const uno::Reference< rendering::XBitmap >& rBitmap ) :
34 CanvasGraphicHelper( rParentCanvas ),
35 mxBitmap( rBitmap )
37 OSL_ENSURE( mxBitmap.is(), "ImplBitmap::ImplBitmap: no valid bitmap" );
39 uno::Reference< rendering::XBitmapCanvas > xBitmapCanvas( rBitmap,
40 uno::UNO_QUERY );
41 if( xBitmapCanvas.is() )
42 mpBitmapCanvas = std::make_shared<ImplBitmapCanvas>(
43 uno::Reference< rendering::XBitmapCanvas >(rBitmap,
44 uno::UNO_QUERY) );
47 ImplBitmap::~ImplBitmap()
51 bool ImplBitmap::draw() const
53 CanvasSharedPtr pCanvas( getCanvas() );
55 OSL_ENSURE( pCanvas && pCanvas->getUNOCanvas().is(),
56 "ImplBitmap::draw: invalid canvas" );
58 if( !pCanvas ||
59 !pCanvas->getUNOCanvas().is() )
61 return false;
64 // TODO(P1): implement caching
65 pCanvas->getUNOCanvas()->drawBitmap( mxBitmap,
66 pCanvas->getViewState(),
67 getRenderState() );
69 return true;
72 void ImplBitmap::drawAlphaModulated( double nAlphaModulation ) const
74 CanvasSharedPtr pCanvas( getCanvas() );
76 OSL_ENSURE( pCanvas && pCanvas->getUNOCanvas().is(),
77 "ImplBitmap::drawAlphaModulated(): invalid canvas" );
79 if( !pCanvas ||
80 !pCanvas->getUNOCanvas().is() )
82 return;
85 rendering::RenderState aLocalState( getRenderState() );
86 uno::Sequence<rendering::ARGBColor> aCol { { nAlphaModulation, 1.0, 1.0, 1.0 } };
87 aLocalState.DeviceColor =
88 pCanvas->getUNOCanvas()->getDevice()->getDeviceColorSpace()->convertFromARGB(aCol);
90 // TODO(P1): implement caching
91 pCanvas->getUNOCanvas()->drawBitmapModulated( mxBitmap,
92 pCanvas->getViewState(),
93 aLocalState );
96 BitmapCanvasSharedPtr ImplBitmap::getBitmapCanvas() const
98 return mpBitmapCanvas;
101 uno::Reference< rendering::XBitmap > ImplBitmap::getUNOBitmap() const
103 return mxBitmap;
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */