#define VIEWPORT_WIDTH 512
#define VIEWPORT_HEIGHT 512
-#define SVG_BUFFER_INCREMENT (size_t)4194304
-
/* Convenient typedefs for libsvgtiny */
typedef struct svgtiny_diagram diagram_t;
typedef struct svgtiny_shape shape_t;
/* The "file" */
char* svg_data;
- size_t svg_data_size;
- size_t svg_data_max;
+
+ /* How far into the file are we? This should always point to the
+ next empty byte. If (for example) svg_data_size is 2, then
+ svg_data[0] and svg_data[1] are used, but svg_data[2] is free. */
+ size_t svg_data_size;
} SvgTinyContext;
context->user_data = user_data;
/* YOLO, no error checking */
- context->svg_data = g_malloc(SVG_BUFFER_INCREMENT);
+ context->svg_data = g_malloc(0);
context->svg_data_size = 0;
return context;
}
static gboolean gdk_pixbuf_load_increment(gpointer data,
- const guchar* buf,
- guint size,
- GError** error) {
+ const guchar* buf,
+ guint buf_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;
+ /* YOLO, no error checking */
+ context->svg_data = g_realloc(context->svg_data,
+ context->svg_data_size + buf_size);
+ memcpy(context->svg_data + context->svg_data_size, buf, buf_size);
+ context->svg_data_size += buf_size;
return TRUE;
}