xref: /AOO41X/main/cppcanvas/source/wrapper/implcanvas.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cppcanvas.hxx"
30 
31 #include <rtl/ustring.hxx>
32 #include <basegfx/matrix/b2dhommatrix.hxx>
33 #include <basegfx/polygon/b2dpolypolygon.hxx>
34 #include <basegfx/tools/canvastools.hxx>
35 
36 #include <com/sun/star/rendering/XCanvas.hpp>
37 
38 #include <canvas/canvastools.hxx>
39 #include <cppcanvas/polypolygon.hxx>
40 
41 #include "implfont.hxx"
42 #include "implcolor.hxx"
43 #include "implcanvas.hxx"
44 
45 
46 using namespace ::com::sun::star;
47 
48 namespace cppcanvas
49 {
50     namespace internal
51     {
52 
53         ImplCanvas::ImplCanvas( const uno::Reference< rendering::XCanvas >& xCanvas ) :
54             maViewState(),
55             maClipPolyPolygon(),
56             mxCanvas( xCanvas )
57         {
58             OSL_ENSURE( mxCanvas.is(), "Canvas::Canvas() invalid XCanvas" );
59 
60             ::canvas::tools::initViewState( maViewState );
61         }
62 
63         ImplCanvas::~ImplCanvas()
64         {
65         }
66 
67         void ImplCanvas::setTransformation( const ::basegfx::B2DHomMatrix& rMatrix )
68         {
69             ::canvas::tools::setViewStateTransform( maViewState, rMatrix );
70         }
71 
72         ::basegfx::B2DHomMatrix ImplCanvas::getTransformation() const
73         {
74             ::basegfx::B2DHomMatrix aMatrix;
75             return ::canvas::tools::getViewStateTransform( aMatrix,
76                                                            maViewState );
77         }
78 
79         void ImplCanvas::setClip( const ::basegfx::B2DPolyPolygon& rClipPoly )
80         {
81             // TODO(T3): not thread-safe. B2DPolyPolygon employs copy-on-write
82             maClipPolyPolygon.reset( rClipPoly );
83             maViewState.Clip.clear();
84         }
85 
86         void ImplCanvas::setClip()
87         {
88             maClipPolyPolygon.reset();
89             maViewState.Clip.clear();
90         }
91 
92         ::basegfx::B2DPolyPolygon const* ImplCanvas::getClip() const
93         {
94             return !maClipPolyPolygon ? NULL : &(*maClipPolyPolygon);
95         }
96 
97         FontSharedPtr ImplCanvas::createFont( const ::rtl::OUString& rFontName, const double& rCellSize ) const
98         {
99             return FontSharedPtr( new ImplFont( getUNOCanvas(), rFontName, rCellSize ) );
100         }
101 
102         ColorSharedPtr ImplCanvas::createColor() const
103         {
104             return ColorSharedPtr( new ImplColor( getUNOCanvas()->getDevice() ) );
105         }
106 
107         CanvasSharedPtr ImplCanvas::clone() const
108         {
109             return CanvasSharedPtr( new ImplCanvas( *this ) );
110         }
111 
112         void ImplCanvas::clear() const
113         {
114             OSL_ENSURE( mxCanvas.is(), "ImplCanvas::clear(): Invalid XCanvas" );
115             mxCanvas->clear();
116         }
117 
118         uno::Reference< rendering::XCanvas > ImplCanvas::getUNOCanvas() const
119         {
120             OSL_ENSURE( mxCanvas.is(), "ImplCanvas::getUNOCanvas(): Invalid XCanvas" );
121 
122             return mxCanvas;
123         }
124 
125         rendering::ViewState ImplCanvas::getViewState() const
126         {
127             if( maClipPolyPolygon && !maViewState.Clip.is() )
128             {
129                 if( !mxCanvas.is() )
130                     return maViewState;
131 
132                 maViewState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
133                     mxCanvas->getDevice(),
134                     *maClipPolyPolygon );
135             }
136 
137             return maViewState;
138         }
139 
140     }
141 }
142