j += 7;
break;
default:
- printf("error ");
+ fprintf(stderr, "error: unmatched case in render_path\n");
j += 1;
}
}
free(buffer);
if (code != svgtiny_OK) {
- fprintf(stderr, "svgtiny_parse failed: ");
+ fprintf(stderr, "svgtiny_parse failed with ");
switch (code) {
case svgtiny_OUT_OF_MEMORY:
fprintf(stderr, "svgtiny_OUT_OF_MEMORY");
return cr;
}
-static GdkPixbuf* gdk_pixbuf_from_svg_file_stream(FILE *fp, GError **error) {
+static GdkPixbuf* gdk_pixbuf_from_svg_file_stream(FILE *fp, GError** error) {
diagram_t* diagram;
cairo_t* cr = 0;
-
GdkPixbuf* pb;
diagram = svgtiny_diagram_from_file(fp, VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
if (!diagram) {
+ g_set_error_literal(error,
+ GDK_PIXBUF_ERROR,
+ GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
+ "Could not parse SVG diagram from file");
return NULL;
}
cr = cairo_context_from_diagram(diagram);
if (!cr) {
svgtiny_free(diagram);
+ g_set_error_literal(error,
+ GDK_PIXBUF_ERROR,
+ GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
+ "Could not create Cairo surface from SVG diagram");
return NULL;
}
if (!pb) {
- fprintf(stderr, "gdk_pixbuf_get_from_surface failed!\n");
+ g_set_error_literal(error,
+ GDK_PIXBUF_ERROR,
+ GDK_PIXBUF_ERROR_FAILED,
+ "Failed to obtain a GdkPixbuf from Cairo surface");
}
return pb;
char* svgpath;
char* pngpath;
FILE* fp;
+ GError* err = NULL;
GdkPixbuf* pb;
/* Parse arguments, and maybe print usage */
return 1;
}
- pb = gdk_pixbuf_from_svg_file_stream(fp, NULL);
- if (pb) {
- gdk_pixbuf_save(pb, pngpath, "png", NULL, NULL);
- g_object_unref(pb);
+ pb = gdk_pixbuf_from_svg_file_stream(fp, &err);
+ if (!pb) {
+ fprintf(stderr,
+ "Error %d in gdk_pixbuf_from_svg_file_stream: %s\n",
+ err->code,
+ err->message);
+ g_error_free(err);
+ return 1;
}
+ gdk_pixbuf_save(pb, pngpath, "png", NULL, NULL);
+ g_object_unref(pb);
return 0;
}