merge the formfield patch from ooo-build
[ooovba.git] / cppcanvas / source / tools / canvasgraphichelper.cxx
blobe6236f1724d56d02a4435ceb5bab4e4579dbb438
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: canvasgraphichelper.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_cppcanvas.hxx"
34 #include <canvasgraphichelper.hxx>
36 #include <com/sun/star/rendering/XGraphicDevice.hpp>
37 #include <com/sun/star/rendering/XCanvas.hpp>
38 #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
40 #include <canvas/canvastools.hxx>
41 #include <basegfx/tools/canvastools.hxx>
42 #include <basegfx/matrix/b2dhommatrix.hxx>
44 #include <cppcanvas/polypolygon.hxx>
45 #include "tools.hxx"
48 using namespace ::com::sun::star;
50 /* Implementation of CanvasGraphicHelper class */
52 namespace cppcanvas
55 namespace internal
57 CanvasGraphicHelper::CanvasGraphicHelper( const CanvasSharedPtr& rParentCanvas ) :
58 maClipPolyPolygon(),
59 mpCanvas( rParentCanvas ),
60 mxGraphicDevice()
62 OSL_ENSURE( mpCanvas.get() != NULL &&
63 mpCanvas->getUNOCanvas().is(),
64 "CanvasGraphicHelper::CanvasGraphicHelper: no valid canvas" );
66 if( mpCanvas.get() != NULL &&
67 mpCanvas->getUNOCanvas().is() )
69 mxGraphicDevice = mpCanvas->getUNOCanvas()->getDevice();
72 ::canvas::tools::initRenderState( maRenderState );
75 void CanvasGraphicHelper::setTransformation( const ::basegfx::B2DHomMatrix& rMatrix )
77 ::canvas::tools::setRenderStateTransform( maRenderState, rMatrix );
80 ::basegfx::B2DHomMatrix CanvasGraphicHelper::getTransformation() const
82 ::basegfx::B2DHomMatrix aMatrix;
83 return ::canvas::tools::getRenderStateTransform( aMatrix,
84 maRenderState );
87 void CanvasGraphicHelper::setClip( const ::basegfx::B2DPolyPolygon& rClipPoly )
89 // TODO(T3): not thread-safe. B2DPolyPolygon employs copy-on-write
90 maClipPolyPolygon.reset( rClipPoly );
91 maRenderState.Clip.clear();
94 void CanvasGraphicHelper::setClip()
96 maClipPolyPolygon.reset();
97 maRenderState.Clip.clear();
100 ::basegfx::B2DPolyPolygon const* CanvasGraphicHelper::getClip() const
102 return !maClipPolyPolygon ? NULL : &(*maClipPolyPolygon);
105 const rendering::RenderState& CanvasGraphicHelper::getRenderState() const
107 if( maClipPolyPolygon && !maRenderState.Clip.is() )
109 uno::Reference< rendering::XCanvas > xCanvas( mpCanvas->getUNOCanvas() );
110 if( !xCanvas.is() )
111 return maRenderState;
113 maRenderState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
114 xCanvas->getDevice(),
115 *maClipPolyPolygon );
118 return maRenderState;
121 void CanvasGraphicHelper::setRGBAColor( Color::IntSRGBA aColor )
123 maRenderState.DeviceColor = tools::intSRGBAToDoubleSequence( mxGraphicDevice,
124 aColor );
127 Color::IntSRGBA CanvasGraphicHelper::getRGBAColor() const
129 return tools::doubleSequenceToIntSRGBA( mxGraphicDevice,
130 maRenderState.DeviceColor );
133 void CanvasGraphicHelper::setCompositeOp( CompositeOp aOp )
135 maRenderState.CompositeOperation = (sal_Int8)aOp;
138 CanvasGraphic::CompositeOp CanvasGraphicHelper::getCompositeOp() const
140 return static_cast<CompositeOp>(maRenderState.CompositeOperation);
143 CanvasSharedPtr CanvasGraphicHelper::getCanvas() const
145 return mpCanvas;
148 uno::Reference< rendering::XGraphicDevice > CanvasGraphicHelper::getGraphicDevice() const
150 return mxGraphicDevice;