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