Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/cppcanvas/source/uno/uno_mtfrenderer.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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
 */
9
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>
18
19
using namespace ::com::sun::star;
20
21
typedef comphelper::WeakComponentImplHelper<css::rendering::XMtfRenderer, css::beans::XFastPropertySet> MtfRendererBase;
22
23
namespace {
24
25
class MtfRenderer : public MtfRendererBase
26
{
27
public:
28
    MtfRenderer (css::uno::Sequence<css::uno::Any> const& args,
29
                 css::uno::Reference<css::uno::XComponentContext> const&);
30
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;
34
35
    // XFastPropertySet
36
    // setFastPropertyValue (0, GDIMetaFile*) is used to speedup the rendering
37
0
    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;
39
40
private:
41
    GDIMetaFile* mpMetafile;
42
    css::uno::Reference<css::rendering::XBitmapCanvas> mxCanvas;
43
};
44
45
void MtfRenderer::setMetafile (const uno::Sequence< sal_Int8 >& /*rMtf*/)
46
0
{
47
        // printf ("MtfRenderer::setMetafile unimplemented, use fast property set or implement me\n");
48
0
}
49
50
void MtfRenderer::draw (double fScaleX, double fScaleY)
51
0
{
52
0
    if (mpMetafile && mxCanvas) {
53
0
        cppcanvas::BitmapCanvasSharedPtr canvas = cppcanvas::VCLFactory::createBitmapCanvas (mxCanvas);
54
0
        cppcanvas::RendererSharedPtr renderer = cppcanvas::VCLFactory::createRenderer (canvas, *mpMetafile, cppcanvas::Renderer::Parameters ());
55
0
        ::basegfx::B2DHomMatrix aMatrix;
56
0
        aMatrix.scale( fScaleX, fScaleY );
57
0
        canvas->setTransformation( aMatrix );
58
0
        renderer->draw ();
59
0
    }
60
0
}
61
62
void MtfRenderer::setFastPropertyValue( sal_Int32 nHandle, const uno::Any& aAny)
63
0
{
64
0
    if (nHandle == 0) {
65
0
        mpMetafile = reinterpret_cast<GDIMetaFile*>( *o3tl::doAccess<sal_Int64>(aAny) );
66
0
    }
67
0
}
68
69
0
MtfRenderer::MtfRenderer (uno::Sequence<uno::Any> const& aArgs, uno::Reference<uno::XComponentContext> const&) : mpMetafile (nullptr)
70
0
{
71
0
    if( aArgs.getLength() == 1 ) {
72
0
        aArgs[0] >>= mxCanvas;
73
0
    }
74
0
}
75
76
} // namespace
77
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)
81
0
{
82
0
    return cppu::acquire(new MtfRenderer(args, context));
83
0
}
84
85
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */