1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <cppcanvas/vclfactory.hxx>
11 #include <o3tl/any.hxx>
12 #include <com/sun/star/rendering/XMtfRenderer.hpp>
13 #include <com/sun/star/rendering/XBitmapCanvas.hpp>
14 #include <com/sun/star/uno/XComponentContext.hpp>
15 #include <com/sun/star/beans/XFastPropertySet.hpp>
16 #include <cppuhelper/compbase.hxx>
17 #include <cppuhelper/basemutex.hxx>
18 #include <vcl/gdimtf.hxx>
20 using namespace ::com::sun::star
;
22 typedef cppu::WeakComponentImplHelper
<css::rendering::XMtfRenderer
, css::beans::XFastPropertySet
> MtfRendererBase
;
26 class MtfRenderer
: private cppu::BaseMutex
, public MtfRendererBase
29 MtfRenderer (css::uno::Sequence
<css::uno::Any
> const& args
,
30 css::uno::Reference
<css::uno::XComponentContext
> const&);
33 void SAL_CALL
setMetafile (const css::uno::Sequence
< sal_Int8
>& rMtf
) override
;
34 void SAL_CALL
draw (double fScaleX
, double fScaleY
) override
;
37 // setFastPropertyValue (0, GDIMetaFile*) is used to speedup the rendering
38 virtual css::uno::Any SAL_CALL
getFastPropertyValue(sal_Int32
/*nHandle*/) override
{ return css::uno::Any(); }
39 virtual void SAL_CALL
setFastPropertyValue(sal_Int32 nHandle
, const css::uno::Any
&) override
;
42 GDIMetaFile
* mpMetafile
;
43 css::uno::Reference
<css::rendering::XBitmapCanvas
> mxCanvas
;
46 void MtfRenderer::setMetafile (const uno::Sequence
< sal_Int8
>& /*rMtf*/)
48 // printf ("MtfRenderer::setMetafile unimplemented, use fast property set or implement me\n");
51 void MtfRenderer::draw (double fScaleX
, double fScaleY
)
53 if (mpMetafile
&& mxCanvas
) {
54 cppcanvas::BitmapCanvasSharedPtr canvas
= cppcanvas::VCLFactory::createBitmapCanvas (mxCanvas
);
55 cppcanvas::RendererSharedPtr renderer
= cppcanvas::VCLFactory::createRenderer (canvas
, *mpMetafile
, cppcanvas::Renderer::Parameters ());
56 ::basegfx::B2DHomMatrix aMatrix
;
57 aMatrix
.scale( fScaleX
, fScaleY
);
58 canvas
->setTransformation( aMatrix
);
63 void MtfRenderer::setFastPropertyValue( sal_Int32 nHandle
, const uno::Any
& aAny
)
66 mpMetafile
= reinterpret_cast<GDIMetaFile
*>( *o3tl::doAccess
<sal_Int64
>(aAny
) );
70 MtfRenderer::MtfRenderer (uno::Sequence
<uno::Any
> const& aArgs
, uno::Reference
<uno::XComponentContext
> const&) : MtfRendererBase (m_aMutex
), mpMetafile (nullptr)
72 if( aArgs
.getLength() == 1 ) {
73 aArgs
[0] >>= mxCanvas
;
79 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
80 com_sun_star_comp_rendering_MtfRenderer_get_implementation(
81 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const& args
)
83 return cppu::acquire(new MtfRenderer(args
, context
));
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */