Bump for 3.6-28
[LibreOffice.git] / cppcanvas / source / tools / canvasgraphichelper.cxx
blobabb975445c8b4ae0a89c790a140bf71f223a48bd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <canvasgraphichelper.hxx>
32 #include <com/sun/star/rendering/XGraphicDevice.hpp>
33 #include <com/sun/star/rendering/XCanvas.hpp>
34 #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
36 #include <canvas/canvastools.hxx>
37 #include <basegfx/tools/canvastools.hxx>
38 #include <basegfx/matrix/b2dhommatrix.hxx>
40 #include <cppcanvas/polypolygon.hxx>
41 #include "tools.hxx"
44 using namespace ::com::sun::star;
46 /* Implementation of CanvasGraphicHelper class */
48 namespace cppcanvas
51 namespace internal
53 CanvasGraphicHelper::CanvasGraphicHelper( const CanvasSharedPtr& rParentCanvas ) :
54 maClipPolyPolygon(),
55 mpCanvas( rParentCanvas ),
56 mxGraphicDevice()
58 OSL_ENSURE( mpCanvas.get() != NULL &&
59 mpCanvas->getUNOCanvas().is(),
60 "CanvasGraphicHelper::CanvasGraphicHelper: no valid canvas" );
62 if( mpCanvas.get() != NULL &&
63 mpCanvas->getUNOCanvas().is() )
65 mxGraphicDevice = mpCanvas->getUNOCanvas()->getDevice();
68 ::canvas::tools::initRenderState( maRenderState );
71 void CanvasGraphicHelper::setTransformation( const ::basegfx::B2DHomMatrix& rMatrix )
73 ::canvas::tools::setRenderStateTransform( maRenderState, rMatrix );
76 ::basegfx::B2DHomMatrix CanvasGraphicHelper::getTransformation() const
78 ::basegfx::B2DHomMatrix aMatrix;
79 return ::canvas::tools::getRenderStateTransform( aMatrix,
80 maRenderState );
83 void CanvasGraphicHelper::setClip( const ::basegfx::B2DPolyPolygon& rClipPoly )
85 // TODO(T3): not thread-safe. B2DPolyPolygon employs copy-on-write
86 maClipPolyPolygon.reset( rClipPoly );
87 maRenderState.Clip.clear();
90 void CanvasGraphicHelper::setClip()
92 maClipPolyPolygon.reset();
93 maRenderState.Clip.clear();
96 ::basegfx::B2DPolyPolygon const* CanvasGraphicHelper::getClip() const
98 return !maClipPolyPolygon ? NULL : &(*maClipPolyPolygon);
101 const rendering::RenderState& CanvasGraphicHelper::getRenderState() const
103 if( maClipPolyPolygon && !maRenderState.Clip.is() )
105 uno::Reference< rendering::XCanvas > xCanvas( mpCanvas->getUNOCanvas() );
106 if( !xCanvas.is() )
107 return maRenderState;
109 maRenderState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
110 xCanvas->getDevice(),
111 *maClipPolyPolygon );
114 return maRenderState;
117 void CanvasGraphicHelper::setRGBAColor( Color::IntSRGBA aColor )
119 maRenderState.DeviceColor = tools::intSRGBAToDoubleSequence( mxGraphicDevice,
120 aColor );
123 Color::IntSRGBA CanvasGraphicHelper::getRGBAColor() const
125 return tools::doubleSequenceToIntSRGBA( mxGraphicDevice,
126 maRenderState.DeviceColor );
129 void CanvasGraphicHelper::setCompositeOp( CompositeOp aOp )
131 maRenderState.CompositeOperation = (sal_Int8)aOp;
134 CanvasGraphic::CompositeOp CanvasGraphicHelper::getCompositeOp() const
136 return static_cast<CompositeOp>(maRenderState.CompositeOperation);
139 CanvasSharedPtr CanvasGraphicHelper::getCanvas() const
141 return mpCanvas;
144 uno::Reference< rendering::XGraphicDevice > CanvasGraphicHelper::getGraphicDevice() const
146 return mxGraphicDevice;
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */