1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_cppcanvas.hxx" 30 31 #include <canvasgraphichelper.hxx> 32 33 #include <com/sun/star/rendering/XGraphicDevice.hpp> 34 #include <com/sun/star/rendering/XCanvas.hpp> 35 #include <com/sun/star/rendering/XPolyPolygon2D.hpp> 36 37 #include <canvas/canvastools.hxx> 38 #include <basegfx/tools/canvastools.hxx> 39 #include <basegfx/matrix/b2dhommatrix.hxx> 40 41 #include <cppcanvas/polypolygon.hxx> 42 #include "tools.hxx" 43 44 45 using namespace ::com::sun::star; 46 47 /* Implementation of CanvasGraphicHelper class */ 48 49 namespace cppcanvas 50 { 51 52 namespace internal 53 { 54 CanvasGraphicHelper::CanvasGraphicHelper( const CanvasSharedPtr& rParentCanvas ) : 55 maClipPolyPolygon(), 56 mpCanvas( rParentCanvas ), 57 mxGraphicDevice() 58 { 59 OSL_ENSURE( mpCanvas.get() != NULL && 60 mpCanvas->getUNOCanvas().is(), 61 "CanvasGraphicHelper::CanvasGraphicHelper: no valid canvas" ); 62 63 if( mpCanvas.get() != NULL && 64 mpCanvas->getUNOCanvas().is() ) 65 { 66 mxGraphicDevice = mpCanvas->getUNOCanvas()->getDevice(); 67 } 68 69 ::canvas::tools::initRenderState( maRenderState ); 70 } 71 72 void CanvasGraphicHelper::setTransformation( const ::basegfx::B2DHomMatrix& rMatrix ) 73 { 74 ::canvas::tools::setRenderStateTransform( maRenderState, rMatrix ); 75 } 76 77 ::basegfx::B2DHomMatrix CanvasGraphicHelper::getTransformation() const 78 { 79 ::basegfx::B2DHomMatrix aMatrix; 80 return ::canvas::tools::getRenderStateTransform( aMatrix, 81 maRenderState ); 82 } 83 84 void CanvasGraphicHelper::setClip( const ::basegfx::B2DPolyPolygon& rClipPoly ) 85 { 86 // TODO(T3): not thread-safe. B2DPolyPolygon employs copy-on-write 87 maClipPolyPolygon.reset( rClipPoly ); 88 maRenderState.Clip.clear(); 89 } 90 91 void CanvasGraphicHelper::setClip() 92 { 93 maClipPolyPolygon.reset(); 94 maRenderState.Clip.clear(); 95 } 96 97 ::basegfx::B2DPolyPolygon const* CanvasGraphicHelper::getClip() const 98 { 99 return !maClipPolyPolygon ? NULL : &(*maClipPolyPolygon); 100 } 101 102 const rendering::RenderState& CanvasGraphicHelper::getRenderState() const 103 { 104 if( maClipPolyPolygon && !maRenderState.Clip.is() ) 105 { 106 uno::Reference< rendering::XCanvas > xCanvas( mpCanvas->getUNOCanvas() ); 107 if( !xCanvas.is() ) 108 return maRenderState; 109 110 maRenderState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( 111 xCanvas->getDevice(), 112 *maClipPolyPolygon ); 113 } 114 115 return maRenderState; 116 } 117 118 void CanvasGraphicHelper::setRGBAColor( Color::IntSRGBA aColor ) 119 { 120 maRenderState.DeviceColor = tools::intSRGBAToDoubleSequence( mxGraphicDevice, 121 aColor ); 122 } 123 124 Color::IntSRGBA CanvasGraphicHelper::getRGBAColor() const 125 { 126 return tools::doubleSequenceToIntSRGBA( mxGraphicDevice, 127 maRenderState.DeviceColor ); 128 } 129 130 void CanvasGraphicHelper::setCompositeOp( CompositeOp aOp ) 131 { 132 maRenderState.CompositeOperation = (sal_Int8)aOp; 133 } 134 135 CanvasGraphic::CompositeOp CanvasGraphicHelper::getCompositeOp() const 136 { 137 return static_cast<CompositeOp>(maRenderState.CompositeOperation); 138 } 139 140 CanvasSharedPtr CanvasGraphicHelper::getCanvas() const 141 { 142 return mpCanvas; 143 } 144 145 uno::Reference< rendering::XGraphicDevice > CanvasGraphicHelper::getGraphicDevice() const 146 { 147 return mxGraphicDevice; 148 } 149 150 } 151 } 152