Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / cppcanvas / source / wrapper / implcanvas.cxx
blob70a4c3f24f42ec7a89d4a1a04b3fb91b594945ca
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 <rtl/ustring.hxx>
22 #include <basegfx/matrix/b2dhommatrix.hxx>
23 #include <basegfx/polygon/b2dpolypolygon.hxx>
24 #include <basegfx/tools/canvastools.hxx>
26 #include <com/sun/star/rendering/XCanvas.hpp>
28 #include <canvas/canvastools.hxx>
29 #include <cppcanvas/polypolygon.hxx>
31 #include "implfont.hxx"
32 #include "implcolor.hxx"
33 #include "implcanvas.hxx"
36 using namespace ::com::sun::star;
38 namespace cppcanvas
40 namespace internal
43 ImplCanvas::ImplCanvas( const uno::Reference< rendering::XCanvas >& xCanvas ) :
44 maViewState(),
45 maClipPolyPolygon(),
46 mxCanvas( xCanvas )
48 OSL_ENSURE( mxCanvas.is(), "Canvas::Canvas() invalid XCanvas" );
50 ::canvas::tools::initViewState( maViewState );
53 ImplCanvas::~ImplCanvas()
57 void ImplCanvas::setTransformation( const ::basegfx::B2DHomMatrix& rMatrix )
59 ::canvas::tools::setViewStateTransform( maViewState, rMatrix );
62 ::basegfx::B2DHomMatrix ImplCanvas::getTransformation() const
64 ::basegfx::B2DHomMatrix aMatrix;
65 return ::canvas::tools::getViewStateTransform( aMatrix,
66 maViewState );
69 void ImplCanvas::setClip( const ::basegfx::B2DPolyPolygon& rClipPoly )
71 // TODO(T3): not thread-safe. B2DPolyPolygon employs copy-on-write
72 maClipPolyPolygon.reset( rClipPoly );
73 maViewState.Clip.clear();
76 void ImplCanvas::setClip()
78 maClipPolyPolygon.reset();
79 maViewState.Clip.clear();
82 ::basegfx::B2DPolyPolygon const* ImplCanvas::getClip() const
84 return !maClipPolyPolygon ? NULL : &(*maClipPolyPolygon);
87 FontSharedPtr ImplCanvas::createFont( const OUString& rFontName, const double& rCellSize ) const
89 return FontSharedPtr( new ImplFont( getUNOCanvas(), rFontName, rCellSize ) );
92 ColorSharedPtr ImplCanvas::createColor() const
94 return ColorSharedPtr( new ImplColor( getUNOCanvas()->getDevice() ) );
97 CanvasSharedPtr ImplCanvas::clone() const
99 return CanvasSharedPtr( new ImplCanvas( *this ) );
102 void ImplCanvas::clear() const
104 OSL_ENSURE( mxCanvas.is(), "ImplCanvas::clear(): Invalid XCanvas" );
105 mxCanvas->clear();
108 uno::Reference< rendering::XCanvas > ImplCanvas::getUNOCanvas() const
110 OSL_ENSURE( mxCanvas.is(), "ImplCanvas::getUNOCanvas(): Invalid XCanvas" );
112 return mxCanvas;
115 rendering::ViewState ImplCanvas::getViewState() const
117 if( maClipPolyPolygon && !maViewState.Clip.is() )
119 if( !mxCanvas.is() )
120 return maViewState;
122 maViewState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
123 mxCanvas->getDevice(),
124 *maClipPolyPolygon );
127 return maViewState;
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */