Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <vcl/graph.hxx>
31 : : #include <vcl/bmpacc.hxx>
32 : : #include <vcl/alpha.hxx>
33 : : #include <com/sun/star/graphic/XGraphicRasterizer.hpp>
34 : : #include <com/sun/star/lang/XServiceInfo.hpp>
35 : : #include <com/sun/star/io/XSeekable.hpp>
36 : : #include <cppuhelper/implbase2.hxx>
37 : : #include <osl/module.h>
38 : :
39 : : #include <cairo.h>
40 : :
41 : : #include <vector>
42 : :
43 : : #if defined MACOSX
44 : : #define VCL_RSVG_GOBJECT_LIBNAME "libgobject-2.0.0.dylib"
45 : : #define VCL_RSVG_LIBRSVG_LIBNAME "librsvg-2.2.dylib"
46 : : #elif defined UNX
47 : : #define VCL_RSVG_GOBJECT_LIBNAME "libgobject-2.0.so.0"
48 : : #define VCL_RSVG_LIBRSVG_LIBNAME "librsvg-2.so.2"
49 : : #elif defined WNT
50 : : #define VCL_RSVG_GOBJECT_LIBNAME "gobjectlo.dll"
51 : : #define VCL_RSVG_LIBRSVG_LIBNAME "librsvg-2-2.dll"
52 : : #else
53 : : #define VCL_RSVG_GOBJECT_LIBNAME "nogobjectlib"
54 : : #define VCL_RSVG_LIBRSVG_LIBNAME "nolibrsvglib"
55 : : #endif
56 : :
57 : : using namespace ::com::sun::star;
58 : :
59 : : // -----------------------------------------------------
60 : : // - external stuff for dynamic library function calls -
61 : : // -----------------------------------------------------
62 : :
63 : : typedef int gboolean;
64 : : typedef unsigned char guint8;
65 : : typedef sal_Size gsize;
66 : : typedef void* gpointer;
67 : :
68 : : struct GError;
69 : :
70 : : struct RsvgHandle;
71 : : struct RsvgDimensionData
72 : : {
73 : : int width;
74 : : int height;
75 : : double em;
76 : : double ex;
77 : : };
78 : :
79 : : namespace vcl
80 : : {
81 : : namespace rsvg
82 : : {
83 : : // -----------------
84 : : // - Uno functions -
85 : : // ----------------
86 : :
87 : 0 : uno::Sequence< ::rtl::OUString > Rasterizer_getSupportedServiceNames()
88 : : {
89 [ # # ][ # # ]: 0 : static ::rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.graphic.GraphicRasterizer_RSVG" ) );
[ # # ][ # # ]
90 [ # # ][ # # ]: 0 : static uno::Sequence< ::rtl::OUString > aServiceNames( &aServiceName, 1 );
[ # # ][ # # ]
91 : :
92 : 0 : return( aServiceNames );
93 : : }
94 : :
95 : : // -----------------------------------------------------------------------------
96 : :
97 : 0 : ::rtl::OUString Rasterizer_getImplementationName()
98 : : {
99 : 0 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "vcl::rsvg::Rasterizer" ) );
100 : : }
101 : :
102 : : // ------------------
103 : : // - LibraryWrapper -
104 : : // ------------------
105 : :
106 : : class LibraryWrapper
107 : : {
108 : : public:
109 : :
110 : : static LibraryWrapper& get();
111 : :
112 [ # # ][ # # ]: 0 : bool isValid() const { return( ( mpGObjectLib != NULL ) && ( mpRSVGLib != NULL ) ); }
113 : :
114 : : // G-Object
115 : 0 : gpointer g_object_unref( gpointer pointer ) { return( (*mp_g_object_unref)( pointer ) ); };
116 : :
117 : : // LibRSVG
118 : 0 : void rsvg_init() { (*mp_rsvg_init)(); }
119 : 0 : RsvgHandle* rsvg_handle_new_from_data( const guint8* data, gsize size, GError** error) { return( (*mp_rsvg_handle_new_from_data)( data, size, error ) ); }
120 : 0 : void rsvg_handle_set_dpi_x_y( RsvgHandle* handle, double dpix, double dpiy ) { (*mp_rsvg_handle_set_dpi_x_y)( handle, dpix, dpiy ); }
121 : 0 : void rsvg_handle_get_dimensions( RsvgHandle* handle, RsvgDimensionData* dimensions ) { (*mp_rsvg_handle_get_dimensions)( handle, dimensions ); }
122 : 0 : gboolean rsvg_handle_render_cairo( RsvgHandle* handle, cairo_t* cairo ) { return( (*mp_rsvg_handle_render_cairo)( handle, cairo ) ); }
123 : :
124 : : private:
125 : :
126 : : LibraryWrapper();
127 : :
128 : : private:
129 : :
130 : : oslModule mpGObjectLib;
131 : : oslModule mpRSVGLib;
132 : :
133 : : // GObject
134 : : gpointer (*mp_g_object_unref)( gpointer );
135 : :
136 : : // LibRSVG
137 : : void (*mp_rsvg_init)( void );
138 : : RsvgHandle* (*mp_rsvg_handle_new_from_data)( const guint8*, gsize, GError** );
139 : : void (*mp_rsvg_handle_set_dpi_x_y)( RsvgHandle*, double, double );
140 : : void (*mp_rsvg_handle_get_dimensions)( RsvgHandle*, RsvgDimensionData* );
141 : : gboolean (*mp_rsvg_handle_render_cairo)( RsvgHandle*, cairo_t* );
142 : : };
143 : :
144 : : // -----------------------------------------------------------------------------
145 : :
146 : 0 : LibraryWrapper& LibraryWrapper::get()
147 : : {
148 : : static LibraryWrapper* pLibraryInstance = NULL;
149 : :
150 [ # # ]: 0 : if( !pLibraryInstance )
151 [ # # ]: 0 : pLibraryInstance = new LibraryWrapper;
152 : :
153 : 0 : return( *pLibraryInstance );
154 : : }
155 : :
156 : : // -----------------------------------------------------------------------------
157 : :
158 : 0 : LibraryWrapper::LibraryWrapper() :
159 : : mpGObjectLib( NULL ),
160 : 0 : mpRSVGLib( NULL )
161 : : {
162 [ # # ]: 0 : const ::rtl::OUString aGObjectLibName( RTL_CONSTASCII_USTRINGPARAM( VCL_RSVG_GOBJECT_LIBNAME ) );
163 [ # # ]: 0 : const ::rtl::OUString aRSVGLibName( RTL_CONSTASCII_USTRINGPARAM( VCL_RSVG_LIBRSVG_LIBNAME ) );
164 : 0 : bool bCont = true;
165 : :
166 : : // GObject
167 [ # # ][ # # ]: 0 : if( bCont && ( NULL != ( mpGObjectLib = osl_loadModule( aGObjectLibName.pData, SAL_LOADMODULE_DEFAULT ) ) ||
[ # # ][ # # ]
[ # # ]
168 : : NULL != ( mpGObjectLib = osl_loadModuleRelative( (oslGenericFunction)LibraryWrapper::get,
169 [ # # ]: 0 : aGObjectLibName.pData, SAL_LOADMODULE_DEFAULT ) )
170 : :
171 : : ) )
172 : : {
173 [ # # ]: 0 : mp_g_object_unref = ( gpointer (*)( gpointer ) ) osl_getAsciiFunctionSymbol( mpGObjectLib, "g_object_unref" );
174 : :
175 [ # # ]: 0 : if( !( mp_g_object_unref ) )
176 : : {
177 : : OSL_TRACE( "not all needed symbols were found in g-object library" );
178 : 0 : bCont = false;
179 : : }
180 : : }
181 : :
182 : : // LibRSVG
183 [ # # ][ # # ]: 0 : if( bCont && ( NULL != ( mpRSVGLib = osl_loadModule( aRSVGLibName.pData, SAL_LOADMODULE_DEFAULT ) ) ||
[ # # ][ # # ]
[ # # ]
184 : : NULL != ( mpRSVGLib = osl_loadModuleRelative( (oslGenericFunction)LibraryWrapper::get,
185 [ # # ]: 0 : aRSVGLibName.pData, SAL_LOADMODULE_DEFAULT ) )
186 : : ) )
187 : : {
188 [ # # ]: 0 : mp_rsvg_init = ( void (*)( void ) ) osl_getAsciiFunctionSymbol( mpRSVGLib, "rsvg_init" );
189 [ # # ]: 0 : mp_rsvg_handle_new_from_data = ( RsvgHandle* (*)( const guint8*, gsize, GError** ) ) osl_getAsciiFunctionSymbol( mpRSVGLib, "rsvg_handle_new_from_data" );
190 [ # # ]: 0 : mp_rsvg_handle_set_dpi_x_y = ( void (*)( RsvgHandle*, double, double ) ) osl_getAsciiFunctionSymbol( mpRSVGLib, "rsvg_handle_set_dpi_x_y" );
191 [ # # ]: 0 : mp_rsvg_handle_get_dimensions = ( void (*)( RsvgHandle*, RsvgDimensionData* ) ) osl_getAsciiFunctionSymbol( mpRSVGLib, "rsvg_handle_get_dimensions" );
192 [ # # ]: 0 : mp_rsvg_handle_render_cairo = ( gboolean (*)( RsvgHandle*, cairo_t* ) ) osl_getAsciiFunctionSymbol( mpRSVGLib, "rsvg_handle_render_cairo" );
193 : :
194 [ # # ]: 0 : if( !( mp_rsvg_init &&
195 : : mp_rsvg_handle_new_from_data &&
196 : : mp_rsvg_handle_set_dpi_x_y &&
197 : : mp_rsvg_handle_get_dimensions &&
198 [ # # ][ # # ]: 0 : mp_rsvg_handle_render_cairo ) )
[ # # ][ # # ]
199 : : {
200 : : OSL_TRACE( "not all needed symbols were found in librsvg library" );
201 : 0 : bCont = false;
202 : : }
203 : : }
204 : :
205 : : OSL_ENSURE( mpGObjectLib, "g-object library could not be loaded" );
206 : : OSL_ENSURE( mpRSVGLib, "librsvg library could not be loaded" );
207 : :
208 [ # # ][ # # ]: 0 : bCont = bCont && mpGObjectLib != NULL && mpRSVGLib != NULL;
[ # # ]
209 : :
210 : : // unload all libraries in case of failure
211 [ # # ]: 0 : if( !bCont )
212 : : {
213 [ # # ]: 0 : if( mpRSVGLib )
214 : : {
215 [ # # ]: 0 : osl_unloadModule( mpRSVGLib );
216 : 0 : mpRSVGLib = NULL;
217 : : }
218 : :
219 [ # # ]: 0 : if( mpGObjectLib )
220 : : {
221 [ # # ]: 0 : osl_unloadModule( mpGObjectLib );
222 : 0 : mpGObjectLib = NULL;
223 : : }
224 : : }
225 : : else
226 [ # # ]: 0 : rsvg_init();
227 : 0 : }
228 : :
229 : : // ---------------------------
230 : : // - ::vcl::rsvg::Rasterizer -
231 : : // ---------------------------
232 : :
233 : : class Rasterizer : public ::cppu::WeakAggImplHelper2< graphic::XGraphicRasterizer, lang::XServiceInfo >
234 : : {
235 : : public:
236 : : Rasterizer();
237 : : virtual ~Rasterizer();
238 : :
239 : : // XGraphicRasterizer
240 : : virtual ::sal_Bool SAL_CALL initializeData( const uno::Reference< io::XInputStream >& DataStream,
241 : : ::sal_uInt32 DPI_X, ::sal_uInt32 DPI_Y,
242 : : awt::Size& DefaultSizePixel )
243 : : throw ( uno::RuntimeException );
244 : :
245 : : virtual uno::Reference< graphic::XGraphic > SAL_CALL rasterize( ::sal_uInt32 Width,
246 : : ::sal_uInt32 Height,
247 : : double RotateAngle,
248 : : double ShearAngle_X,
249 : : double ShearAngle_Y,
250 : : const uno::Sequence< beans::PropertyValue >& RasterizeProperties )
251 : : throw (uno::RuntimeException);
252 : :
253 : : // XServiceInfo
254 : : virtual ::rtl::OUString SAL_CALL getImplementationName()
255 : : throw( uno::RuntimeException);
256 : :
257 : : virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& )
258 : : throw( uno::RuntimeException );
259 : :
260 : : virtual uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
261 : : throw( uno::RuntimeException );
262 : :
263 : : protected:
264 : :
265 : : void implFreeRsvgHandle();
266 : :
267 : : uno::Reference< graphic::XGraphic > implGetXGraphicFromSurface( cairo_surface_t* pSurface ) const;
268 : :
269 : : private:
270 : :
271 : : Rasterizer( const Rasterizer& );
272 : : Rasterizer& operator=( const Rasterizer& );
273 : :
274 : : private:
275 : :
276 : : RsvgHandle* mpRsvgHandle;
277 : : sal_Int32 mnDefaultWidth;
278 : : sal_Int32 mnDefaultHeight;
279 : : bool mbLibInit;
280 : : };
281 : :
282 : : // -----------------------------------------------------------------------------
283 : :
284 : 0 : Rasterizer::Rasterizer() :
285 : : mpRsvgHandle( NULL ),
286 : : mnDefaultWidth( 0 ),
287 : : mnDefaultHeight( 0 ),
288 : 0 : mbLibInit( true )
289 : : {
290 : : try
291 : : {
292 [ # # ]: 0 : LibraryWrapper& rLib = LibraryWrapper::get();
293 : 0 : mbLibInit = rLib.isValid();
294 : : }
295 [ # # ]: 0 : catch( ... )
296 : : {
297 : 0 : mbLibInit = false;
298 : : }
299 : 0 : }
300 : :
301 : : // -----------------------------------------------------------------------------
302 : :
303 : 0 : Rasterizer::~Rasterizer()
304 : : {
305 [ # # ]: 0 : implFreeRsvgHandle();
306 [ # # ]: 0 : }
307 : :
308 : : // -----------------------------------------------------------------------------
309 : :
310 : 0 : void Rasterizer::implFreeRsvgHandle()
311 : : {
312 [ # # ]: 0 : if( mpRsvgHandle )
313 : : {
314 : 0 : LibraryWrapper::get().g_object_unref( static_cast< gpointer >( mpRsvgHandle ) );
315 : 0 : mpRsvgHandle = NULL;
316 : : }
317 : 0 : }
318 : :
319 : : // -----------------------------------------------------------------------------
320 : :
321 : 0 : uno::Reference< graphic::XGraphic > Rasterizer::implGetXGraphicFromSurface( cairo_surface_t* pSurface ) const
322 : : {
323 : 0 : unsigned char* pData = cairo_image_surface_get_data( pSurface );
324 : 0 : const sal_Int32 nWidth = cairo_image_surface_get_width( pSurface );
325 : 0 : const sal_Int32 nHeight = cairo_image_surface_get_height( pSurface );
326 : 0 : const sal_Int32 nStride = cairo_image_surface_get_stride( pSurface );
327 : :
328 : 0 : uno::Reference< graphic::XGraphic > xRet;
329 : :
330 [ # # ][ # # ]: 0 : if( pData && nWidth && nHeight && nStride )
[ # # ][ # # ]
331 : : {
332 : 0 : Size aSize( nWidth, nHeight );
333 [ # # ]: 0 : Bitmap aBmp( aSize, 24 );
334 [ # # ]: 0 : AlphaMask aAlphaMask( aSize );
335 [ # # ]: 0 : BitmapWriteAccess* pBmpAcc = aBmp.AcquireWriteAccess();
336 [ # # ]: 0 : BitmapWriteAccess* pAlpAcc = aAlphaMask.AcquireWriteAccess();
337 : :
338 [ # # ][ # # ]: 0 : if( pBmpAcc && pAlpAcc )
339 : : {
340 : 0 : BitmapColor aPixel, aWhitePixel( 255, 255, 255 ), aAlpha( 0 ), aFullAlpha( 255 );
341 : 0 : sal_uInt32* pRow = reinterpret_cast< sal_uInt32* >( pData );
342 : :
343 [ # # ]: 0 : for( sal_Int32 nY = 0; nY < nHeight; ++nY, pRow = reinterpret_cast< sal_uInt32* >( pData += nStride ) )
344 : : {
345 [ # # ]: 0 : for( sal_Int32 nX = 0; nX < nWidth; ++nX )
346 : : {
347 : 0 : const register sal_uInt32 nPixel = *pRow++;
348 : 0 : const register sal_uInt32 nAlpha = nPixel >> 24;
349 : :
350 [ # # ]: 0 : if( !nAlpha )
351 : : {
352 [ # # ]: 0 : pBmpAcc->SetPixel( nY, nX, aWhitePixel );
353 [ # # ]: 0 : pAlpAcc->SetPixel( nY, nX, aFullAlpha );
354 : : }
355 : : else
356 : : {
357 : 0 : aPixel.SetRed( static_cast< sal_uInt8 >( ( ( ( nPixel & 0x00ff0000 ) >> 16 ) * 255 ) / nAlpha ) );
358 : 0 : aPixel.SetGreen( static_cast< sal_uInt8 >( ( ( ( nPixel & 0x0000ff00 ) >> 8 ) * 255 ) / nAlpha ) );
359 : 0 : aPixel.SetBlue( static_cast< sal_uInt8 >( ( ( nPixel & 0x000000ff ) * 255 ) / nAlpha ) );
360 [ # # ]: 0 : pBmpAcc->SetPixel( nY, nX, aPixel );
361 : :
362 : 0 : aAlpha.SetIndex( static_cast< sal_uInt8 >( 255 - nAlpha ) );
363 [ # # ]: 0 : pAlpAcc->SetPixel( nY, nX, aAlpha );
364 : : }
365 : : }
366 : : }
367 : :
368 [ # # ]: 0 : aBmp.ReleaseAccess( pBmpAcc );
369 [ # # ]: 0 : aAlphaMask.ReleaseAccess( pAlpAcc );
370 : :
371 [ # # ][ # # ]: 0 : const Graphic aGraphic( BitmapEx( aBmp, aAlphaMask ) );
[ # # ]
372 [ # # ][ # # ]: 0 : xRet.set( aGraphic.GetXGraphic(), uno::UNO_QUERY );
[ # # ]
373 : : }
374 : : else
375 : : {
376 [ # # ]: 0 : aBmp.ReleaseAccess( pBmpAcc );
377 [ # # ]: 0 : aAlphaMask.ReleaseAccess( pAlpAcc );
378 [ # # ][ # # ]: 0 : }
379 : : }
380 : :
381 : 0 : return( xRet );
382 : : }
383 : :
384 : : // -----------------------------------------------------------------------------
385 : :
386 : 0 : ::sal_Bool SAL_CALL Rasterizer::initializeData( const uno::Reference< io::XInputStream >& rDataStream,
387 : : ::sal_uInt32 nDPI_X, ::sal_uInt32 nDPI_Y,
388 : : awt::Size& rDefaultSizePixel )
389 : : throw ( uno::RuntimeException )
390 : : {
391 : 0 : LibraryWrapper& rLib = LibraryWrapper::get();
392 : :
393 : 0 : implFreeRsvgHandle();
394 : :
395 [ # # ][ # # ]: 0 : if( mbLibInit && rDataStream.is() )
[ # # ]
396 : : {
397 [ # # ]: 0 : ::std::vector< sal_Int8 > aDataBuffer;
398 [ # # ]: 0 : uno::Reference< io::XSeekable > xSeekable( rDataStream, uno::UNO_QUERY );
399 [ # # ][ # # ]: 0 : sal_Int32 nReadSize, nBlockSize = ( xSeekable.is() ? xSeekable->getLength() : 65536 );
[ # # ]
400 [ # # ]: 0 : uno::Sequence< sal_Int8 > aStmBuffer( nBlockSize );
401 : :
402 [ # # ]: 0 : do
403 : : {
404 [ # # ][ # # ]: 0 : nReadSize = rDataStream->readBytes( aStmBuffer, nBlockSize );
405 : :
406 [ # # ]: 0 : if( nReadSize > 0 )
407 : : {
408 [ # # ]: 0 : const sal_Int8* pArray = aStmBuffer.getArray();
409 [ # # ]: 0 : aDataBuffer.insert( aDataBuffer.end(), pArray, pArray + nReadSize );
410 : : }
411 : : }
412 : : while( nReadSize == nBlockSize );
413 : :
414 [ # # ]: 0 : if (aDataBuffer.size())
415 : : {
416 : : //See: fdo#50975 rsvg_handle_new_from_data calls
417 : : //rsvg_handle_fill_with_data which itself calls rsvg_handle_close
418 : : //on success. Older versions of librsvg (e.g. 2.16.1) don't
419 : : //protect against rsvg_handle_close getting called twice, so we
420 : : //shouldn't additionally call svg_handle_close here.
421 [ # # ]: 0 : mpRsvgHandle = rLib.rsvg_handle_new_from_data( reinterpret_cast< sal_uInt8* >( &aDataBuffer[ 0 ] ),
422 [ # # ]: 0 : aDataBuffer.size(), NULL );
423 [ # # ]: 0 : }
424 : : }
425 : :
426 : : // get default dimensions of image
427 : 0 : mnDefaultWidth = mnDefaultHeight = 0;
428 : :
429 [ # # ]: 0 : if( mpRsvgHandle )
430 : : {
431 : 0 : RsvgDimensionData aDefaultDimension = { 0, 0, 0.0, 0.0 };
432 : :
433 [ # # ][ # # ]: 0 : rLib.rsvg_handle_set_dpi_x_y( mpRsvgHandle, nDPI_X ? nDPI_X: 72, nDPI_Y ? nDPI_Y : 72 );
[ # # ]
434 [ # # ]: 0 : rLib.rsvg_handle_get_dimensions( mpRsvgHandle, &aDefaultDimension );
435 : :
436 : 0 : mnDefaultWidth = aDefaultDimension.width;
437 : 0 : mnDefaultHeight = aDefaultDimension.height;
438 : : }
439 : :
440 : 0 : rDefaultSizePixel.Width = mnDefaultWidth;
441 : 0 : rDefaultSizePixel.Height = mnDefaultHeight;
442 : :
443 : 0 : return( mpRsvgHandle != NULL );
444 : : }
445 : :
446 : : // -----------------------------------------------------------------------------
447 : :
448 : 0 : uno::Reference< graphic::XGraphic > SAL_CALL Rasterizer::rasterize( ::sal_uInt32 nWidth,
449 : : ::sal_uInt32 nHeight,
450 : : double /*fRotateAngle*/,
451 : : double /*fShearAngle_X*/,
452 : : double /*ShearAngle_Y*/,
453 : : const uno::Sequence< beans::PropertyValue >&
454 : : /*rRasterizeProperties*/ )
455 : : throw ( uno::RuntimeException )
456 : : {
457 : 0 : LibraryWrapper& rLib = LibraryWrapper::get();
458 : 0 : uno::Reference< graphic::XGraphic > xRet;
459 : :
460 [ # # ][ # # ]: 0 : if( mpRsvgHandle && rLib.isValid() && nWidth && nHeight && mnDefaultWidth && mnDefaultHeight )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
461 : : {
462 [ # # ]: 0 : cairo_surface_t* pSurface = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, nWidth, nHeight );
463 : :
464 [ # # ][ # # ]: 0 : if( pSurface && ( CAIRO_STATUS_SUCCESS == cairo_surface_status( pSurface ) ) )
[ # # ][ # # ]
465 : : {
466 [ # # ]: 0 : cairo_t* pCr = cairo_create( pSurface );
467 : :
468 [ # # ]: 0 : if( pCr )
469 : : {
470 : : cairo_matrix_t aMatrix;
471 : :
472 [ # # ]: 0 : cairo_matrix_init_identity( &aMatrix );
473 : : cairo_matrix_scale( &aMatrix,
474 : : static_cast< double >( nWidth ) / mnDefaultWidth,
475 [ # # ]: 0 : static_cast< double >( nHeight ) / mnDefaultHeight );
476 [ # # ]: 0 : cairo_transform( pCr, &aMatrix );
477 : :
478 [ # # ][ # # ]: 0 : if( rLib.rsvg_handle_render_cairo( mpRsvgHandle, pCr ) )
479 : : {
480 [ # # ][ # # ]: 0 : xRet = implGetXGraphicFromSurface( pSurface );
481 : : }
482 : :
483 [ # # ]: 0 : cairo_destroy( pCr );
484 : : }
485 : :
486 [ # # ]: 0 : cairo_surface_destroy( pSurface );
487 : : OSL_ENSURE( xRet.is(), "SVG *not* rendered successfully" );
488 : : }
489 : : }
490 : :
491 : 0 : return( xRet );
492 : : }
493 : :
494 : : // -----------------------------------------------------------------------------
495 : :
496 : 0 : ::rtl::OUString SAL_CALL Rasterizer::getImplementationName()
497 : : throw( uno::RuntimeException )
498 : : {
499 : 0 : return( Rasterizer_getImplementationName() );
500 : : }
501 : :
502 : : // -----------------------------------------------------------------------------
503 : :
504 : 0 : sal_Bool SAL_CALL Rasterizer::supportsService( const ::rtl::OUString& rServiceName )
505 : : throw( uno::RuntimeException )
506 : : {
507 [ # # ]: 0 : const uno::Sequence< ::rtl::OUString > aServices( Rasterizer_getSupportedServiceNames() );
508 : :
509 [ # # ]: 0 : for( sal_Int32 nService = 0; nService < aServices.getLength(); ++nService )
510 : : {
511 [ # # ]: 0 : if( rServiceName == aServices[ nService ] )
512 : 0 : return sal_True;
513 : : }
514 : :
515 [ # # ]: 0 : return sal_False;
516 : : }
517 : :
518 : : // -----------------------------------------------------------------------------
519 : :
520 : 0 : uno::Sequence< ::rtl::OUString > SAL_CALL Rasterizer::getSupportedServiceNames()
521 : : throw( uno::RuntimeException )
522 : : {
523 : 0 : return( Rasterizer_getSupportedServiceNames() );
524 : : }
525 : :
526 : : // ------------------------------
527 : : // - Uno instantiation function -
528 : : // ------------------------------
529 : :
530 : 0 : uno::Reference< uno::XInterface > SAL_CALL Rasterizer_createInstance( const uno::Reference< lang::XMultiServiceFactory >& )
531 : : {
532 [ # # ]: 0 : return static_cast< ::cppu::OWeakObject* >( new rsvg::Rasterizer );
533 : : }
534 : :
535 : : } // namespace rsvg
536 : : } // namespace vcl
537 : :
538 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|