From 32c60685bacab38b0d2ad35f8904eeccff7ab862 Mon Sep 17 00:00:00 2001 From: Jochen Keil Date: Wed, 22 May 2013 20:51:11 +0200 Subject: [PATCH] Wrapper functions for {creat,destroy}ing an rsvg handle This wrapper functions should facilitate the handling of rsvg handles. Especially unrefing with g_object_unref does not seem to work properly using the lua bindings. --- lua/librsvg-helper.h | 71 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 7 deletions(-) diff --git a/lua/librsvg-helper.h b/lua/librsvg-helper.h index 26916bc2..900227e9 100644 --- a/lua/librsvg-helper.h +++ b/lua/librsvg-helper.h @@ -25,18 +25,75 @@ #ifndef _LIBRSVG_HELPER_H_ #define _LIBRSVG_HELPER_H_ -#include +#include +#include -cairo_text_extents_t *create_cairo_text_extents_t(void) { - return calloc(1, sizeof(cairo_text_extents_t)); +RsvgDimensionData * +rsvgDimensionDataCreate(void) +{ + return (RsvgDimensionData *)calloc(1, sizeof(RsvgDimensionData)); } -cairo_font_extents_t *create_cairo_font_extents_t(void) { - return calloc(1, sizeof(cairo_font_extents_t)); +void +rsvgDimensionDataGet(RsvgDimensionData * dd, + int * width, int * height, double * em, double * ex) +{ + if (dd) { + *width = dd->width; + *height = dd->height; + *em = dd->em; + *ex = dd->ex; + } } -cairo_matrix_t *create_cairo_matrix_t(void) { - return calloc(1, sizeof(cairo_matrix_t)); +RsvgPositionData * +rsvgPositionDataCreate(void) +{ + return (RsvgPositionData *)calloc(1, sizeof(RsvgPositionData)); +} + +void +rsvgPositionDataGet(RsvgPositionData * pd, int * x, int * y) +{ + if (pd) { + *x = pd->x; + *y = pd->y; + } +} + +RsvgHandle * +rsvg_create_handle_from_file(const char * filename) +{ + GError * error = NULL; + RsvgHandle * handle = rsvg_handle_new_from_file(filename, &error); + + if (error) { + g_object_unref(error); + if (handle) + g_object_unref(handle); + handle = NULL; + } + + return handle; +} + +int +rsvg_destroy_handle(RsvgHandle * handle) +{ + int status = 0; + + if (handle) { + GError * error = NULL; + status = rsvg_handle_close(handle, &error); + + if (status) + g_object_unref(handle); + + if (error) + g_object_unref(error); + } + + return status; } #endif /* _LIBRSVG_HELPER_H_ */