Using the font option resulted in a segfault. Needs more care,
[rrdtool.git] / src / rrd_graph.c
index 8900872..5597c49 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * RRDtool 1.0.33  Copyright Tobias Oetiker, 1997 - 2000
+ * RRDtool 1.1.x  Copyright Tobias Oetiker, 1997 - 2002
  ****************************************************************************
  * rrd__graph.c  make creates ne rrds
  ****************************************************************************/
@@ -21,7 +21,7 @@
 
 
 #ifndef RRD_DEFAULT_FONT
-#define RRD_DEFAULT_FONT "/usr/openwin/lib/X11/fonts/TrueType/Arial.ttf" 
+#define RRD_DEFAULT_FONT "/usr/share/fonts/truetype/openoffice/ariosor.ttf" 
 /* #define RRD_DEFAULT_FONT "/usr/share/fonts/truetype/Arial.ttf" */
 #endif
 
@@ -45,8 +45,8 @@ xlab_t xlab[] = {
     /*{300,      TMT_HOUR,3,    TMT_HOUR,12,   TMT_HOUR,12,    12*3600,"%a %p"},  this looks silly*/
     {600,      TMT_HOUR,6,    TMT_DAY,1,     TMT_DAY,1,      24*3600,"%a"},
     {1800,     TMT_HOUR,12,   TMT_DAY,1,     TMT_DAY,2,      24*3600,"%a"},
-    {3600,     TMT_DAY,1,     TMT_WEEK,1,     TMT_WEEK,1,    7*24*3600,"Week %W"},
-    {3*3600,   TMT_WEEK,1,      TMT_MONTH,1,     TMT_WEEK,2,    7*24*3600,"Week %W"},
+    {3600,     TMT_DAY,1,     TMT_WEEK,1,     TMT_WEEK,1,    7*24*3600,"Week %V"},
+    {3*3600,   TMT_WEEK,1,      TMT_MONTH,1,     TMT_WEEK,2,    7*24*3600,"Week %V"},
     {6*3600,   TMT_MONTH,1,   TMT_MONTH,1,   TMT_MONTH,1, 30*24*3600,"%b"},
     {48*3600,  TMT_MONTH,1,   TMT_MONTH,3,   TMT_MONTH,3, 30*24*3600,"%b"},
     {10*24*3600, TMT_YEAR,1,  TMT_YEAR,1,    TMT_YEAR,1, 365*24*3600,"%y"},
@@ -803,7 +803,7 @@ printf("DEBUG: value from vdef is %f\n",im->gdes[ptr].vf.val);
                             * further save step size and data source
                             * count of this rra
                             */ 
-                           im->gdes[gdi].rpnp[rpi].data = im->gdes[ptr].data; 
+                            im->gdes[gdi].rpnp[rpi].data =  im->gdes[ptr].data + im->gdes[ptr].ds;
                            im->gdes[gdi].rpnp[rpi].step = im->gdes[ptr].step;
                            im->gdes[gdi].rpnp[rpi].ds_cnt = im->gdes[ptr].ds_cnt;
 
@@ -1324,11 +1324,14 @@ leg_place(image_desc_t *im)
                    continue;
                im->gdes[ii].leg_x = leg_x;
                im->gdes[ii].leg_y = leg_y;
+printf("DEBUG: using font %s with width %lf\n",
+       im->text_prop[TEXT_PROP_LEGEND].font,
+       im->text_prop[TEXT_PROP_LEGEND].size);
                leg_x += 
                 gfx_get_text_width(leg_x,im->text_prop[TEXT_PROP_LEGEND].font,
                                      im->text_prop[TEXT_PROP_LEGEND].size,
                                      im->tabwidth,
-                                     im->gdes[i].legend) 
+                                     im->gdes[ii].legend) 
                   + legspace[ii]
                   + glue;
                if (im->gdes[ii].gf != GF_GPRINT && 
@@ -2511,27 +2514,48 @@ rrd_graph_options(int argc, char *argv[],image_desc_t *im)
             }
             break;        
         case 'n':{
-          char *prop = "";
-          double size = 1;
-          char *font = "dummy";
-
-          if(sscanf(optarg,
-                    "%10[A-Z]:%lf:%s",
-                    prop,&size,font) == 3){
-            int sindex;
-            if((sindex=text_prop_conv(prop)) != -1){
-              im->text_prop[sindex].size=size;              
-              im->text_prop[sindex].font=font;
-              
-            }  else {
-              rrd_set_error("invalid color name '%s'",col_nam);
-            }
-          } else {
-            rrd_set_error("invalid text property format");
-            return;
-          }
-          break;          
-        }
+                       /* originally this used char *prop = "" and
+                       ** char *font = "dummy" however this results
+                       ** in a SEG fault, at least on RH7.1
+                       **
+                       ** The current implementation isn't proper
+                       ** either, font is never freed and prop uses
+                       ** a fixed width string
+                       */
+           char prop[100];
+           double size = 1;
+           char *font;
+
+           font=malloc(255);
+           if(sscanf(optarg,
+                               "%10[A-Z]:%lf:%s",
+                               prop,&size,font) == 3){
+               int sindex;
+               if((sindex=text_prop_conv(prop)) != -1){
+printf("DEBUG: setting all to the default of font %s with width %lf\n",
+font,size);
+                   im->text_prop[sindex].size=size;              
+                   im->text_prop[sindex].font=font;
+                   if (sindex==0) { /* the default */
+                       im->text_prop[TEXT_PROP_TITLE].size=size;
+                       im->text_prop[TEXT_PROP_TITLE].font=font;
+                       im->text_prop[TEXT_PROP_AXIS].size=size;
+                       im->text_prop[TEXT_PROP_AXIS].font=font;
+                       im->text_prop[TEXT_PROP_UNIT].size=size;
+                       im->text_prop[TEXT_PROP_UNIT].font=font;
+                       im->text_prop[TEXT_PROP_LEGEND].size=size;
+                       im->text_prop[TEXT_PROP_LEGEND].font=font;
+                   }
+               } else {
+                   rrd_set_error("invalid fonttag '%s'",prop);
+                   return;
+               }
+           } else {
+               rrd_set_error("invalid text property format");
+               return;
+           }
+           break;          
+       }
         case 'm':
            im->zoom= atof(optarg);
            if (im->zoom <= 0.0) {