summaryrefslogtreecommitdiff
path: root/vcl/source/components
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@suse.cz>2011-04-22 15:09:06 +0200
committerJan Holesovsky <kendy@suse.cz>2011-04-22 15:09:06 +0200
commit83380a7805f69b18f432895fc17c53cf0354bf4d (patch)
treeb38d271cb6a768b6c2f9d3bee37d0d88e0472cb4 /vcl/source/components
parentd5bbd70673a2d5c6f8937428b97111e9c13fd21f (diff)
parent9e84958536c737f8fdcff4d28664d0c13b9cdc8c (diff)
Merge commit 'ooo/DEV300_m106' into libreoffice-3-4
Conflicts: cppcanvas/source/mtfrenderer/transparencygroupaction.cxx l10ntools/scripts/localize.pl l10ntools/source/directory.cxx l10ntools/source/srciter.cxx padmin/Executable_spadmin.bin.mk padmin/Library_spa.mk svtools/inc/svtools/filter.hxx svtools/inc/svtools/grfmgr.hxx svtools/source/filter/filter.cxx svtools/source/filter/filter2.cxx svtools/source/filter/wmf/emfwr.cxx svtools/source/filter/wmf/enhwmf.cxx svtools/source/filter/wmf/winmtf.cxx svtools/source/filter/wmf/winmtf.hxx svtools/source/filter/wmf/winwmf.cxx svtools/source/filter/wmf/wmfwr.cxx svtools/source/graphic/grfmgr.cxx svtools/source/graphic/grfmgr2.cxx toolkit/source/controls/controlmodelcontainerbase.cxx toolkit/source/controls/unocontrol.cxx toolkit/source/helper/formpdfexport.cxx toolkit/source/helper/unowrapper.cxx vcl/Package_osx.mk vcl/aqua/source/app/salinst.cxx vcl/aqua/source/app/salsys.cxx vcl/aqua/source/dtrans/aqua_service.cxx vcl/aqua/source/dtrans/test_aquacb.cxx vcl/aqua/source/res/makefile.mk vcl/aqua/source/window/salframe.cxx vcl/aqua/source/window/salframeview.mm vcl/inc/aqua/salgdi.h vcl/inc/aqua/salinst.h vcl/inc/graphite_adaptors.hxx vcl/inc/graphite_cache.hxx vcl/inc/graphite_serverfont.hxx vcl/inc/impprn.hxx vcl/inc/svdata.hxx vcl/inc/unx/i18n_status.hxx vcl/inc/unx/saldata.hxx vcl/inc/unx/salfont.h vcl/inc/unx/salinst.h vcl/inc/unx/salprn.h vcl/inc/unx/salsys.h vcl/inc/unx/sm.hxx vcl/inc/vcl/gdimtf.hxx vcl/inc/vcl/graph.hxx vcl/inc/vcl/outdev.hxx vcl/inc/vcl/polyscan.hxx vcl/inc/vcl/svcompat.hxx vcl/inc/vcl/svgread.hxx vcl/inc/vcl/unobrok.hxx vcl/inc/win/salgdi.h vcl/inc/win/wincomp.hxx vcl/prj/d.lst vcl/source/app/dbggui.cxx vcl/source/app/idlemgr.cxx vcl/source/app/makefile.mk vcl/source/app/settings.cxx vcl/source/app/sound.cxx vcl/source/app/stdtext.cxx vcl/source/app/svapp.cxx vcl/source/app/svdata.cxx vcl/source/app/svmain.cxx vcl/source/app/timer.cxx vcl/source/app/unohelp.cxx vcl/source/components/dtranscomp.cxx vcl/source/control/button.cxx vcl/source/control/combobox.cxx vcl/source/control/ctrl.cxx vcl/source/control/edit.cxx vcl/source/control/field2.cxx vcl/source/control/ilstbox.cxx vcl/source/gdi/bitmap.cxx vcl/source/gdi/bitmapex.cxx vcl/source/gdi/cvtgrf.cxx vcl/source/gdi/font.cxx vcl/source/gdi/image.cxx vcl/source/gdi/imagerepository.cxx vcl/source/gdi/impbmp.cxx vcl/source/gdi/impgraph.cxx vcl/source/gdi/impimagetree.cxx vcl/source/gdi/jobset.cxx vcl/source/gdi/makefile.mk vcl/source/gdi/metaact.cxx vcl/source/gdi/outdev.cxx vcl/source/gdi/outdev2.cxx vcl/source/gdi/outdev5.cxx vcl/source/gdi/outdev6.cxx vcl/source/gdi/outmap.cxx vcl/source/gdi/polyscan.cxx vcl/source/gdi/print.cxx vcl/source/gdi/print2.cxx vcl/source/gdi/region.cxx vcl/source/gdi/salgdilayout.cxx vcl/source/gdi/sallayout.cxx vcl/source/gdi/svcompat.cxx vcl/source/gdi/virdev.cxx vcl/source/glyphs/gcach_ftyp.cxx vcl/source/glyphs/gcach_vdev.cxx vcl/source/glyphs/gcach_vdev.hxx vcl/source/glyphs/graphite_adaptors.cxx vcl/source/glyphs/graphite_cache.cxx vcl/source/glyphs/graphite_layout.cxx vcl/source/glyphs/graphite_serverfont.cxx vcl/source/glyphs/graphite_textsrc.hxx vcl/source/glyphs/makefile.mk vcl/source/src/makefile.mk vcl/source/window/accel.cxx vcl/source/window/brdwin.cxx vcl/source/window/btndlg.cxx vcl/source/window/dialog.cxx vcl/source/window/dndevdis.cxx vcl/source/window/dockmgr.cxx vcl/source/window/dockwin.cxx vcl/source/window/floatwin.cxx vcl/source/window/introwin.cxx vcl/source/window/keycod.cxx vcl/source/window/menu.cxx vcl/source/window/msgbox.cxx vcl/source/window/scrwnd.cxx vcl/source/window/split.cxx vcl/source/window/splitwin.cxx vcl/source/window/status.cxx vcl/source/window/syswin.cxx vcl/source/window/tabpage.cxx vcl/source/window/toolbox.cxx vcl/source/window/toolbox2.cxx vcl/source/window/window.cxx vcl/source/window/window2.cxx vcl/source/window/winproc.cxx vcl/source/window/wrkwin.cxx vcl/unx/generic/app/i18n_cb.cxx vcl/unx/generic/app/i18n_ic.cxx vcl/unx/generic/app/saldata.cxx vcl/unx/generic/app/saldisp.cxx vcl/unx/generic/app/salinst.cxx vcl/unx/generic/app/wmadaptor.cxx vcl/unx/generic/fontmanager/afm_hash.cpp vcl/unx/generic/gdi/salbmp.cxx vcl/unx/generic/gdi/salgdi3.cxx vcl/unx/generic/gdi/xrender_peer.cxx vcl/unx/generic/window/salframe.cxx vcl/unx/generic/window/salobj.cxx vcl/unx/gtk/a11y/makefile.mk vcl/unx/gtk/app/gtksys.cxx vcl/unx/gtk/app/makefile.mk vcl/unx/gtk/window/gtkframe.cxx vcl/unx/gtk/window/gtkobject.cxx vcl/unx/headless/svpinst.cxx vcl/unx/headless/svpinst.hxx vcl/unx/headless/svpprn.hxx vcl/unx/kde/kdedata.cxx vcl/unx/kde/salnativewidgets-kde.cxx vcl/unx/kde4/KDESalDisplay.hxx vcl/unx/kde4/KDEXLib.cxx vcl/unx/kde4/KDEXLib.hxx vcl/unx/kde4/VCLKDEApplication.cxx vcl/unx/kde4/makefile.mk vcl/unx/source/app/makefile.mk vcl/unx/source/fontmanager/makefile.mk vcl/unx/source/gdi/makefile.mk vcl/unx/source/inc/salcursors.h vcl/util/linksvp/makefile.mk vcl/win/source/app/saldata.cxx vcl/win/source/app/salinst.cxx vcl/win/source/app/salshl.cxx vcl/win/source/gdi/makefile.mk vcl/win/source/gdi/salbmp.cxx vcl/win/source/gdi/salgdi.cxx vcl/win/source/gdi/salgdi2.cxx vcl/win/source/gdi/salgdi3.cxx vcl/win/source/gdi/salgdi_gdiplus.cxx vcl/win/source/gdi/salprn.cxx vcl/win/source/gdi/salvd.cxx vcl/win/source/gdi/winlayout.cxx vcl/win/source/window/salframe.cxx vcl/win/source/window/salmenu.cxx vcl/win/source/window/salobj.cxx
Diffstat (limited to 'vcl/source/components')
-rw-r--r--vcl/source/components/dtranscomp.cxx13
-rw-r--r--vcl/source/components/factory.cxx15
-rw-r--r--vcl/source/components/fontident.cxx14
-rw-r--r--vcl/source/components/makefile.mk21
-rw-r--r--vcl/source/components/rasterizer_rsvg.cxx640
5 files changed, 679 insertions, 24 deletions
diff --git a/vcl/source/components/dtranscomp.cxx b/vcl/source/components/dtranscomp.cxx
index cd1fbec0502b..b089db6e387e 100644
--- a/vcl/source/components/dtranscomp.cxx
+++ b/vcl/source/components/dtranscomp.cxx
@@ -29,6 +29,13 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_vcl.hxx"
+#include "osl/mutex.hxx"
+
+#include "vcl/svapp.hxx"
+
+#include "svdata.hxx"
+#include "salinst.hxx"
+
#include "com/sun/star/lang/XServiceInfo.hpp"
#include "com/sun/star/lang/XSingleServiceFactory.hpp"
#include "com/sun/star/lang/XInitialization.hpp"
@@ -42,12 +49,6 @@
#include "com/sun/star/datatransfer/dnd/XDropTarget.hpp"
#include "com/sun/star/datatransfer/dnd/DNDConstants.hpp"
-#include "vcl/svapp.hxx"
-#include "vcl/svdata.hxx"
-#include "vcl/salinst.hxx"
-#include "osl/mutex.hxx"
-#include "osl/mutex.hxx"
-
#include "cppuhelper/compbase1.hxx"
#include "cppuhelper/compbase2.hxx"
#include "cppuhelper/compbase3.hxx"
diff --git a/vcl/source/components/factory.cxx b/vcl/source/components/factory.cxx
index 9325c047b5d7..04b0e122cbce 100644
--- a/vcl/source/components/factory.cxx
+++ b/vcl/source/components/factory.cxx
@@ -42,9 +42,7 @@ using ::rtl::OUStringBuffer;
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
-
// service implementation
-
extern Sequence< OUString > SAL_CALL vcl_session_getSupportedServiceNames();
extern OUString SAL_CALL vcl_session_getImplementationName();
extern Reference< XInterface > SAL_CALL vcl_session_createInstance( const Reference< XMultiServiceFactory > & );
@@ -74,6 +72,13 @@ extern Reference< XInterface > SAL_CALL DragSource_createInstance( const Referen
extern Sequence< OUString > SAL_CALL DropTarget_getSupportedServiceNames();
extern OUString SAL_CALL DropTarget_getImplementationName();
extern Reference< XInterface > SAL_CALL DropTarget_createInstance( const Reference< XMultiServiceFactory > & );
+
+namespace rsvg
+{
+ extern Sequence< OUString > SAL_CALL Rasterizer_getSupportedServiceNames();
+ extern OUString SAL_CALL Rasterizer_getImplementationName();
+ extern Reference< XInterface > SAL_CALL Rasterizer_createInstance( const Reference< XMultiServiceFactory > & );
+}
}
extern "C" {
@@ -139,6 +144,12 @@ extern "C" {
xMgr, vcl::DropTarget_getImplementationName(), vcl::DropTarget_createInstance,
vcl::DropTarget_getSupportedServiceNames() );
}
+ else if( vcl::rsvg::Rasterizer_getImplementationName().equalsAscii( pImplementationName ) )
+ {
+ xFactory = ::cppu::createSingleFactory(
+ xMgr, vcl::rsvg::Rasterizer_getImplementationName(), vcl::rsvg::Rasterizer_createInstance,
+ vcl::rsvg::Rasterizer_getSupportedServiceNames() );
+ }
if( xFactory.is() )
{
xFactory->acquire();
diff --git a/vcl/source/components/fontident.cxx b/vcl/source/components/fontident.cxx
index e411dcf49aba..6afadbbe267e 100644
--- a/vcl/source/components/fontident.cxx
+++ b/vcl/source/components/fontident.cxx
@@ -29,6 +29,13 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_vcl.hxx"
+#include <tools/debug.hxx>
+
+#include "vcl/svapp.hxx"
+#include "vcl/font.hxx"
+
+#include "svdata.hxx"
+
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/beans/XMaterialHolder.hpp>
#include <com/sun/star/awt/FontDescriptor.hpp>
@@ -39,15 +46,8 @@
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/lang/DisposedException.hpp>
-#include "vcl/svapp.hxx"
-#include "vcl/svdata.hxx"
-#include "vcl/font.hxx"
-
#include <cppuhelper/implbase3.hxx>
-#include <tools/debug.hxx>
-
-
using ::rtl::OUString;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
diff --git a/vcl/source/components/makefile.mk b/vcl/source/components/makefile.mk
index 982687104c01..41f21bfa3749 100644
--- a/vcl/source/components/makefile.mk
+++ b/vcl/source/components/makefile.mk
@@ -33,20 +33,23 @@ ENABLE_EXCEPTIONS=TRUE
# --- Settings -----------------------------------------------------
-.INCLUDE : $(PRJ)$/util$/makefile.pmk
-.INCLUDE : settings.mk
+.INCLUDE : $(PRJ)$/util$/makefile.pmk
+.INCLUDE : settings.mk
.INCLUDE : $(PRJ)$/util$/makefile2.pmk
# --- Files --------------------------------------------------------
-SLOFILES= $(SLO)$/display.obj \
- $(SLO)$/dtranscomp.obj \
- $(SLO)$/fontident.obj \
- $(SLO)$/stringmirror.obj \
+SLOFILES= $(SLO)$/display.obj \
+ $(SLO)$/dtranscomp.obj \
+ $(SLO)$/fontident.obj \
+ $(SLO)$/stringmirror.obj \
+ $(SLO)$/rasterizer_rsvg.obj \
$(SLO)$/factory.obj
-# --- Targets ------------------------------------------------------
+EXCEPTIONSFILES= $(SLO)$/rasterizer_rsvg.obj
+
-.INCLUDE : target.mk
-.INCLUDE : $(PRJ)$/util$/target.pmk
+# --- Targets ------------------------------------------------------
+.INCLUDE : target.mk
+.INCLUDE : $(PRJ)$/util$/target.pmk
diff --git a/vcl/source/components/rasterizer_rsvg.cxx b/vcl/source/components/rasterizer_rsvg.cxx
new file mode 100644
index 000000000000..5547b179d227
--- /dev/null
+++ b/vcl/source/components/rasterizer_rsvg.cxx
@@ -0,0 +1,640 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_vcl.hxx"
+
+#include <vcl/graph.hxx>
+#include <vcl/bmpacc.hxx>
+#include <vcl/alpha.hxx>
+#include <com/sun/star/graphic/XGraphicRasterizer.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/io/XSeekable.hpp>
+#include <cppuhelper/implbase2.hxx>
+#include <osl/module.h>
+
+#include <vector>
+
+#if defined MACOSX
+ #define VCL_RSVG_GOBJECT_LIBNAME "libgobject-2.0.0.dylib"
+ #define VCL_RSVG_CAIRO_LIBNAME "libcairo.2.dylib"
+ #define VCL_RSVG_LIBRSVG_LIBNAME "librsvg-2.2.dylib"
+#elif defined UNX
+ #define VCL_RSVG_GOBJECT_LIBNAME "libgobject-2.0.so"
+ #define VCL_RSVG_CAIRO_LIBNAME "libcairo.so"
+ #define VCL_RSVG_LIBRSVG_LIBNAME "librsvg-2.so"
+#elif defined WNT
+ #define VCL_RSVG_GOBJECT_LIBNAME "libgobject-2.0-0.dll"
+ #define VCL_RSVG_CAIRO_LIBNAME "cairo.dll"
+ #define VCL_RSVG_LIBRSVG_LIBNAME "librsvg-2-2.dll"
+#else
+ #define VCL_RSVG_GOBJECT_LIBNAME "nogobjectlib"
+ #define VCL_RSVG_CAIRO_LIBNAME "nocairolib"
+ #define VCL_RSVG_LIBRSVG_LIBNAME "nolibrsvglib"
+#endif
+
+#define VCL_RSVG_DEFAULT_DPI 72
+
+using namespace ::com::sun::star;
+
+// -----------------------------------------------------
+// - external stuff for dynamic library function calls -
+// -----------------------------------------------------
+
+typedef int gboolean;
+typedef unsigned char guint8;
+typedef sal_Size gsize;
+typedef void* gpointer;
+
+struct GError;
+
+enum cairo_format_t { CAIRO_FORMAT_ARGB32 = 0 };
+enum cairo_status_t { CAIRO_STATUS_SUCCESS = 0 };
+
+struct cairo_surface_t;
+struct cairo_t;
+struct cairo_matrix_t
+{
+ double xx; double yx;
+ double xy; double yy;
+ double x0; double y0;
+};
+
+struct RsvgHandle;
+struct RsvgDimensionData
+{
+ int width;
+ int height;
+ double em;
+ double ex;
+};
+
+namespace vcl
+{
+namespace rsvg
+{
+// -----------------
+// - Uno functions -
+// ----------------
+
+uno::Sequence< ::rtl::OUString > Rasterizer_getSupportedServiceNames()
+{
+ static ::rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.graphic.GraphicRasterizer_RSVG" ) );
+ static uno::Sequence< ::rtl::OUString > aServiceNames( &aServiceName, 1 );
+
+ return( aServiceNames );
+}
+
+// -----------------------------------------------------------------------------
+
+::rtl::OUString Rasterizer_getImplementationName()
+{
+ return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "vcl::rsvg::Rasterizer" ) );
+}
+
+// ------------------
+// - LibraryWrapper -
+// ------------------
+
+class LibraryWrapper
+{
+public:
+
+ static LibraryWrapper& get();
+
+ bool isValid() const { return( ( mpGObjectLib != NULL ) && ( mpCairoLib != NULL ) && ( mpRSVGLib != NULL ) ); }
+
+ // G-Object
+ gpointer g_object_unref( gpointer pointer ) { return( (*mp_g_object_unref)( pointer ) ); };
+
+ // LibRSVG
+
+ // Cairo
+ cairo_surface_t* image_surface_create( cairo_format_t format, int width, int height ) { return( (*mp_image_surface_create)( format, width, height ) ); }
+ void surface_destroy( cairo_surface_t* surface ) { (*mp_surface_destroy)( surface ); }
+ cairo_status_t surface_status( cairo_surface_t* surface ) { return( (*mp_surface_status)( surface ) ); }
+ cairo_t* create( cairo_surface_t* surface ) { return( (*mp_create)( surface ) ); }
+ void destroy( cairo_t* cairo ) { (*mp_destroy )( cairo ); }
+ void matrix_init_identity( cairo_matrix_t* matrix ){ (*mp_matrix_init_identity)( matrix ); }
+ void matrix_translate( cairo_matrix_t* matrix, double nx, double ny ) { (*mp_matrix_translate)( matrix, nx, ny ); }
+ void matrix_scale( cairo_matrix_t* matrix, double sx, double sy ) {( *mp_matrix_scale )( matrix, sx, sy ); }
+ void matrix_rotate( cairo_matrix_t* matrix, double radians ) { ( *mp_matrix_rotate )( matrix, radians ); }
+ void transform( cairo_t* cairo, cairo_matrix_t *matrix ) { (*mp_transform)( cairo, matrix ); }
+ unsigned char* image_surface_get_data(cairo_surface_t* surface) { return( (*mp_image_surface_get_data)( surface ) ); }
+ int image_surface_get_width(cairo_surface_t* surface) { return( (*mp_image_surface_get_width)( surface ) ); }
+ int image_surface_get_height(cairo_surface_t* surface) { return( (*mp_image_surface_get_height)( surface ) ); }
+ int image_surface_get_stride(cairo_surface_t* surface) { return( (*mp_image_surface_get_stride)( surface ) ); }
+
+ // LibRSVG
+ void rsvg_init() { (*mp_rsvg_init)(); }
+ RsvgHandle* rsvg_handle_new_from_data( const guint8* data, gsize size, GError** error) { return( (*mp_rsvg_handle_new_from_data)( data, size, error ) ); }
+ gboolean rsvg_handle_close( RsvgHandle* handle, GError** error ) { return( (*mp_rsvg_handle_close)( handle, error ) ); }
+ void rsvg_handle_set_dpi_x_y( RsvgHandle* handle, double dpix, double dpiy ) { (*mp_rsvg_handle_set_dpi_x_y)( handle, dpix, dpiy ); }
+ void rsvg_handle_get_dimensions( RsvgHandle* handle, RsvgDimensionData* dimensions ) { (*mp_rsvg_handle_get_dimensions)( handle, dimensions ); }
+ gboolean rsvg_handle_render_cairo( RsvgHandle* handle, cairo_t* cairo ) { return( (*mp_rsvg_handle_render_cairo)( handle, cairo ) ); }
+
+private:
+
+ LibraryWrapper();
+
+private:
+
+ oslModule mpGObjectLib;
+ oslModule mpCairoLib;
+ oslModule mpRSVGLib;
+
+ // GObject
+ gpointer (*mp_g_object_unref)( gpointer );
+
+ // Cairo
+ cairo_surface_t* (*mp_image_surface_create)(cairo_format_t,int,int);
+ void (*mp_surface_destroy )(cairo_surface_t*);
+ cairo_status_t (*mp_surface_status)(cairo_surface_t*);
+ cairo_t* (*mp_create)(cairo_surface_t*);
+ void (*mp_destroy)(cairo_t*);
+ void (*mp_matrix_init_identity)(cairo_matrix_t*);
+ void (*mp_matrix_translate)( cairo_matrix_t*, double, double);
+ void (*mp_matrix_scale )( cairo_matrix_t*, double, double);
+ void (*mp_matrix_rotate)( cairo_matrix_t*, double);
+ void (*mp_transform)( cairo_t*, cairo_matrix_t*);
+ unsigned char* (*mp_image_surface_get_data)( cairo_surface_t* );
+ int (*mp_image_surface_get_width)(cairo_surface_t* surface);
+ int (*mp_image_surface_get_height)(cairo_surface_t* surface);
+ int (*mp_image_surface_get_stride)(cairo_surface_t* surface);
+
+ // LibRSVG
+ void (*mp_rsvg_init)( void );
+ RsvgHandle* (*mp_rsvg_handle_new_from_data)( const guint8*, gsize, GError** );
+ gboolean (*mp_rsvg_handle_close)( RsvgHandle*, GError** );
+ void (*mp_rsvg_handle_set_dpi_x_y)( RsvgHandle*, double, double );
+ void (*mp_rsvg_handle_get_dimensions)( RsvgHandle*, RsvgDimensionData* );
+ gboolean (*mp_rsvg_handle_render_cairo)( RsvgHandle*, cairo_t* );
+};
+
+// -----------------------------------------------------------------------------
+
+LibraryWrapper& LibraryWrapper::get()
+{
+ static LibraryWrapper* pLibraryInstance = NULL;
+
+ if( !pLibraryInstance )
+ pLibraryInstance = new LibraryWrapper;
+
+ return( *pLibraryInstance );
+}
+
+// -----------------------------------------------------------------------------
+
+LibraryWrapper::LibraryWrapper() :
+ mpGObjectLib( NULL ),
+ mpCairoLib( NULL ),
+ mpRSVGLib( NULL )
+{
+ const ::rtl::OUString aGObjectLibName( RTL_CONSTASCII_USTRINGPARAM( VCL_RSVG_GOBJECT_LIBNAME ) );
+ const ::rtl::OUString aCairoLibName( RTL_CONSTASCII_USTRINGPARAM( VCL_RSVG_CAIRO_LIBNAME ) );
+ const ::rtl::OUString aRSVGLibName( RTL_CONSTASCII_USTRINGPARAM( VCL_RSVG_LIBRSVG_LIBNAME ) );
+ bool bCont = true;
+
+ // GObject
+ if( bCont && ( NULL != ( mpGObjectLib = osl_loadModule( aGObjectLibName.pData, SAL_LOADMODULE_DEFAULT ) ) ||
+ NULL != ( mpGObjectLib = osl_loadModuleRelative( (oslGenericFunction)LibraryWrapper::get,
+ aGObjectLibName.pData, SAL_LOADMODULE_DEFAULT ) )
+
+ ) )
+ {
+ mp_g_object_unref = ( gpointer (*)( gpointer ) ) osl_getAsciiFunctionSymbol( mpGObjectLib, "g_object_unref" );
+
+ if( !( mp_g_object_unref ) )
+ {
+ OSL_TRACE( "not all needed symbols were found in g-object library" );
+ bCont = false;
+ }
+ }
+
+ // Cairo
+ if( bCont && ( NULL != ( mpCairoLib = osl_loadModule( aCairoLibName.pData, SAL_LOADMODULE_DEFAULT ) ) ||
+ NULL != ( mpCairoLib = osl_loadModuleRelative( (oslGenericFunction)LibraryWrapper::get,
+ aCairoLibName.pData, SAL_LOADMODULE_DEFAULT ) )
+ ) )
+ {
+ mp_image_surface_create = ( cairo_surface_t* (*)( cairo_format_t, int, int ) ) osl_getAsciiFunctionSymbol( mpCairoLib, "cairo_image_surface_create" );
+ mp_surface_destroy = ( void (*)( cairo_surface_t* ) ) osl_getAsciiFunctionSymbol( mpCairoLib, "cairo_surface_destroy" );
+ mp_surface_status = ( cairo_status_t (*)( cairo_surface_t* ) ) osl_getAsciiFunctionSymbol( mpCairoLib, "cairo_surface_status" );
+ mp_create = ( cairo_t* (*)( cairo_surface_t* ) ) osl_getAsciiFunctionSymbol( mpCairoLib, "cairo_create" );
+ mp_destroy = ( void (*)( cairo_t* ) ) osl_getAsciiFunctionSymbol( mpCairoLib, "cairo_destroy" );
+ mp_matrix_init_identity = ( void (*)( cairo_matrix_t* ) ) osl_getAsciiFunctionSymbol( mpCairoLib, "cairo_matrix_init_identity" );
+ mp_matrix_translate = ( void (*)( cairo_matrix_t*, double, double ) ) osl_getAsciiFunctionSymbol( mpCairoLib, "cairo_matrix_translate" );
+ mp_matrix_scale = ( void (*)( cairo_matrix_t*, double, double ) ) osl_getAsciiFunctionSymbol( mpCairoLib, "cairo_matrix_scale" );
+ mp_matrix_rotate = ( void (*)( cairo_matrix_t*, double ) ) osl_getAsciiFunctionSymbol( mpCairoLib, "cairo_matrix_rotate" );
+ mp_transform = ( void (*)( cairo_t*, cairo_matrix_t* ) ) osl_getAsciiFunctionSymbol( mpCairoLib, "cairo_transform" );
+ mp_image_surface_get_data = ( unsigned char* (*)( cairo_surface_t* ) ) osl_getAsciiFunctionSymbol( mpCairoLib, "cairo_image_surface_get_data" );
+ mp_image_surface_get_width = ( int (*)( cairo_surface_t* ) ) osl_getAsciiFunctionSymbol( mpCairoLib, "cairo_image_surface_get_width" );
+ mp_image_surface_get_height = ( int (*)( cairo_surface_t* ) ) osl_getAsciiFunctionSymbol( mpCairoLib, "cairo_image_surface_get_height" );
+ mp_image_surface_get_stride = ( int (*)( cairo_surface_t* ) ) osl_getAsciiFunctionSymbol( mpCairoLib, "cairo_image_surface_get_stride" );
+
+ if( !( mp_image_surface_create &&
+ mp_surface_destroy &&
+ mp_surface_status &&
+ mp_create &&
+ mp_destroy &&
+ mp_matrix_init_identity &&
+ mp_matrix_translate &&
+ mp_matrix_scale &&
+ mp_matrix_rotate &&
+ mp_transform &&
+ mp_image_surface_get_data &&
+ mp_image_surface_get_width &&
+ mp_image_surface_get_height &&
+ mp_image_surface_get_stride ) )
+ {
+ OSL_TRACE( "not all needed symbols were found in cairo library" );
+ bCont = false;
+ }
+ }
+
+ // LibRSVG
+ if( bCont && ( NULL != ( mpRSVGLib = osl_loadModule( aRSVGLibName.pData, SAL_LOADMODULE_DEFAULT ) ) ||
+ NULL != ( mpRSVGLib = osl_loadModuleRelative( (oslGenericFunction)LibraryWrapper::get,
+ aRSVGLibName.pData, SAL_LOADMODULE_DEFAULT ) )
+ ) )
+ {
+ mp_rsvg_init = ( void (*)( void ) ) osl_getAsciiFunctionSymbol( mpRSVGLib, "rsvg_init" );
+ mp_rsvg_handle_new_from_data = ( RsvgHandle* (*)( const guint8*, gsize, GError** ) ) osl_getAsciiFunctionSymbol( mpRSVGLib, "rsvg_handle_new_from_data" );
+ mp_rsvg_handle_close = ( gboolean (*)( RsvgHandle*, GError** ) ) osl_getAsciiFunctionSymbol( mpRSVGLib, "rsvg_handle_close" );
+ mp_rsvg_handle_set_dpi_x_y = ( void (*)( RsvgHandle*, double, double ) ) osl_getAsciiFunctionSymbol( mpRSVGLib, "rsvg_handle_set_dpi_x_y" );
+ mp_rsvg_handle_get_dimensions = ( void (*)( RsvgHandle*, RsvgDimensionData* ) ) osl_getAsciiFunctionSymbol( mpRSVGLib, "rsvg_handle_get_dimensions" );
+ mp_rsvg_handle_render_cairo = ( gboolean (*)( RsvgHandle*, cairo_t* ) ) osl_getAsciiFunctionSymbol( mpRSVGLib, "rsvg_handle_render_cairo" );
+
+ if( !( mp_rsvg_init &&
+ mp_rsvg_handle_new_from_data &&
+ mp_rsvg_handle_close &&
+ mp_rsvg_handle_set_dpi_x_y &&
+ mp_rsvg_handle_get_dimensions &&
+ mp_rsvg_handle_render_cairo ) )
+ {
+ OSL_TRACE( "not all needed symbols were found in librsvg library" );
+ bCont = false;
+ }
+ }
+
+ OSL_ENSURE( mpGObjectLib, "g-object library could not be loaded" );
+ OSL_ENSURE( mpCairoLib, "cairo library could not be loaded" );
+ OSL_ENSURE( mpRSVGLib, "librsvg library could not be loaded" );
+
+ bCont = bCont && mpGObjectLib != NULL && mpCairoLib != NULL && mpRSVGLib != NULL;
+
+ // unload all libraries in case of failure
+ if( !bCont )
+ {
+ if( mpRSVGLib )
+ {
+ osl_unloadModule( mpRSVGLib );
+ mpRSVGLib = NULL;
+ }
+
+ if( mpCairoLib )
+ {
+ osl_unloadModule( mpCairoLib );
+ mpCairoLib = NULL;
+ }
+
+ if( mpGObjectLib )
+ {
+ osl_unloadModule( mpGObjectLib );
+ mpGObjectLib = NULL;
+ }
+ }
+ else
+ rsvg_init();
+}
+
+// ---------------------------
+// - ::vcl::rsvg::Rasterizer -
+// ---------------------------
+
+class Rasterizer : public ::cppu::WeakAggImplHelper2< graphic::XGraphicRasterizer, lang::XServiceInfo >
+{
+public:
+ Rasterizer();
+ virtual ~Rasterizer();
+
+ // XGraphicRasterizer
+ virtual ::sal_Bool SAL_CALL initializeData( const uno::Reference< io::XInputStream >& DataStream,
+ ::sal_uInt32 DPI_X, ::sal_uInt32 DPI_Y,
+ awt::Size& DefaultSizePixel )
+ throw ( uno::RuntimeException );
+
+ virtual uno::Reference< graphic::XGraphic > SAL_CALL rasterize( ::sal_uInt32 Width,
+ ::sal_uInt32 Height,
+ double RotateAngle,
+ double ShearAngle_X,
+ double ShearAngle_Y,
+ const uno::Sequence< beans::PropertyValue >& RasterizeProperties )
+ throw (uno::RuntimeException);
+
+ // XServiceInfo
+ virtual ::rtl::OUString SAL_CALL getImplementationName()
+ throw( uno::RuntimeException);
+
+ virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& )
+ throw( uno::RuntimeException );
+
+ virtual uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
+ throw( uno::RuntimeException );
+
+protected:
+
+ void implFreeRsvgHandle();
+
+ uno::Reference< graphic::XGraphic > implGetXGraphicFromSurface( cairo_surface_t* pSurface ) const;
+
+private:
+
+ Rasterizer( const Rasterizer& );
+ Rasterizer& operator=( const Rasterizer& );
+
+private:
+
+ RsvgHandle* mpRsvgHandle;
+ sal_Int32 mnDefaultWidth;
+ sal_Int32 mnDefaultHeight;
+ bool mbLibInit;
+};
+
+// -----------------------------------------------------------------------------
+
+Rasterizer::Rasterizer() :
+ mpRsvgHandle( NULL ),
+ mnDefaultWidth( 0 ),
+ mnDefaultHeight( 0 ),
+ mbLibInit( true )
+{
+ try
+ {
+ LibraryWrapper& rLib = LibraryWrapper::get();
+ mbLibInit = rLib.isValid();
+ }
+ catch( ... )
+ {
+ mbLibInit = false;
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+Rasterizer::~Rasterizer()
+{
+ implFreeRsvgHandle();
+}
+
+// -----------------------------------------------------------------------------
+
+void Rasterizer::implFreeRsvgHandle()
+{
+ if( mpRsvgHandle )
+ {
+ LibraryWrapper::get().g_object_unref( static_cast< gpointer >( mpRsvgHandle ) );
+ mpRsvgHandle = NULL;
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+uno::Reference< graphic::XGraphic > Rasterizer::implGetXGraphicFromSurface( cairo_surface_t* pSurface ) const
+{
+ LibraryWrapper& rLib = LibraryWrapper::get();
+ unsigned char* pData = rLib.image_surface_get_data( pSurface );
+ const sal_Int32 nWidth = rLib.image_surface_get_width( pSurface );
+ const sal_Int32 nHeight =rLib.image_surface_get_height( pSurface );
+ const sal_Int32 nStride = rLib.image_surface_get_stride( pSurface );
+
+ uno::Reference< graphic::XGraphic > xRet;
+
+ if( pData && nWidth && nHeight && nStride )
+ {
+ Size aSize( nWidth, nHeight );
+ Bitmap aBmp( aSize, 24 );
+ AlphaMask aAlphaMask( aSize );
+ BitmapWriteAccess* pBmpAcc = aBmp.AcquireWriteAccess();
+ BitmapWriteAccess* pAlpAcc = aAlphaMask.AcquireWriteAccess();
+
+ if( pBmpAcc && pAlpAcc )
+ {
+ BitmapColor aPixel, aWhitePixel( 255, 255, 255 ), aAlpha( 0 ), aFullAlpha( 255 );
+ sal_uInt32* pRow = reinterpret_cast< sal_uInt32* >( pData );
+
+ for( sal_Int32 nY = 0; nY < nHeight; ++nY, pRow = reinterpret_cast< sal_uInt32* >( pData += nStride ) )
+ {
+ for( sal_Int32 nX = 0; nX < nWidth; ++nX )
+ {
+ const register sal_uInt32 nPixel = *pRow++;
+ const register sal_uInt32 nAlpha = nPixel >> 24;
+
+ if( !nAlpha )
+ {
+ pBmpAcc->SetPixel( nY, nX, aWhitePixel );
+ pAlpAcc->SetPixel( nY, nX, aFullAlpha );
+ }
+ else
+ {
+ aPixel.SetRed( static_cast< sal_uInt8 >( ( ( ( nPixel & 0x00ff0000 ) >> 16 ) * 255 ) / nAlpha ) );
+ aPixel.SetGreen( static_cast< sal_uInt8 >( ( ( ( nPixel & 0x0000ff00 ) >> 8 ) * 255 ) / nAlpha ) );
+ aPixel.SetBlue( static_cast< sal_uInt8 >( ( ( nPixel & 0x000000ff ) * 255 ) / nAlpha ) );
+ pBmpAcc->SetPixel( nY, nX, aPixel );
+
+ aAlpha.SetIndex( static_cast< sal_uInt8 >( 255 - nAlpha ) );
+ pAlpAcc->SetPixel( nY, nX, aAlpha );
+ }
+ }
+ }
+
+ aBmp.ReleaseAccess( pBmpAcc );
+ aAlphaMask.ReleaseAccess( pAlpAcc );
+
+ const Graphic aGraphic( BitmapEx( aBmp, aAlphaMask ) );
+ xRet.set( aGraphic.GetXGraphic(), uno::UNO_QUERY );
+ }
+ else
+ {
+ aBmp.ReleaseAccess( pBmpAcc );
+ aAlphaMask.ReleaseAccess( pAlpAcc );
+ }
+ }
+
+ return( xRet );
+}
+
+// -----------------------------------------------------------------------------
+
+::sal_Bool SAL_CALL Rasterizer::initializeData( const uno::Reference< io::XInputStream >& rDataStream,
+ ::sal_uInt32 nDPI_X, ::sal_uInt32 nDPI_Y,
+ awt::Size& rDefaultSizePixel )
+ throw ( uno::RuntimeException )
+{
+ LibraryWrapper& rLib = LibraryWrapper::get();
+
+ implFreeRsvgHandle();
+
+ if( mbLibInit && rDataStream.is() )
+ {
+ ::std::vector< sal_Int8 > aDataBuffer;
+ uno::Reference< io::XSeekable > xSeekable( rDataStream, uno::UNO_QUERY );
+ sal_Int32 nReadSize, nBlockSize = ( xSeekable.is() ? xSeekable->getLength() : 65536 );
+ uno::Sequence< sal_Int8 > aStmBuffer( nBlockSize );
+
+ do
+ {
+ nReadSize = rDataStream->readBytes( aStmBuffer, nBlockSize );
+
+ if( nReadSize > 0 )
+ {
+ const sal_Int8* pArray = aStmBuffer.getArray();
+ aDataBuffer.insert( aDataBuffer.end(), pArray, pArray + nReadSize );
+ }
+ }
+ while( nReadSize == nBlockSize );
+
+ if( aDataBuffer.size() &&
+ ( NULL != ( mpRsvgHandle = rLib.rsvg_handle_new_from_data( reinterpret_cast< sal_uInt8* >( &aDataBuffer[ 0 ] ),
+ aDataBuffer.size(), NULL ) ) ) &&
+ !rLib.rsvg_handle_close( mpRsvgHandle, NULL ) )
+ {
+ implFreeRsvgHandle();
+ }
+ }
+
+ // get default dimensions of image
+ mnDefaultWidth = mnDefaultHeight = 0;
+
+ if( mpRsvgHandle )
+ {
+ RsvgDimensionData aDefaultDimension = { 0, 0, 0.0, 0.0 };
+
+ rLib.rsvg_handle_set_dpi_x_y( mpRsvgHandle, nDPI_X ? nDPI_X: 72, nDPI_Y ? nDPI_Y : 72 );
+ rLib.rsvg_handle_get_dimensions( mpRsvgHandle, &aDefaultDimension );
+
+ mnDefaultWidth = aDefaultDimension.width;
+ mnDefaultHeight = aDefaultDimension.height;
+ }
+
+ rDefaultSizePixel.Width = mnDefaultWidth;
+ rDefaultSizePixel.Height = mnDefaultHeight;
+
+ return( mpRsvgHandle != NULL );
+}
+
+// -----------------------------------------------------------------------------
+
+uno::Reference< graphic::XGraphic > SAL_CALL Rasterizer::rasterize( ::sal_uInt32 nWidth,
+ ::sal_uInt32 nHeight,
+ double /*fRotateAngle*/,
+ double /*fShearAngle_X*/,
+ double /*ShearAngle_Y*/,
+ const uno::Sequence< beans::PropertyValue >&
+ /*rRasterizeProperties*/ )
+ throw ( uno::RuntimeException )
+{
+ LibraryWrapper& rLib = LibraryWrapper::get();
+ uno::Reference< graphic::XGraphic > xRet;
+
+ if( mpRsvgHandle && rLib.isValid() && nWidth && nHeight && mnDefaultWidth && mnDefaultHeight )
+ {
+ cairo_surface_t* pSurface = rLib.image_surface_create( CAIRO_FORMAT_ARGB32, nWidth, nHeight );
+
+ if( pSurface && ( CAIRO_STATUS_SUCCESS == rLib.surface_status( pSurface ) ) )
+ {
+ cairo_t* pCr = rLib.create( pSurface );
+
+ if( pCr )
+ {
+ cairo_matrix_t aMatrix;
+
+ rLib.matrix_init_identity( &aMatrix );
+ rLib.matrix_scale( &aMatrix,
+ static_cast< double >( nWidth ) / mnDefaultWidth,
+ static_cast< double >( nHeight ) / mnDefaultHeight );
+ rLib.transform( pCr, &aMatrix );
+
+ if( rLib.rsvg_handle_render_cairo( mpRsvgHandle, pCr ) )
+ {
+ xRet = implGetXGraphicFromSurface( pSurface );
+ }
+
+ rLib.destroy( pCr );
+ }
+
+ rLib.surface_destroy( pSurface );
+ OSL_ENSURE( xRet.is(), "SVG *not* rendered successfully" );
+ }
+ }
+
+ return( xRet );
+}
+
+// -----------------------------------------------------------------------------
+
+::rtl::OUString SAL_CALL Rasterizer::getImplementationName()
+ throw( uno::RuntimeException )
+{
+ return( Rasterizer_getImplementationName() );
+}
+
+// -----------------------------------------------------------------------------
+
+sal_Bool SAL_CALL Rasterizer::supportsService( const ::rtl::OUString& rServiceName )
+ throw( uno::RuntimeException )
+{
+ const uno::Sequence< ::rtl::OUString > aServices( Rasterizer_getSupportedServiceNames() );
+
+ for( sal_Int32 nService = 0; nService < aServices.getLength(); ++nService )
+ {
+ if( rServiceName == aServices[ nService ] )
+ return sal_True;
+ }
+
+ return sal_False;
+}
+
+// -----------------------------------------------------------------------------
+
+uno::Sequence< ::rtl::OUString > SAL_CALL Rasterizer::getSupportedServiceNames()
+ throw( uno::RuntimeException )
+{
+ return( Rasterizer_getSupportedServiceNames() );
+}
+
+// ------------------------------
+// - Uno instantiation function -
+// ------------------------------
+
+uno::Reference< uno::XInterface > SAL_CALL Rasterizer_createInstance( const uno::Reference< lang::XMultiServiceFactory >& )
+{
+ return static_cast< ::cppu::OWeakObject* >( new rsvg::Rasterizer );
+}
+
+} // namespace rsvg
+} // namespace vcl