Bump version to 5.0-14
[LibreOffice.git] / cppcanvas / source / tools / canvasgraphichelper.cxx
blob43231ed347d576e9e63e399bf565af6fc8d857a7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <canvasgraphichelper.hxx>
23 #include <com/sun/star/rendering/XGraphicDevice.hpp>
24 #include <com/sun/star/rendering/XCanvas.hpp>
25 #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
27 #include <canvas/canvastools.hxx>
28 #include <basegfx/tools/canvastools.hxx>
29 #include <basegfx/matrix/b2dhommatrix.hxx>
31 #include <cppcanvas/polypolygon.hxx>
32 #include "tools.hxx"
35 using namespace ::com::sun::star;
37 /* Implementation of CanvasGraphicHelper class */
39 namespace cppcanvas
42 namespace internal
44 CanvasGraphicHelper::CanvasGraphicHelper( const CanvasSharedPtr& rParentCanvas ) :
45 maClipPolyPolygon(),
46 mpCanvas( rParentCanvas ),
47 mxGraphicDevice()
49 OSL_ENSURE( mpCanvas.get() != NULL &&
50 mpCanvas->getUNOCanvas().is(),
51 "CanvasGraphicHelper::CanvasGraphicHelper: no valid canvas" );
53 if( mpCanvas.get() != NULL &&
54 mpCanvas->getUNOCanvas().is() )
56 mxGraphicDevice = mpCanvas->getUNOCanvas()->getDevice();
59 ::canvas::tools::initRenderState( maRenderState );
62 void CanvasGraphicHelper::setTransformation( const ::basegfx::B2DHomMatrix& rMatrix )
64 ::canvas::tools::setRenderStateTransform( maRenderState, rMatrix );
67 ::basegfx::B2DHomMatrix CanvasGraphicHelper::getTransformation() const
69 ::basegfx::B2DHomMatrix aMatrix;
70 return ::canvas::tools::getRenderStateTransform( aMatrix,
71 maRenderState );
74 void CanvasGraphicHelper::setClip( const ::basegfx::B2DPolyPolygon& rClipPoly )
76 // TODO(T3): not thread-safe. B2DPolyPolygon employs copy-on-write
77 maClipPolyPolygon.reset( rClipPoly );
78 maRenderState.Clip.clear();
81 void CanvasGraphicHelper::setClip()
83 maClipPolyPolygon.reset();
84 maRenderState.Clip.clear();
87 ::basegfx::B2DPolyPolygon const* CanvasGraphicHelper::getClip() const
89 return !maClipPolyPolygon ? NULL : &(*maClipPolyPolygon);
92 const rendering::RenderState& CanvasGraphicHelper::getRenderState() const
94 if( maClipPolyPolygon && !maRenderState.Clip.is() )
96 uno::Reference< rendering::XCanvas > xCanvas( mpCanvas->getUNOCanvas() );
97 if( !xCanvas.is() )
98 return maRenderState;
100 maRenderState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
101 xCanvas->getDevice(),
102 *maClipPolyPolygon );
105 return maRenderState;
108 void CanvasGraphicHelper::setCompositeOp( CompositeOp aOp )
110 maRenderState.CompositeOperation = (sal_Int8)aOp;
113 CanvasGraphic::CompositeOp CanvasGraphicHelper::getCompositeOp() const
115 return static_cast<CompositeOp>(maRenderState.CompositeOperation);
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */