allow output to stdout -- Timo Stripf
[rrdtool.git] / src / rrd_graph.c
index 4af6f82..f71f6dc 100644 (file)
@@ -327,16 +327,16 @@ int im_free(
     free(im->gdes);
     if (im->font_options)
         cairo_font_options_destroy(im->font_options);
-    
-    status = cairo_status (im->cr);
+
+    status = cairo_status(im->cr);
 
     if (im->cr)
         cairo_destroy(im->cr);
     if (im->surface)
         cairo_surface_destroy(im->surface);
     if (status)
-        fprintf(stderr,"OOPS: Cairo has issuesm it can't even die: %s\n",
-                         cairo_status_to_string (status));
+        fprintf(stderr, "OOPS: Cairo has issuesm it can't even die: %s\n",
+                cairo_status_to_string(status));
 
     return 0;
 }
@@ -1971,6 +1971,10 @@ double frexp10(
     return mnt;
 }
 
+/* from http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm */
+/* yes we are loosing precision by doing tos with floats instead of doubles
+   but it seems more stable this way. */
+
 static int AlmostEqual2sComplement(
     float A,
     float B,
@@ -2406,11 +2410,12 @@ void axis_paint(
 
 
     /* arrow for X and Y axis direction */
-    gfx_new_area(im, im->xorigin + im->xsize + 2, im->yorigin - 2, im->xorigin + im->xsize + 2, im->yorigin + 3, im->xorigin + im->xsize + 7, im->yorigin + 0.5,    /* LINEOFFSET */
+
+    gfx_new_area(im, im->xorigin + im->xsize + 2, im->yorigin - 3, im->xorigin + im->xsize + 2, im->yorigin + 3, im->xorigin + im->xsize + 7, im->yorigin,  /* horyzontal */
                  im->graph_col[GRC_ARROW]);
     gfx_close_path(im);
 
-    gfx_new_area(im, im->xorigin - 2, im->yorigin - im->ysize - 2, im->xorigin + 3, im->yorigin - im->ysize - 2, im->xorigin + 0.5, im->yorigin - im->ysize - 7,    /* LINEOFFSET */
+    gfx_new_area(im, im->xorigin - 3, im->yorigin - im->ysize - 2, im->xorigin + 3, im->yorigin - im->ysize - 2, im->xorigin, im->yorigin - im->ysize - 7,  /* vertical */
                  im->graph_col[GRC_ARROW]);
     gfx_close_path(im);
 
@@ -2843,9 +2848,17 @@ int graph_size_location(
     return 0;
 }
 
-/* from http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm */
-/* yes we are loosing precision by doing tos with floats instead of doubles
-   but it seems more stable this way. */
+
+
+static cairo_status_t cairo_write_func_file(
+       void *closure,
+       const unsigned char *data,
+       unsigned int length)
+{
+       if (fwrite(data, length, 1, closure) != 1)
+               return CAIRO_STATUS_WRITE_ERROR;
+       return CAIRO_STATUS_SUCCESS;
+}
 
 
 /* draw that picture thing ... */
@@ -2928,16 +2941,19 @@ int graph_paint(
                                        im->yimg * im->zoom);
         break;
     case IF_PDF:
+        im->gridfit = 0;
         im->surface =
             cairo_pdf_surface_create(im->graphfile, im->ximg * im->zoom,
                                      im->yimg * im->zoom);
         break;
     case IF_EPS:
+        im->gridfit = 0;
         im->surface =
             cairo_ps_surface_create(im->graphfile, im->ximg * im->zoom,
                                     im->yimg * im->zoom);
         break;
     case IF_SVG:
+        im->gridfit = 0;
         im->surface =
             cairo_svg_surface_create(im->graphfile, im->ximg * im->zoom,
                                      im->yimg * im->zoom);
@@ -3272,11 +3288,20 @@ int graph_paint(
 
     switch (im->imgformat) {
     case IF_PNG:
-        if (cairo_surface_write_to_png(im->surface, im->graphfile) !=
-            CAIRO_STATUS_SUCCESS) {
-            rrd_set_error("Could not save png to '%s'", im->graphfile);
-            return 1;
-        }
+               {
+                       cairo_status_t status;
+               
+                       if (strcmp(im->graphfile, "-") == 0) {
+               status = cairo_surface_write_to_png_stream(im->surface, &cairo_write_func_file, (void*)stdout);
+                       } else {
+               status = cairo_surface_write_to_png(im->surface, im->graphfile);
+                       }
+               
+               if (status != CAIRO_STATUS_SUCCESS) {
+               rrd_set_error("Could not save png to '%s'", im->graphfile);
+                   return 1;
+               }
+               }
         break;
     default:
         cairo_show_page(im->cr);