+static gpointer gdk_pixbuf_begin_load(GdkPixbufModuleSizeFunc size_func,
+ GdkPixbufModulePreparedFunc prep_func,
+ GdkPixbufModuleUpdatedFunc updated_func,
+ gpointer user_data,
+ GError **error) {
+
+ SvgTinyContext* context = g_new(SvgTinyContext, 1);
+
+ context->size_func = size_func;
+ context->prepared_func = prep_func;
+ context->updated_func = updated_func;
+ context->user_data = user_data;
+
+ /* YOLO, no error checking */
+ context->svg_data = g_malloc(SVG_BUFFER_INCREMENT);
+ context->svg_data_size = 0;
+
+ return context;
+}
+
+static gboolean gdk_pixbuf_load_increment(gpointer data,
+ const guchar* buf,
+ guint size,
+ GError** error) {
+ size_t increment = 0;
+ SvgTinyContext* context = (SvgTinyContext*)data;
+
+ if (context->svg_data_size + size > context->svg_data_max) {
+ if (size > SVG_BUFFER_INCREMENT) {
+ increment = size;
+ }
+ else {
+ increment = SVG_BUFFER_INCREMENT;
+ }
+
+ /* YOLO, no error checking */
+ context->svg_data = g_realloc(context->svg_data,
+ context->svg_data_max + increment);
+
+ context->svg_data_max += increment;
+ }
+
+ memcpy(context->svg_data + context->svg_data_size, buf, size);
+ context->svg_data_size += size;
+
+ return TRUE;
+}
+
+static void emit_updated(SvgTinyContext* context, GdkPixbuf* pixbuf) {
+ if (context->updated_func != NULL) {
+ (*context->updated_func)(pixbuf,
+ 0,
+ 0,
+ gdk_pixbuf_get_width(pixbuf),
+ gdk_pixbuf_get_height(pixbuf),
+ context->user_data);
+ }
+}
+
+static void emit_prepared(SvgTinyContext* context, GdkPixbuf* pixbuf) {
+ if (context->prepared_func != NULL) {
+ (*context->prepared_func)(pixbuf, NULL, context->user_data);
+ }
+}
+
+
+/*
+static void emit_size(SvgTinyContext* context, GdkPixbuf* pixbuf) {
+ int w = gdk_pixbuf_get_width(pixbuf);
+ int h = gdk_pixbuf_get_height(pixbuf);
+ if (context->size_func != NULL) {
+ (*context->size_func)(&w, &h, context->user_data);
+ }
+}
+*/
+
+
+static gboolean gdk_pixbuf_stop_load(gpointer data, GError **error) {
+ SvgTinyContext* context = (SvgTinyContext*)data;
+ GdkPixbuf* pixbuf = NULL;
+ gboolean result = TRUE;
+ GError* sub_error = NULL;
+
+ pixbuf = gdk_pixbuf_from_svg_buffer(context->svg_data,
+ context->svg_data_size,
+ &sub_error);
+
+ if (pixbuf != NULL) {
+ /*emit_size(context, pixbuf);*/
+ emit_prepared(context, pixbuf);
+ emit_updated(context, pixbuf);
+ g_object_unref(pixbuf);
+ }
+ else {
+ g_propagate_error(error, sub_error);
+ result = FALSE;
+ }
+ g_free(context);
+
+ return result;
+}
+
+