update dev300-m58
[ooovba.git] / cppcanvas / source / wrapper / implcanvas.cxx
blobabf46c5ba30329828d6d9b21111aa56660d68fa4
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: implcanvas.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 <rtl/ustring.hxx>
35 #include <basegfx/matrix/b2dhommatrix.hxx>
36 #include <basegfx/polygon/b2dpolypolygon.hxx>
37 #include <basegfx/tools/canvastools.hxx>
39 #include <com/sun/star/rendering/XCanvas.hpp>
41 #include <canvas/canvastools.hxx>
42 #include <cppcanvas/polypolygon.hxx>
44 #include "implfont.hxx"
45 #include "implcolor.hxx"
46 #include "implcanvas.hxx"
49 using namespace ::com::sun::star;
51 namespace cppcanvas
53 namespace internal
56 ImplCanvas::ImplCanvas( const uno::Reference< rendering::XCanvas >& xCanvas ) :
57 maViewState(),
58 maClipPolyPolygon(),
59 mxCanvas( xCanvas )
61 OSL_ENSURE( mxCanvas.is(), "Canvas::Canvas() invalid XCanvas" );
63 ::canvas::tools::initViewState( maViewState );
66 ImplCanvas::~ImplCanvas()
70 void ImplCanvas::setTransformation( const ::basegfx::B2DHomMatrix& rMatrix )
72 ::canvas::tools::setViewStateTransform( maViewState, rMatrix );
75 ::basegfx::B2DHomMatrix ImplCanvas::getTransformation() const
77 ::basegfx::B2DHomMatrix aMatrix;
78 return ::canvas::tools::getViewStateTransform( aMatrix,
79 maViewState );
82 void ImplCanvas::setClip( const ::basegfx::B2DPolyPolygon& rClipPoly )
84 // TODO(T3): not thread-safe. B2DPolyPolygon employs copy-on-write
85 maClipPolyPolygon.reset( rClipPoly );
86 maViewState.Clip.clear();
89 void ImplCanvas::setClip()
91 maClipPolyPolygon.reset();
92 maViewState.Clip.clear();
95 ::basegfx::B2DPolyPolygon const* ImplCanvas::getClip() const
97 return !maClipPolyPolygon ? NULL : &(*maClipPolyPolygon);
100 FontSharedPtr ImplCanvas::createFont( const ::rtl::OUString& rFontName, const double& rCellSize ) const
102 return FontSharedPtr( new ImplFont( getUNOCanvas(), rFontName, rCellSize ) );
105 ColorSharedPtr ImplCanvas::createColor() const
107 return ColorSharedPtr( new ImplColor( getUNOCanvas()->getDevice() ) );
110 CanvasSharedPtr ImplCanvas::clone() const
112 return CanvasSharedPtr( new ImplCanvas( *this ) );
115 void ImplCanvas::clear() const
117 OSL_ENSURE( mxCanvas.is(), "ImplCanvas::clear(): Invalid XCanvas" );
118 mxCanvas->clear();
121 uno::Reference< rendering::XCanvas > ImplCanvas::getUNOCanvas() const
123 OSL_ENSURE( mxCanvas.is(), "ImplCanvas::getUNOCanvas(): Invalid XCanvas" );
125 return mxCanvas;
128 rendering::ViewState ImplCanvas::getViewState() const
130 if( maClipPolyPolygon && !maViewState.Clip.is() )
132 if( !mxCanvas.is() )
133 return maViewState;
135 maViewState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
136 mxCanvas->getDevice(),
137 *maClipPolyPolygon );
140 return maViewState;