LibreOffice Module svtools (master) 1
renderer.cxx
Go to the documentation of this file.
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 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20
21#include <com/sun/star/awt/Rectangle.hpp>
22#include <com/sun/star/awt/XDevice.hpp>
23#include <com/sun/star/graphic/XGraphic.hpp>
24#include <com/sun/star/graphic/XGraphicRenderer.hpp>
25#include <com/sun/star/lang/XServiceInfo.hpp>
26#include <com/sun/star/uno/XComponentContext.hpp>
27#include <tools/gen.hxx>
28#include <vcl/svapp.hxx>
34#include <rtl/ref.hxx>
35#include <vcl/GraphicObject.hxx>
36#include <vcl/outdev.hxx>
37
38#define UNOGRAPHIC_DEVICE 1
39#define UNOGRAPHIC_DESTINATIONRECT 2
40#define UNOGRAPHIC_RENDERDATA 3
41
42using namespace ::com::sun::star;
43
44namespace {
45
46class GraphicRendererVCL : public ::cppu::OWeakAggObject,
47 public css::lang::XServiceInfo,
48 public css::lang::XTypeProvider,
50 public css::graphic::XGraphicRenderer
51{
52 static rtl::Reference<::comphelper::PropertySetInfo> createPropertySetInfo();
53
54public:
55
56 GraphicRendererVCL();
57
58 // XInterface
59 virtual css::uno::Any SAL_CALL queryAggregation( const css::uno::Type & rType ) override;
60 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
61 virtual void SAL_CALL acquire() noexcept override;
62 virtual void SAL_CALL release() noexcept override;
63
64 // XServiceInfo
65 virtual OUString SAL_CALL getImplementationName() override;
66 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
67 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
68
69 // XTypeProvider
70 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override;
71 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) override;
72
73 // PropertySetHelper
74 virtual void _setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const css::uno::Any* pValues ) override;
75 virtual void _getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, css::uno::Any* pValue ) override;
76
77 // XGraphicRenderer
78 virtual void SAL_CALL render( const css::uno::Reference< css::graphic::XGraphic >& Graphic ) override;
79
80private:
81
82 css::uno::Reference< css::awt::XDevice > mxDevice;
83
84 VclPtr<OutputDevice> mpOutDev;
85 tools::Rectangle maDestRect;
86 css::uno::Any maRenderData;
87};
88
89GraphicRendererVCL::GraphicRendererVCL() :
90 ::comphelper::PropertySetHelper( createPropertySetInfo() ),
91 mpOutDev( nullptr )
92{
93}
94
95uno::Any SAL_CALL GraphicRendererVCL::queryAggregation( const uno::Type & rType )
96{
97 uno::Any aAny;
98
100 aAny <<= uno::Reference< lang::XServiceInfo >(this);
101 else if( rType == cppu::UnoType<lang::XTypeProvider>::get())
102 aAny <<= uno::Reference< lang::XTypeProvider >(this);
103 else if( rType == cppu::UnoType<beans::XPropertySet>::get())
104 aAny <<= uno::Reference< beans::XPropertySet >(this);
106 aAny <<= uno::Reference< beans::XPropertyState >(this);
108 aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
110 aAny <<= uno::Reference< graphic::XGraphicRenderer >(this);
111 else
112 aAny = OWeakAggObject::queryAggregation( rType );
113
114 return aAny;
115}
116
117
118uno::Any SAL_CALL GraphicRendererVCL::queryInterface( const uno::Type & rType )
119{
120 return OWeakAggObject::queryInterface( rType );
121}
122
123
124void SAL_CALL GraphicRendererVCL::acquire()
125 noexcept
126{
127 OWeakAggObject::acquire();
128}
129
130
131void SAL_CALL GraphicRendererVCL::release()
132 noexcept
133{
134 OWeakAggObject::release();
135}
136
137
138OUString SAL_CALL GraphicRendererVCL::getImplementationName()
139{
140 return "com.sun.star.comp.graphic.GraphicRendererVCL";
141}
142
143sal_Bool SAL_CALL GraphicRendererVCL::supportsService( const OUString& ServiceName )
144{
146}
147
148
149uno::Sequence< OUString > SAL_CALL GraphicRendererVCL::getSupportedServiceNames()
150{
151 return { "com.sun.star.graphic.GraphicRendererVCL" };
152}
153
154
155uno::Sequence< uno::Type > SAL_CALL GraphicRendererVCL::getTypes()
156{
157 static const uno::Sequence< uno::Type > aTypes {
165 return aTypes;
166}
167
168uno::Sequence< sal_Int8 > SAL_CALL GraphicRendererVCL::getImplementationId()
169{
170 return css::uno::Sequence<sal_Int8>();
171}
172
173
174rtl::Reference<::comphelper::PropertySetInfo> GraphicRendererVCL::createPropertySetInfo()
175{
176 static ::comphelper::PropertyMapEntry const aEntries[] =
177 {
178 { OUString("Device"), UNOGRAPHIC_DEVICE, cppu::UnoType<uno::Any>::get(), 0, 0 },
179 { OUString("DestinationRect"), UNOGRAPHIC_DESTINATIONRECT, cppu::UnoType<awt::Rectangle>::get(), 0, 0 },
180 { OUString("RenderData"), UNOGRAPHIC_RENDERDATA, cppu::UnoType<uno::Any>::get(), 0, 0 },
181 };
182
183 return rtl::Reference<::comphelper::PropertySetInfo>( new ::comphelper::PropertySetInfo(aEntries) );
184}
185
186
187void GraphicRendererVCL::_setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const uno::Any* pValues )
188{
189 SolarMutexGuard aGuard;
190
191 while( *ppEntries )
192 {
193 switch( (*ppEntries)->mnHandle )
194 {
196 {
197 uno::Reference< awt::XDevice > xDevice;
198
199 if( ( *pValues >>= xDevice ) && xDevice.is() )
200 {
201 mxDevice = xDevice;
202 mpOutDev = VCLUnoHelper::GetOutputDevice( xDevice );
203 }
204 else
205 {
206 mxDevice.clear();
207 mpOutDev = nullptr;
208 }
209 }
210 break;
211
213 {
214 awt::Rectangle aAWTRect;
215
216 if( *pValues >>= aAWTRect )
217 {
218 maDestRect = tools::Rectangle( Point( aAWTRect.X, aAWTRect.Y ),
219 Size( aAWTRect.Width, aAWTRect.Height ) );
220 }
221 }
222 break;
223
225 {
226 maRenderData = *pValues;
227 }
228 break;
229 }
230
231 ++ppEntries;
232 ++pValues;
233 }
234}
235
236
237void GraphicRendererVCL::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValues )
238{
239 SolarMutexGuard aGuard;
240
241 while( *ppEntries )
242 {
243 switch( (*ppEntries)->mnHandle )
244 {
246 {
247 if( mxDevice.is() )
248 *pValues <<= mxDevice;
249 }
250 break;
251
253 {
254 const awt::Rectangle aAWTRect( maDestRect.Left(), maDestRect.Top(),
255 maDestRect.GetWidth(), maDestRect.GetHeight() );
256
257 *pValues <<= aAWTRect;
258 }
259 break;
260
262 {
263 *pValues = maRenderData;
264 }
265 break;
266 }
267
268 ++ppEntries;
269 ++pValues;
270 }
271}
272
273void SAL_CALL GraphicRendererVCL::render( const uno::Reference< graphic::XGraphic >& rxGraphic )
274{
275 if( mpOutDev && mxDevice.is() && rxGraphic.is() )
276 {
277 Graphic aGraphic(rxGraphic);
278 if (!aGraphic.IsNone())
279 {
280 GraphicObject aGraphicObject(std::move(aGraphic));
281 aGraphicObject.Draw(*mpOutDev, maDestRect.TopLeft(), maDestRect.GetSize());
282 }
283 }
284}
285
286}
287
288extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
290 css::uno::XComponentContext *,
291 css::uno::Sequence<css::uno::Any> const &)
292{
293 return cppu::acquire(new GraphicRendererVCL);
294}
295
296/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const PropertyValue * pValues
bool Draw(OutputDevice &rOut, const Point &rPt, const Size &rSz, const GraphicAttr *pAttr=nullptr) const
bool IsNone() const
static OutputDevice * GetOutputDevice(const css::uno::Reference< css::awt::XDevice > &rxDevice)
virtual void _getPropertyValues(const comphelper::PropertyMapEntry **ppEntries, css::uno::Any *pValue)=0
virtual void _setPropertyValues(const comphelper::PropertyMapEntry **ppEntries, const css::uno::Any *pValues)=0
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &rType) SAL_OVERRIDE
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) SAL_OVERRIDE
virtual void SAL_CALL acquire() SAL_NOEXCEPT SAL_OVERRIDE
virtual void SAL_CALL release() SAL_NOEXCEPT SAL_OVERRIDE
css::uno::Type const & get()
ScXMLEditAttributeMap::Entry const aEntries[]
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
#define UNOGRAPHIC_RENDERDATA
Definition: renderer.cxx:40
#define UNOGRAPHIC_DEVICE
Definition: renderer.cxx:38
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_graphic_GraphicRendererVCL_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
Definition: renderer.cxx:289
#define UNOGRAPHIC_DESTINATIONRECT
Definition: renderer.cxx:39
unsigned char sal_Bool
const SvXMLTokenMapEntry aTypes[]