1*25ea7f45SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*25ea7f45SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*25ea7f45SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*25ea7f45SAndrew Rist  * distributed with this work for additional information
6*25ea7f45SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*25ea7f45SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*25ea7f45SAndrew Rist  * "License"); you may not use this file except in compliance
9*25ea7f45SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*25ea7f45SAndrew Rist  *
11*25ea7f45SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*25ea7f45SAndrew Rist  *
13*25ea7f45SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*25ea7f45SAndrew Rist  * software distributed under the License is distributed on an
15*25ea7f45SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*25ea7f45SAndrew Rist  * KIND, either express or implied.  See the License for the
17*25ea7f45SAndrew Rist  * specific language governing permissions and limitations
18*25ea7f45SAndrew Rist  * under the License.
19*25ea7f45SAndrew Rist  *
20*25ea7f45SAndrew Rist  *************************************************************/
21*25ea7f45SAndrew Rist 
22*25ea7f45SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_canvas.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/rendering/XSimpleCanvas.hpp>
28cdf0e10cSrcweir #include <com/sun/star/rendering/CompositeOperation.hpp>
29cdf0e10cSrcweir #include <com/sun/star/rendering/PanoseLetterForm.hpp>
30cdf0e10cSrcweir #include <com/sun/star/rendering/PanoseWeight.hpp>
31cdf0e10cSrcweir #include <com/sun/star/lang/XServiceName.hpp>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <o3tl/lazy_update.hxx>
34cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
35cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx>
36cdf0e10cSrcweir #include <cppuhelper/compbase2.hxx>
37cdf0e10cSrcweir #include <cppuhelper/basemutex.hxx>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <comphelper/servicedecl.hxx>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
42cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #include "canvas/canvastools.hxx"
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #include <boost/bind.hpp>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #define SERVICE_NAME "com.sun.star.rendering.SimpleCanvas"
49cdf0e10cSrcweir 
50cdf0e10cSrcweir using namespace ::com::sun::star;
51cdf0e10cSrcweir using namespace canvas;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir namespace
54cdf0e10cSrcweir {
color2Sequence(sal_Int32 const & nColor)55cdf0e10cSrcweir     inline uno::Sequence< double > color2Sequence( sal_Int32 const& nColor  	)
56cdf0e10cSrcweir     {
57cdf0e10cSrcweir         // TODO(F3): Color management
58cdf0e10cSrcweir         uno::Sequence< double > aRes( 4 );
59cdf0e10cSrcweir 
60cdf0e10cSrcweir         aRes[0] = static_cast<sal_uInt8>( (nColor&0xFF000000U) >> 24U ) / 255.0;
61cdf0e10cSrcweir         aRes[1] = static_cast<sal_uInt8>( (nColor&0x00FF0000U) >> 16U ) / 255.0;
62cdf0e10cSrcweir         aRes[2] = static_cast<sal_uInt8>( (nColor&0x0000FF00U) >>  8U ) / 255.0;
63cdf0e10cSrcweir         aRes[3] = static_cast<sal_uInt8>( (nColor&0x000000FFU) )        / 255.0;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir         return aRes;
66cdf0e10cSrcweir     }
67cdf0e10cSrcweir 
rect2Poly(uno::Reference<rendering::XGraphicDevice> const & xDevice,geometry::RealRectangle2D const & rRect)68cdf0e10cSrcweir     inline uno::Reference< rendering::XPolyPolygon2D > rect2Poly( uno::Reference<rendering::XGraphicDevice> const& xDevice,
69cdf0e10cSrcweir                                                                   geometry::RealRectangle2D const&                 rRect )
70cdf0e10cSrcweir     {
71cdf0e10cSrcweir         uno::Sequence< geometry::RealPoint2D > rectSequence( 4 );
72cdf0e10cSrcweir         geometry::RealPoint2D* pOutput = rectSequence.getArray();
73cdf0e10cSrcweir         pOutput[0] = geometry::RealPoint2D( rRect.X1, rRect.Y1 );
74cdf0e10cSrcweir         pOutput[1] = geometry::RealPoint2D( rRect.X2, rRect.Y1 );
75cdf0e10cSrcweir         pOutput[2] = geometry::RealPoint2D( rRect.X2, rRect.Y2 );
76cdf0e10cSrcweir         pOutput[3] = geometry::RealPoint2D( rRect.X1, rRect.Y2 );
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         uno::Sequence< uno::Sequence< geometry::RealPoint2D > > sequenceSequence( 1 );
79cdf0e10cSrcweir         sequenceSequence[0] = rectSequence;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir         uno::Reference< rendering::XPolyPolygon2D > xRes(
82cdf0e10cSrcweir             xDevice->createCompatibleLinePolyPolygon( sequenceSequence ),
83cdf0e10cSrcweir             uno::UNO_QUERY );
84cdf0e10cSrcweir         if( xRes.is() )
85cdf0e10cSrcweir             xRes->setClosed( 0, sal_True );
86cdf0e10cSrcweir         return xRes;
87cdf0e10cSrcweir     }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     struct SimpleRenderState
90cdf0e10cSrcweir     {
91cdf0e10cSrcweir         o3tl::LazyUpdate<sal_Int32,
92cdf0e10cSrcweir                          uno::Sequence<double>,
93cdf0e10cSrcweir                          o3tl::LAZYUPDATE_FUNCTION_TAG >              m_aPenColor;
94cdf0e10cSrcweir         o3tl::LazyUpdate<sal_Int32,
95cdf0e10cSrcweir                          uno::Sequence<double>,
96cdf0e10cSrcweir                          o3tl::LAZYUPDATE_FUNCTION_TAG >              m_aFillColor;
97cdf0e10cSrcweir         o3tl::LazyUpdate<geometry::RealRectangle2D,
98cdf0e10cSrcweir                          uno::Reference< rendering::XPolyPolygon2D >,
99cdf0e10cSrcweir                          o3tl::LAZYUPDATE_FUNCTOR_TAG >               m_aRectClip;
100cdf0e10cSrcweir         geometry::AffineMatrix2D                                      m_aTransformation;
101cdf0e10cSrcweir 
SimpleRenderState__anonb6634b2f0111::SimpleRenderState102cdf0e10cSrcweir         explicit SimpleRenderState( uno::Reference<rendering::XGraphicDevice> const& xDevice ) :
103cdf0e10cSrcweir             m_aPenColor( &color2Sequence),
104cdf0e10cSrcweir             m_aFillColor( &color2Sequence ),
105cdf0e10cSrcweir             m_aRectClip( boost::bind( &rect2Poly,
106cdf0e10cSrcweir                                       xDevice,
107cdf0e10cSrcweir                                       _1 )),
108cdf0e10cSrcweir             m_aTransformation()
109cdf0e10cSrcweir         {
110cdf0e10cSrcweir             tools::setIdentityAffineMatrix2D( m_aTransformation );
111cdf0e10cSrcweir         }
112cdf0e10cSrcweir     };
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     typedef ::cppu::WeakComponentImplHelper2< ::com::sun::star::rendering::XSimpleCanvas,
116cdf0e10cSrcweir                                               ::com::sun::star::lang::XServiceName >	SimpleCanvasBase;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir     class SimpleCanvasImpl : private cppu::BaseMutex,
119cdf0e10cSrcweir                              public SimpleCanvasBase
120cdf0e10cSrcweir     {
121cdf0e10cSrcweir     private:
isStrokingEnabled() const122cdf0e10cSrcweir         bool isStrokingEnabled() const
123cdf0e10cSrcweir         {
124cdf0e10cSrcweir             return maRenderState.m_aPenColor.getInValue() && sal_Int32(0xFF) != 0;
125cdf0e10cSrcweir         }
126cdf0e10cSrcweir 
createStrokingRenderState() const127cdf0e10cSrcweir         rendering::RenderState createStrokingRenderState() const
128cdf0e10cSrcweir         {
129cdf0e10cSrcweir             return rendering::RenderState(maRenderState.m_aTransformation,
130cdf0e10cSrcweir                                           *maRenderState.m_aRectClip,
131cdf0e10cSrcweir                                           *maRenderState.m_aPenColor,
132cdf0e10cSrcweir                                           rendering::CompositeOperation::OVER);
133cdf0e10cSrcweir         }
134cdf0e10cSrcweir 
isFillingEnabled() const135cdf0e10cSrcweir         bool isFillingEnabled() const
136cdf0e10cSrcweir         {
137cdf0e10cSrcweir             return maRenderState.m_aFillColor.getInValue() && sal_Int32(0xFF) != 0;
138cdf0e10cSrcweir         }
139cdf0e10cSrcweir 
createFillingRenderState() const140cdf0e10cSrcweir         rendering::RenderState createFillingRenderState() const
141cdf0e10cSrcweir         {
142cdf0e10cSrcweir             return rendering::RenderState(maRenderState.m_aTransformation,
143cdf0e10cSrcweir                                           *maRenderState.m_aRectClip,
144cdf0e10cSrcweir                                           *maRenderState.m_aFillColor,
145cdf0e10cSrcweir                                           rendering::CompositeOperation::OVER);
146cdf0e10cSrcweir         }
147cdf0e10cSrcweir 
grabCanvas(uno::Sequence<uno::Any> const & rArgs)148cdf0e10cSrcweir         static uno::Reference<rendering::XCanvas> grabCanvas( uno::Sequence<uno::Any> const& rArgs )
149cdf0e10cSrcweir         {
150cdf0e10cSrcweir             uno::Reference<rendering::XCanvas> xRet;
151cdf0e10cSrcweir 
152cdf0e10cSrcweir             // can't do much without an XCanvas, can't we?
153cdf0e10cSrcweir             if( rArgs.getLength() < 1 )
154cdf0e10cSrcweir                 throw lang::IllegalArgumentException();
155cdf0e10cSrcweir 
156cdf0e10cSrcweir             xRet.set( rArgs[0], uno::UNO_QUERY );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir             // can't do much without an XCanvas, can't we?
159cdf0e10cSrcweir             if( !xRet.is() )
160cdf0e10cSrcweir                 throw lang::IllegalArgumentException();
161cdf0e10cSrcweir 
162cdf0e10cSrcweir             return xRet;
163cdf0e10cSrcweir         }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     public:
SimpleCanvasImpl(const uno::Sequence<uno::Any> & aArguments,const uno::Reference<uno::XComponentContext> &)166cdf0e10cSrcweir         SimpleCanvasImpl( const uno::Sequence< uno::Any >&                aArguments,
167cdf0e10cSrcweir                           const uno::Reference< uno::XComponentContext >&  ) :
168cdf0e10cSrcweir             SimpleCanvasBase( m_aMutex ),
169cdf0e10cSrcweir             mxCanvas( grabCanvas(aArguments) ),
170cdf0e10cSrcweir             maFont(boost::bind( &rendering::XCanvas::createFont,
171cdf0e10cSrcweir                                 boost::cref(mxCanvas),
172cdf0e10cSrcweir                                 _1,
173cdf0e10cSrcweir                                 uno::Sequence< beans::PropertyValue >(),
174cdf0e10cSrcweir                                 geometry::Matrix2D() )),
175cdf0e10cSrcweir             maViewState(),
176cdf0e10cSrcweir             maRenderState( mxCanvas->getDevice() )
177cdf0e10cSrcweir         {
178cdf0e10cSrcweir             tools::initViewState(maViewState);
179cdf0e10cSrcweir         }
180cdf0e10cSrcweir 
181cdf0e10cSrcweir         ///////////////////////////////////////////////////////////////////////////////////////////////
182cdf0e10cSrcweir 
183cdf0e10cSrcweir     private:
184cdf0e10cSrcweir         // Ifc XServiceName
getServiceName()185cdf0e10cSrcweir         virtual ::rtl::OUString SAL_CALL getServiceName(  ) throw (uno::RuntimeException)
186cdf0e10cSrcweir         {
187cdf0e10cSrcweir             return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) );
188cdf0e10cSrcweir         }
189cdf0e10cSrcweir 
190cdf0e10cSrcweir         // Ifc XSimpleCanvas
selectFont(const::rtl::OUString & sFontName,double size,::sal_Bool bold,::sal_Bool italic)191cdf0e10cSrcweir         virtual void SAL_CALL selectFont( const ::rtl::OUString& sFontName,
192cdf0e10cSrcweir                                           double                 size,
193cdf0e10cSrcweir                                           ::sal_Bool             bold,
194cdf0e10cSrcweir                                           ::sal_Bool             italic ) throw (uno::RuntimeException)
195cdf0e10cSrcweir         {
196cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
197cdf0e10cSrcweir 
198cdf0e10cSrcweir             maFont->FontDescription.FamilyName = sFontName;
199cdf0e10cSrcweir             maFont->CellSize = size;
200cdf0e10cSrcweir             maFont->FontDescription.FontDescription.Weight =
201cdf0e10cSrcweir                 bold ? rendering::PanoseWeight::BOLD : rendering::PanoseWeight::MEDIUM;
202cdf0e10cSrcweir             maFont->FontDescription.FontDescription.Letterform =
203cdf0e10cSrcweir                 italic ? rendering::PanoseLetterForm::OBLIQUE_CONTACT : rendering::PanoseLetterForm::ANYTHING;
204cdf0e10cSrcweir         }
205cdf0e10cSrcweir 
setPenColor(::sal_Int32 nsRgbaColor)206cdf0e10cSrcweir         virtual void SAL_CALL setPenColor( ::sal_Int32 nsRgbaColor ) throw (uno::RuntimeException)
207cdf0e10cSrcweir         {
208cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
209cdf0e10cSrcweir             *(maRenderState.m_aPenColor) = nsRgbaColor;
210cdf0e10cSrcweir         }
211cdf0e10cSrcweir 
setFillColor(::sal_Int32 nsRgbaColor)212cdf0e10cSrcweir         virtual void SAL_CALL setFillColor( ::sal_Int32 nsRgbaColor ) throw (uno::RuntimeException)
213cdf0e10cSrcweir         {
214cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
215cdf0e10cSrcweir             *(maRenderState.m_aFillColor) = nsRgbaColor;
216cdf0e10cSrcweir         }
217cdf0e10cSrcweir 
setRectClip(const geometry::RealRectangle2D & aRect)218cdf0e10cSrcweir         virtual void SAL_CALL setRectClip( const geometry::RealRectangle2D& aRect ) throw (uno::RuntimeException)
219cdf0e10cSrcweir         {
220cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
221cdf0e10cSrcweir             *(maRenderState.m_aRectClip) = aRect;
222cdf0e10cSrcweir         }
223cdf0e10cSrcweir 
setTransformation(const geometry::AffineMatrix2D & aTransform)224cdf0e10cSrcweir         virtual void SAL_CALL setTransformation( const geometry::AffineMatrix2D& aTransform ) throw (uno::RuntimeException)
225cdf0e10cSrcweir         {
226cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
227cdf0e10cSrcweir             maRenderState.m_aTransformation = aTransform;
228cdf0e10cSrcweir         }
229cdf0e10cSrcweir 
drawPixel(const geometry::RealPoint2D & aPoint)230cdf0e10cSrcweir         virtual void SAL_CALL drawPixel( const geometry::RealPoint2D& aPoint ) throw (uno::RuntimeException)
231cdf0e10cSrcweir         {
232cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
233cdf0e10cSrcweir             mxCanvas->drawPoint(aPoint,
234cdf0e10cSrcweir                                 maViewState,
235cdf0e10cSrcweir                                 createFillingRenderState());
236cdf0e10cSrcweir         }
237cdf0e10cSrcweir 
drawLine(const geometry::RealPoint2D & aStartPoint,const geometry::RealPoint2D & aEndPoint)238cdf0e10cSrcweir         virtual void SAL_CALL drawLine( const geometry::RealPoint2D& aStartPoint,
239cdf0e10cSrcweir                                         const geometry::RealPoint2D& aEndPoint ) throw (uno::RuntimeException)
240cdf0e10cSrcweir         {
241cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
242cdf0e10cSrcweir             mxCanvas->drawLine(aStartPoint,
243cdf0e10cSrcweir                                aEndPoint,
244cdf0e10cSrcweir                                maViewState,
245cdf0e10cSrcweir                                createStrokingRenderState());
246cdf0e10cSrcweir         }
247cdf0e10cSrcweir 
drawRect(const geometry::RealRectangle2D & aRect)248cdf0e10cSrcweir         virtual void SAL_CALL drawRect( const geometry::RealRectangle2D& aRect ) throw (uno::RuntimeException)
249cdf0e10cSrcweir         {
250cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
251cdf0e10cSrcweir             uno::Reference< rendering::XPolyPolygon2D > xPoly(
252cdf0e10cSrcweir                 rect2Poly( mxCanvas->getDevice(),
253cdf0e10cSrcweir                            aRect));
254cdf0e10cSrcweir 
255cdf0e10cSrcweir             if( isFillingEnabled() )
256cdf0e10cSrcweir                 mxCanvas->drawPolyPolygon(xPoly,
257cdf0e10cSrcweir                                           maViewState,
258cdf0e10cSrcweir                                           createFillingRenderState());
259cdf0e10cSrcweir             if( isStrokingEnabled() )
260cdf0e10cSrcweir                 mxCanvas->drawPolyPolygon(xPoly,
261cdf0e10cSrcweir                                           maViewState,
262cdf0e10cSrcweir                                           createStrokingRenderState());
263cdf0e10cSrcweir         }
264cdf0e10cSrcweir 
drawPolyPolygon(const uno::Reference<rendering::XPolyPolygon2D> & xPolyPolygon)265cdf0e10cSrcweir         virtual void SAL_CALL drawPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon ) throw (uno::RuntimeException)
266cdf0e10cSrcweir         {
267cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
268cdf0e10cSrcweir 
269cdf0e10cSrcweir             if( isFillingEnabled() )
270cdf0e10cSrcweir                 mxCanvas->drawPolyPolygon(xPolyPolygon,
271cdf0e10cSrcweir                                           maViewState,
272cdf0e10cSrcweir                                           createFillingRenderState());
273cdf0e10cSrcweir             if( isStrokingEnabled() )
274cdf0e10cSrcweir                 mxCanvas->drawPolyPolygon(xPolyPolygon,
275cdf0e10cSrcweir                                           maViewState,
276cdf0e10cSrcweir                                           createStrokingRenderState());
277cdf0e10cSrcweir         }
278cdf0e10cSrcweir 
drawText(const rendering::StringContext & aText,const geometry::RealPoint2D & aOutPos,::sal_Int8 nTextDirection)279cdf0e10cSrcweir         virtual void SAL_CALL drawText( const rendering::StringContext& aText,
280cdf0e10cSrcweir                                         const geometry::RealPoint2D&    aOutPos,
281cdf0e10cSrcweir                                         ::sal_Int8                      nTextDirection ) throw (uno::RuntimeException)
282cdf0e10cSrcweir         {
283cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
284cdf0e10cSrcweir             const basegfx::B2DHomMatrix offsetTransform(basegfx::tools::createTranslateB2DHomMatrix(aOutPos.X,aOutPos.Y));
285cdf0e10cSrcweir             rendering::RenderState aRenderState( createStrokingRenderState() );
286cdf0e10cSrcweir             tools::appendToRenderState(aRenderState, offsetTransform);
287cdf0e10cSrcweir 
288cdf0e10cSrcweir             mxCanvas->drawText(aText,
289cdf0e10cSrcweir                                maFont.getOutValue(),
290cdf0e10cSrcweir                                maViewState,
291cdf0e10cSrcweir                                aRenderState,
292cdf0e10cSrcweir                                nTextDirection);
293cdf0e10cSrcweir         }
294cdf0e10cSrcweir 
drawBitmap(const uno::Reference<rendering::XBitmap> & xBitmap,const geometry::RealPoint2D & aLeftTop)295cdf0e10cSrcweir         virtual void SAL_CALL drawBitmap( const uno::Reference< rendering::XBitmap >& xBitmap,
296cdf0e10cSrcweir                                           const geometry::RealPoint2D&                aLeftTop ) throw (uno::RuntimeException)
297cdf0e10cSrcweir         {
298cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
299cdf0e10cSrcweir             const basegfx::B2DHomMatrix offsetTransform(basegfx::tools::createTranslateB2DHomMatrix(aLeftTop.X,aLeftTop.Y));
300cdf0e10cSrcweir             rendering::RenderState aRenderState( createStrokingRenderState() );
301cdf0e10cSrcweir             tools::appendToRenderState(aRenderState, offsetTransform);
302cdf0e10cSrcweir 
303cdf0e10cSrcweir             mxCanvas->drawBitmap(xBitmap,maViewState,aRenderState);
304cdf0e10cSrcweir         }
305cdf0e10cSrcweir 
getDevice()306cdf0e10cSrcweir         virtual uno::Reference< rendering::XGraphicDevice > SAL_CALL getDevice(  ) throw (uno::RuntimeException)
307cdf0e10cSrcweir         {
308cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
309cdf0e10cSrcweir             return mxCanvas->getDevice();
310cdf0e10cSrcweir         }
311cdf0e10cSrcweir 
getCanvas()312cdf0e10cSrcweir         virtual uno::Reference< rendering::XCanvas > SAL_CALL getCanvas(  ) throw (uno::RuntimeException)
313cdf0e10cSrcweir         {
314cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
315cdf0e10cSrcweir             return mxCanvas;
316cdf0e10cSrcweir         }
317cdf0e10cSrcweir 
getFontMetrics()318cdf0e10cSrcweir         virtual rendering::FontMetrics SAL_CALL getFontMetrics(  ) throw (uno::RuntimeException)
319cdf0e10cSrcweir         {
320cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
321cdf0e10cSrcweir             return maFont.getOutValue()->getFontMetrics();
322cdf0e10cSrcweir         }
323cdf0e10cSrcweir 
getCurrentFont()324cdf0e10cSrcweir         virtual uno::Reference< rendering::XCanvasFont > SAL_CALL getCurrentFont(  ) throw (uno::RuntimeException)
325cdf0e10cSrcweir         {
326cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
327cdf0e10cSrcweir             return maFont.getOutValue();
328cdf0e10cSrcweir         }
329cdf0e10cSrcweir 
getCurrentPenColor()330cdf0e10cSrcweir         virtual ::sal_Int32 SAL_CALL getCurrentPenColor(  ) throw (uno::RuntimeException)
331cdf0e10cSrcweir         {
332cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
333cdf0e10cSrcweir             return maRenderState.m_aPenColor.getInValue();
334cdf0e10cSrcweir         }
335cdf0e10cSrcweir 
getCurrentFillColor()336cdf0e10cSrcweir         virtual ::sal_Int32 SAL_CALL getCurrentFillColor(  ) throw (uno::RuntimeException)
337cdf0e10cSrcweir         {
338cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
339cdf0e10cSrcweir             return maRenderState.m_aFillColor.getInValue();
340cdf0e10cSrcweir         }
341cdf0e10cSrcweir 
getCurrentClipRect()342cdf0e10cSrcweir         virtual geometry::RealRectangle2D SAL_CALL getCurrentClipRect(  ) throw (uno::RuntimeException)
343cdf0e10cSrcweir         {
344cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
345cdf0e10cSrcweir             return maRenderState.m_aRectClip.getInValue();
346cdf0e10cSrcweir         }
347cdf0e10cSrcweir 
getCurrentTransformation()348cdf0e10cSrcweir         virtual geometry::AffineMatrix2D SAL_CALL getCurrentTransformation(  ) throw (uno::RuntimeException)
349cdf0e10cSrcweir         {
350cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
351cdf0e10cSrcweir             return maRenderState.m_aTransformation;
352cdf0e10cSrcweir         }
353cdf0e10cSrcweir 
getCurrentViewState()354cdf0e10cSrcweir         virtual rendering::ViewState SAL_CALL getCurrentViewState(  ) throw (uno::RuntimeException)
355cdf0e10cSrcweir         {
356cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
357cdf0e10cSrcweir             return maViewState;
358cdf0e10cSrcweir         }
359cdf0e10cSrcweir 
getCurrentRenderState(sal_Bool bUseFillColor)360cdf0e10cSrcweir         virtual rendering::RenderState SAL_CALL getCurrentRenderState( sal_Bool bUseFillColor ) throw (uno::RuntimeException)
361cdf0e10cSrcweir         {
362cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
363cdf0e10cSrcweir             if( bUseFillColor )
364cdf0e10cSrcweir                 return createFillingRenderState();
365cdf0e10cSrcweir             else
366cdf0e10cSrcweir                 return createStrokingRenderState();
367cdf0e10cSrcweir         }
368cdf0e10cSrcweir 
369cdf0e10cSrcweir         ///////////////////////////////////////////////////////////////////////////////////////////////
370cdf0e10cSrcweir 
371cdf0e10cSrcweir         typedef o3tl::LazyUpdate<
372cdf0e10cSrcweir             rendering::FontRequest,
373cdf0e10cSrcweir             uno::Reference< rendering::XCanvasFont >,
374cdf0e10cSrcweir             o3tl::LAZYUPDATE_FUNCTOR_TAG > SimpleFont;
375cdf0e10cSrcweir 
376cdf0e10cSrcweir         uno::Reference<rendering::XCanvas> mxCanvas;
377cdf0e10cSrcweir         SimpleFont                         maFont;
378cdf0e10cSrcweir         rendering::ViewState               maViewState;
379cdf0e10cSrcweir         SimpleRenderState                  maRenderState;
380cdf0e10cSrcweir     };
381cdf0e10cSrcweir 
382cdf0e10cSrcweir     namespace sdecl = comphelper::service_decl;
383cdf0e10cSrcweir #if defined (__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ <= 3)
384cdf0e10cSrcweir     sdecl::class_<SimpleCanvasImpl, sdecl::with_args<true> > serviceImpl;
385cdf0e10cSrcweir     const sdecl::ServiceDecl simpleCanvasDecl(
386cdf0e10cSrcweir         serviceImpl,
387cdf0e10cSrcweir #else
388cdf0e10cSrcweir     const sdecl::ServiceDecl simpleCanvasDecl(
389cdf0e10cSrcweir         sdecl::class_<SimpleCanvasImpl, sdecl::with_args<true> >(),
390cdf0e10cSrcweir #endif
391cdf0e10cSrcweir         "com.sun.star.comp.rendering.SimpleCanvas",
392cdf0e10cSrcweir         SERVICE_NAME );
393cdf0e10cSrcweir }
394cdf0e10cSrcweir 
395cdf0e10cSrcweir // The C shared lib entry points
396cdf0e10cSrcweir COMPHELPER_SERVICEDECL_EXPORTS1(simpleCanvasDecl)
397