drop the dummy surface prior to creating the real one
[rrdtool.git] / src / rrd_graph.c
index dcd9059..6f1a1ac 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * RRDtool 1.3rc7  Copyright by Tobi Oetiker, 1997-2008
+ * RRDtool 1.3.1  Copyright by Tobi Oetiker, 1997-2008
  ****************************************************************************
  * rrd__graph.c  produce graphs from data in rrdfiles
  ****************************************************************************/
@@ -2950,9 +2950,14 @@ int graph_paint(
     rrd_infoval_t info;
     PangoFontMap *font_map = pango_cairo_font_map_get_default();
 
-    /* if we are lazy and there is nothing to PRINT ... quit now */
-    if (lazy && im->prt_c == 0)
+    /* if we want and can be lazy ... quit now */
+    if (lazy) {
+        info.u_cnt = im->ximg;
+        grinfo_push(im, sprintf_alloc("image_width"), RD_I_CNT, info);
+        info.u_cnt = im->yimg;
+        grinfo_push(im, sprintf_alloc("image_height"), RD_I_CNT, info);
         return 0;
+    }
     /* pull the data from the rrd files ... */
     if (data_fetch(im) == -1)
         return -1;
@@ -2961,14 +2966,16 @@ int graph_paint(
         return -1;
     /* calculate and PRINT and GPRINT definitions. We have to do it at
      * this point because it will affect the length of the legends
-     * if there are no graph elements we stop here ... 
+     * if there are no graph elements (i==0) we stop here ... 
      * if we are lazy, try to quit ... 
      */
     i = print_calc(im);
     if (i < 0)
         return -1;
+
     if ((i == 0) || lazy)
         return 0;
+
 /**************************************************************
  *** Calculating sizes and locations became a bit confusing ***
  *** so I moved this into a separate function.              ***
@@ -3052,6 +3059,7 @@ int graph_paint(
             (im->surface, CAIRO_SVG_VERSION_1_1);
         break;
     };
+    cairo_destroy(im->cr);
     im->cr = cairo_create(im->surface);
     cairo_set_antialias(im->cr, im->graph_antialias);
     cairo_scale(im->cr, im->zoom, im->zoom);
@@ -3556,6 +3564,10 @@ int rrd_graph(
         walker = walker->next;
     }
     walker = grinfo;
+    *xsize = 0;
+    *ysize = 0;
+    *ymin = 0;
+    *ymax = 0;
     while (walker) {
         if (strcmp(walker->key, "image_width") == 0) {
             *xsize = walker->value.u_int;
@@ -3600,7 +3612,7 @@ rrd_info_t *rrd_graph_v(
     char **argv)
 {
     image_desc_t im;
-    rrd_info_t  *grinfo;
+    rrd_info_t *grinfo;
 
     rrd_graph_init(&im);
     /* a dummy surface so that we can measure text sizes for placements */
@@ -3656,10 +3668,17 @@ rrd_info_t *rrd_graph_v(
 
     if (im.imginfo) {
         rrd_infoval_t info;
+        char     *filename;
 
+        filename = im.graphfile + strlen(im.graphfile);
+        while (filename > im.graphfile) {
+            if (*(filename - 1) == '/' || *(filename - 1) == '\\')
+                break;
+            filename--;
+        }
         info.u_str =
             sprintf_alloc(im.imginfo,
-                          im.graphfile,
+                          filename,
                           (long) (im.zoom *
                                   im.ximg), (long) (im.zoom * im.yimg));
         grinfo_push(&im, sprintf_alloc("image_info"), RD_I_STR, info);
@@ -3746,26 +3765,6 @@ void rrd_graph_init(
     cairo_font_options_set_antialias(im->font_options, CAIRO_ANTIALIAS_GRAY);
     for (i = 0; i < DIM(graph_col); i++)
         im->graph_col[i] = graph_col[i];
-#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
-    {
-        char     *windir;
-        char      rrd_win_default_font[1000];
-
-        windir = getenv("windir");
-        /* %windir% is something like D:\windows or C:\winnt */
-        if (windir != NULL) {
-            strncpy(rrd_win_default_font, windir, 500);
-            rrd_win_default_font[500] = '\0';
-            strcat(rrd_win_default_font, "\\fonts\\");
-            strcat(rrd_win_default_font, RRD_DEFAULT_FONT);
-            for (i = 0; i < DIM(text_prop); i++) {
-                strncpy(text_prop[i].font,
-                        rrd_win_default_font, sizeof(text_prop[i].font) - 1);
-                text_prop[i].font[sizeof(text_prop[i].font) - 1] = '\0';
-            }
-        }
-    }
-#endif
     {
         char     *deffont;
 
@@ -3861,7 +3860,7 @@ void rrd_graph_options(
         int       col_start, col_end;
 
         opt = getopt_long(argc, argv,
-                          "s:e:x:y:v:w:h:D:iu:l:rb:oc:n:m:t:f:a:I:zgjFYAMEX:L:S:T:NR:B:W:k",
+                          "s:e:x:y:v:w:h:D:iu:l:rb:oc:n:m:t:f:a:I:zgjFYAMEX:L:S:T:NR:B:W:kP",
                           long_options, &option_index);
         if (opt == EOF)
             break;
@@ -4457,9 +4456,9 @@ int vdef_calc(
     src = &im->gdes[dst->vidx];
     data = src->data + src->ds;
     end =
-        src->end_orig % src->step ==
-        0 ? src->end_orig : (src->end_orig + src->step -
-                             src->end_orig % src->step);
+        src->end_orig % (long) src->step ==
+        0 ? src->end_orig : (src->end_orig + (long) src->step -
+                             src->end_orig % (long) src->step);
 
     steps = (end - src->start) / src->step;
 #if 0