+ chart->class->draw (chart, cr, geom);
+}
+
+char *
+chart_draw_png (const struct chart *chart, const char *file_name_template,
+ int number)
+{
+ const int width = 640;
+ const int length = 480;
+
+ struct chart_geometry geom;
+ cairo_surface_t *surface;
+ cairo_status_t status;
+ const char *number_pos;
+ char *file_name;
+ cairo_t *cr;
+
+ number_pos = strchr (file_name_template, '#');
+ if (number_pos != NULL)
+ file_name = xasprintf ("%.*s%d%s", (int) (number_pos - file_name_template),
+ file_name_template, number, number_pos + 1);
+ else
+ file_name = xstrdup (file_name_template);
+
+ surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, width, length);
+ cr = cairo_create (surface);
+
+ cairo_translate (cr, 0.0, length);
+ cairo_scale (cr, 1.0, -1.0);
+
+ cairo_save (cr);
+ cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
+ cairo_rectangle (cr, 0, 0, width, length);
+ cairo_fill (cr);
+ cairo_restore (cr);
+
+ cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+
+ chart_geometry_init (cr, &geom, width, length);
+ chart_draw (chart, cr, &geom);
+ chart_geometry_free (cr);
+
+ status = cairo_surface_write_to_png (surface, file_name);
+ if (status != CAIRO_STATUS_SUCCESS)
+ error (0, 0, _("writing output file \"%s\": %s"),
+ file_name, cairo_status_to_string (status));
+
+ cairo_destroy (cr);
+ cairo_surface_destroy (surface);
+
+ return file_name;