1*25b11142SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*25b11142SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*25b11142SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*25b11142SAndrew Rist * distributed with this work for additional information 6*25b11142SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*25b11142SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*25b11142SAndrew Rist * "License"); you may not use this file except in compliance 9*25b11142SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*25b11142SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*25b11142SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*25b11142SAndrew Rist * software distributed under the License is distributed on an 15*25b11142SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*25b11142SAndrew Rist * KIND, either express or implied. See the License for the 17*25b11142SAndrew Rist * specific language governing permissions and limitations 18*25b11142SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*25b11142SAndrew Rist *************************************************************/ 21*25b11142SAndrew Rist 22*25b11142SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_cppcanvas.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <rtl/ustring.hxx> 28cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx> 29cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx> 30cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx> 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <com/sun/star/rendering/XCanvas.hpp> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include <canvas/canvastools.hxx> 35cdf0e10cSrcweir #include <cppcanvas/polypolygon.hxx> 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include "implfont.hxx" 38cdf0e10cSrcweir #include "implcolor.hxx" 39cdf0e10cSrcweir #include "implcanvas.hxx" 40cdf0e10cSrcweir 41cdf0e10cSrcweir 42cdf0e10cSrcweir using namespace ::com::sun::star; 43cdf0e10cSrcweir 44cdf0e10cSrcweir namespace cppcanvas 45cdf0e10cSrcweir { 46cdf0e10cSrcweir namespace internal 47cdf0e10cSrcweir { 48cdf0e10cSrcweir ImplCanvas(const uno::Reference<rendering::XCanvas> & xCanvas)49cdf0e10cSrcweir ImplCanvas::ImplCanvas( const uno::Reference< rendering::XCanvas >& xCanvas ) : 50cdf0e10cSrcweir maViewState(), 51cdf0e10cSrcweir maClipPolyPolygon(), 52cdf0e10cSrcweir mxCanvas( xCanvas ) 53cdf0e10cSrcweir { 54cdf0e10cSrcweir OSL_ENSURE( mxCanvas.is(), "Canvas::Canvas() invalid XCanvas" ); 55cdf0e10cSrcweir 56cdf0e10cSrcweir ::canvas::tools::initViewState( maViewState ); 57cdf0e10cSrcweir } 58cdf0e10cSrcweir ~ImplCanvas()59cdf0e10cSrcweir ImplCanvas::~ImplCanvas() 60cdf0e10cSrcweir { 61cdf0e10cSrcweir } 62cdf0e10cSrcweir setTransformation(const::basegfx::B2DHomMatrix & rMatrix)63cdf0e10cSrcweir void ImplCanvas::setTransformation( const ::basegfx::B2DHomMatrix& rMatrix ) 64cdf0e10cSrcweir { 65cdf0e10cSrcweir ::canvas::tools::setViewStateTransform( maViewState, rMatrix ); 66cdf0e10cSrcweir } 67cdf0e10cSrcweir getTransformation() const68cdf0e10cSrcweir ::basegfx::B2DHomMatrix ImplCanvas::getTransformation() const 69cdf0e10cSrcweir { 70cdf0e10cSrcweir ::basegfx::B2DHomMatrix aMatrix; 71cdf0e10cSrcweir return ::canvas::tools::getViewStateTransform( aMatrix, 72cdf0e10cSrcweir maViewState ); 73cdf0e10cSrcweir } 74cdf0e10cSrcweir setClip(const::basegfx::B2DPolyPolygon & rClipPoly)75cdf0e10cSrcweir void ImplCanvas::setClip( const ::basegfx::B2DPolyPolygon& rClipPoly ) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir // TODO(T3): not thread-safe. B2DPolyPolygon employs copy-on-write 78cdf0e10cSrcweir maClipPolyPolygon.reset( rClipPoly ); 79cdf0e10cSrcweir maViewState.Clip.clear(); 80cdf0e10cSrcweir } 81cdf0e10cSrcweir setClip()82cdf0e10cSrcweir void ImplCanvas::setClip() 83cdf0e10cSrcweir { 84cdf0e10cSrcweir maClipPolyPolygon.reset(); 85cdf0e10cSrcweir maViewState.Clip.clear(); 86cdf0e10cSrcweir } 87cdf0e10cSrcweir getClip() const88cdf0e10cSrcweir ::basegfx::B2DPolyPolygon const* ImplCanvas::getClip() const 89cdf0e10cSrcweir { 90cdf0e10cSrcweir return !maClipPolyPolygon ? NULL : &(*maClipPolyPolygon); 91cdf0e10cSrcweir } 92cdf0e10cSrcweir createFont(const::rtl::OUString & rFontName,const double & rCellSize) const93cdf0e10cSrcweir FontSharedPtr ImplCanvas::createFont( const ::rtl::OUString& rFontName, const double& rCellSize ) const 94cdf0e10cSrcweir { 95cdf0e10cSrcweir return FontSharedPtr( new ImplFont( getUNOCanvas(), rFontName, rCellSize ) ); 96cdf0e10cSrcweir } 97cdf0e10cSrcweir createColor() const98cdf0e10cSrcweir ColorSharedPtr ImplCanvas::createColor() const 99cdf0e10cSrcweir { 100cdf0e10cSrcweir return ColorSharedPtr( new ImplColor( getUNOCanvas()->getDevice() ) ); 101cdf0e10cSrcweir } 102cdf0e10cSrcweir clone() const103cdf0e10cSrcweir CanvasSharedPtr ImplCanvas::clone() const 104cdf0e10cSrcweir { 105cdf0e10cSrcweir return CanvasSharedPtr( new ImplCanvas( *this ) ); 106cdf0e10cSrcweir } 107cdf0e10cSrcweir clear() const108cdf0e10cSrcweir void ImplCanvas::clear() const 109cdf0e10cSrcweir { 110cdf0e10cSrcweir OSL_ENSURE( mxCanvas.is(), "ImplCanvas::clear(): Invalid XCanvas" ); 111cdf0e10cSrcweir mxCanvas->clear(); 112cdf0e10cSrcweir } 113cdf0e10cSrcweir getUNOCanvas() const114cdf0e10cSrcweir uno::Reference< rendering::XCanvas > ImplCanvas::getUNOCanvas() const 115cdf0e10cSrcweir { 116cdf0e10cSrcweir OSL_ENSURE( mxCanvas.is(), "ImplCanvas::getUNOCanvas(): Invalid XCanvas" ); 117cdf0e10cSrcweir 118cdf0e10cSrcweir return mxCanvas; 119cdf0e10cSrcweir } 120cdf0e10cSrcweir getViewState() const121cdf0e10cSrcweir rendering::ViewState ImplCanvas::getViewState() const 122cdf0e10cSrcweir { 123cdf0e10cSrcweir if( maClipPolyPolygon && !maViewState.Clip.is() ) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir if( !mxCanvas.is() ) 126cdf0e10cSrcweir return maViewState; 127cdf0e10cSrcweir 128cdf0e10cSrcweir maViewState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( 129cdf0e10cSrcweir mxCanvas->getDevice(), 130cdf0e10cSrcweir *maClipPolyPolygon ); 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir return maViewState; 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136cdf0e10cSrcweir } 137cdf0e10cSrcweir } 138