| 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 |
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 |
{ |
| 47 |
// printf ("MtfRenderer::setMetafile unimplemented, use fast property set or implement me\n"); |
| 48 |
} |
| 49 |
|
| 50 |
void MtfRenderer::draw (double fScaleX, double fScaleY) |
| 51 |
{ |
| 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 (); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
void MtfRenderer::setFastPropertyValue( sal_Int32 nHandle, const uno::Any& aAny) |
| 63 |
{ |
| 64 |
if (nHandle == 0) { |
| 65 |
mpMetafile = reinterpret_cast<GDIMetaFile*>( *o3tl::doAccess<sal_Int64>(aAny) ); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
MtfRenderer::MtfRenderer (uno::Sequence<uno::Any> const& aArgs, uno::Reference<uno::XComponentContext> const&) : mpMetafile (nullptr) |
| 70 |
{ |
| 71 |
if( aArgs.getLength() == 1 ) { |
| 72 |
aArgs[0] >>= mxCanvas; |
| 73 |
} |
| 74 |
} |
| 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 |
{ |
| 82 |
return cppu::acquire(new MtfRenderer(args, context)); |
| 83 |
} |
| 84 |
|
| 85 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |