Bump version to 24.04.3.4
[LibreOffice.git] / cppcanvas / source / uno / uno_mtfrenderer.cxx
bloba531e0938f9f05f93e40e1f5e69a39755aaa78aa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
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 <comphelper/compbase.hxx>
17 #include <vcl/gdimtf.hxx>
19 using namespace ::com::sun::star;
21 typedef comphelper::WeakComponentImplHelper<css::rendering::XMtfRenderer, css::beans::XFastPropertySet> MtfRendererBase;
23 namespace {
25 class MtfRenderer : public MtfRendererBase
27 public:
28 MtfRenderer (css::uno::Sequence<css::uno::Any> const& args,
29 css::uno::Reference<css::uno::XComponentContext> const&);
31 // XMtfRenderer iface
32 void SAL_CALL setMetafile (const css::uno::Sequence< sal_Int8 >& rMtf) override;
33 void SAL_CALL draw (double fScaleX, double fScaleY) override;
35 // XFastPropertySet
36 // setFastPropertyValue (0, GDIMetaFile*) is used to speedup the rendering
37 virtual css::uno::Any SAL_CALL getFastPropertyValue(sal_Int32 /*nHandle*/) override { return css::uno::Any(); }
38 virtual void SAL_CALL setFastPropertyValue(sal_Int32 nHandle, const css::uno::Any&) override;
40 private:
41 GDIMetaFile* mpMetafile;
42 css::uno::Reference<css::rendering::XBitmapCanvas> mxCanvas;
45 void MtfRenderer::setMetafile (const uno::Sequence< sal_Int8 >& /*rMtf*/)
47 // printf ("MtfRenderer::setMetafile unimplemented, use fast property set or implement me\n");
50 void MtfRenderer::draw (double fScaleX, double fScaleY)
52 if (mpMetafile && mxCanvas) {
53 cppcanvas::BitmapCanvasSharedPtr canvas = cppcanvas::VCLFactory::createBitmapCanvas (mxCanvas);
54 cppcanvas::RendererSharedPtr renderer = cppcanvas::VCLFactory::createRenderer (canvas, *mpMetafile, cppcanvas::Renderer::Parameters ());
55 ::basegfx::B2DHomMatrix aMatrix;
56 aMatrix.scale( fScaleX, fScaleY );
57 canvas->setTransformation( aMatrix );
58 renderer->draw ();
62 void MtfRenderer::setFastPropertyValue( sal_Int32 nHandle, const uno::Any& aAny)
64 if (nHandle == 0) {
65 mpMetafile = reinterpret_cast<GDIMetaFile*>( *o3tl::doAccess<sal_Int64>(aAny) );
69 MtfRenderer::MtfRenderer (uno::Sequence<uno::Any> const& aArgs, uno::Reference<uno::XComponentContext> const&) : mpMetafile (nullptr)
71 if( aArgs.getLength() == 1 ) {
72 aArgs[0] >>= mxCanvas;
76 } // namespace
78 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
79 com_sun_star_comp_rendering_MtfRenderer_get_implementation(
80 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
82 return cppu::acquire(new MtfRenderer(args, context));
85 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */