LibreOffice Module cppcanvas (master) 1
implbitmap.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include "implbitmap.hxx"
22#include "implbitmapcanvas.hxx"
23
24#include <osl/diagnose.h>
25
26
27using namespace ::com::sun::star;
28
29namespace cppcanvas::internal
30{
31
32 ImplBitmap::ImplBitmap( const CanvasSharedPtr& rParentCanvas,
33 const uno::Reference< rendering::XBitmap >& rBitmap ) :
34 CanvasGraphicHelper( rParentCanvas ),
35 mxBitmap( rBitmap )
36 {
37 OSL_ENSURE( mxBitmap.is(), "ImplBitmap::ImplBitmap: no valid bitmap" );
38
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) );
45 }
46
47 ImplBitmap::~ImplBitmap()
48 {
49 }
50
51 bool ImplBitmap::draw() const
52 {
53 CanvasSharedPtr pCanvas( getCanvas() );
54
55 OSL_ENSURE( pCanvas && pCanvas->getUNOCanvas().is(),
56 "ImplBitmap::draw: invalid canvas" );
57
58 if( !pCanvas ||
59 !pCanvas->getUNOCanvas().is() )
60 {
61 return false;
62 }
63
64 // TODO(P1): implement caching
65 pCanvas->getUNOCanvas()->drawBitmap( mxBitmap,
66 pCanvas->getViewState(),
67 getRenderState() );
68
69 return true;
70 }
71
72 void ImplBitmap::drawAlphaModulated( double nAlphaModulation ) const
73 {
74 CanvasSharedPtr pCanvas( getCanvas() );
75
76 OSL_ENSURE( pCanvas && pCanvas->getUNOCanvas().is(),
77 "ImplBitmap::drawAlphaModulated(): invalid canvas" );
78
79 if( !pCanvas ||
80 !pCanvas->getUNOCanvas().is() )
81 {
82 return;
83 }
84
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);
89
90 // TODO(P1): implement caching
91 pCanvas->getUNOCanvas()->drawBitmapModulated( mxBitmap,
92 pCanvas->getViewState(),
93 aLocalState );
94 }
95
96 BitmapCanvasSharedPtr ImplBitmap::getBitmapCanvas() const
97 {
98 return mpBitmapCanvas;
99 }
100
101 uno::Reference< rendering::XBitmap > ImplBitmap::getUNOBitmap() const
102 {
103 return mxBitmap;
104 }
105}
106
107/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
uno::Reference< rendering::XBitmap > mxBitmap
ImplBitmap(const CanvasSharedPtr &rParentCanvas, const css::uno::Reference< css::rendering::XBitmap > &rBitmap)
std::shared_ptr< BitmapCanvas > BitmapCanvasSharedPtr
std::shared_ptr< Canvas > CanvasSharedPtr