+ cr = cairo_context_from_diagram(diagram);
+ if (!cr) {
+ svgtiny_free(diagram);
+ return 1;
+ }
+
+ /* We're using the viewport width and height and not the diagram
+ * width/height for the image. The diagram can be of a different
+ * size and aspect ratio than the viewport, and our main use case is
+ * for icons that are generally square and reasonably sized. If the
+ * diagram is "small," then we want to scale it up until it fits
+ * nicely in the viewport before rendering it. That's as opposed to
+ * rendering the image small, and letting GDK scale it up. Of course
+ * this reasoning makes the assumption that the viewport is usually
+ * larger than the diagram.
+ */
+ pb = gdk_pixbuf_get_from_surface(cairo_get_target(cr),
+ 0,
+ 0,
+ VIEWPORT_WIDTH,
+ VIEWPORT_HEIGHT);
+
+
+ if (pb) {
+ gdk_pixbuf_save(pb, pngpath, "png", NULL, NULL);
+ g_object_unref(pb);
+ }
+
+ return 0;
+}
+
+
+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) {
+ return NULL;
+ }
+
+ cr = cairo_context_from_diagram(diagram);
+ if (!cr) {
+ svgtiny_free(diagram);
+ return NULL;
+ }
+
+
+ /* We're using the viewport width and height and not the diagram
+ * width/height for the image. The diagram can be of a different
+ * size and aspect ratio than the viewport, and our main use case is
+ * for icons that are generally square and reasonably sized. If the
+ * diagram is "small," then we want to scale it up until it fits
+ * nicely in the viewport before rendering it. That's as opposed to
+ * rendering the image small, and letting GDK scale it up. Of course
+ * this reasoning makes the assumption that the viewport is usually
+ * larger than the diagram.
+ */
+ pb = gdk_pixbuf_get_from_surface(cairo_get_target(cr),
+ 0,
+ 0,
+ VIEWPORT_WIDTH,
+ VIEWPORT_HEIGHT);
+
+
+ if (!pb) {
+ fprintf(stderr, "gdk_pixbuf_get_from_surface failed!\n");
+ }
+
+ return pb;