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 27 using namespace ::com::sun::star; 28 29 namespace cppcanvas::internal 30 { 31 ImplBitmap(const CanvasSharedPtr & rParentCanvas,const uno::Reference<rendering::XBitmap> & rBitmap)32 ImplBitmap::ImplBitmap( const CanvasSharedPtr& rParentCanvas, 33 const uno::Reference< rendering::XBitmap >& rBitmap ) : 34 CanvasGraphicHelper( rParentCanvas ), 35 mxBitmap( rBitmap ), 36 mpBitmapCanvas() 37 { 38 OSL_ENSURE( mxBitmap.is(), "ImplBitmap::ImplBitmap: no valid bitmap" ); 39 40 uno::Reference< rendering::XBitmapCanvas > xBitmapCanvas( rBitmap, 41 uno::UNO_QUERY ); 42 if( xBitmapCanvas.is() ) 43 mpBitmapCanvas = std::make_shared<ImplBitmapCanvas>( 44 uno::Reference< rendering::XBitmapCanvas >(rBitmap, 45 uno::UNO_QUERY) ); 46 } 47 ~ImplBitmap()48 ImplBitmap::~ImplBitmap() 49 { 50 } 51 draw() const52 bool ImplBitmap::draw() const 53 { 54 CanvasSharedPtr pCanvas( getCanvas() ); 55 56 OSL_ENSURE( pCanvas && pCanvas->getUNOCanvas().is(), 57 "ImplBitmap::draw: invalid canvas" ); 58 59 if( !pCanvas || 60 !pCanvas->getUNOCanvas().is() ) 61 { 62 return false; 63 } 64 65 // TODO(P1): implement caching 66 pCanvas->getUNOCanvas()->drawBitmap( mxBitmap, 67 pCanvas->getViewState(), 68 getRenderState() ); 69 70 return true; 71 } 72 drawAlphaModulated(double nAlphaModulation) const73 void ImplBitmap::drawAlphaModulated( double nAlphaModulation ) const 74 { 75 CanvasSharedPtr pCanvas( getCanvas() ); 76 77 OSL_ENSURE( pCanvas && pCanvas->getUNOCanvas().is(), 78 "ImplBitmap::drawAlphaModulated(): invalid canvas" ); 79 80 if( !pCanvas || 81 !pCanvas->getUNOCanvas().is() ) 82 { 83 return; 84 } 85 86 rendering::RenderState aLocalState( getRenderState() ); 87 uno::Sequence<rendering::ARGBColor> aCol { { nAlphaModulation, 1.0, 1.0, 1.0 } }; 88 aLocalState.DeviceColor = 89 pCanvas->getUNOCanvas()->getDevice()->getDeviceColorSpace()->convertFromARGB(aCol); 90 91 // TODO(P1): implement caching 92 pCanvas->getUNOCanvas()->drawBitmapModulated( mxBitmap, 93 pCanvas->getViewState(), 94 aLocalState ); 95 } 96 getBitmapCanvas() const97 BitmapCanvasSharedPtr ImplBitmap::getBitmapCanvas() const 98 { 99 return mpBitmapCanvas; 100 } 101 getUNOBitmap() const102 uno::Reference< rendering::XBitmap > ImplBitmap::getUNOBitmap() const 103 { 104 return mxBitmap; 105 } 106 } 107 108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 109