让cacti支持中文

在chinaunix上看了abel的帖子,其中有如何让cacti中的rrdtools支持中文字符的部分,就对Heinet的cacti修改了一下,比较顺利。

cacti版本0.8.6i、rrdtool版本1.2.9。

主要是修改rrdtools源码中的两个文件。

diff -u rrdtool-1.2.8/src/rrd_gfx.c rrdtool-1.2.8-big5/src/rrd_gfx.c
— rrdtool-1.2.8/src/rrd_gfx.c Fri Jun 10 16:54:58 2005
+++ rrdtool-1.2.8-big5/src/rrd_gfx.c Fri Jun 10 16:45:42 2005
@@ -378,6 +378,9 @@
  unsigned int  n;
  int           error;
  int        gottab = 0;  
+  // 雙字元處理 multi-bytes 問題
+  wchar_t* w_text;
+
  ft_pen.x = 0;   /* start at (0,0) !! */
  ft_pen.y = 0;
 
@@ -391,6 +394,11 @@
  string->;transform.xy = (FT_Fixed)(-sin(M_PI*(rotation)/180.0)*0x10000);
  string->;transform.yx = (FT_Fixed)( sin(M_PI*(rotation)/180.0)*0x10000);
  string->;transform.yy = (FT_Fixed)( cos(M_PI*(rotation)/180.0)*0x10000);
+  // pointer malloc
+  w_text = (wchar_t) calloc (string->;count,sizeof(wchar_t));
+  //  轉換為 wide 型式
+  mbstowcs(w_text,text,string->;count);
+
 
  use_kerning = FT_HAS_KERNING(face);
  previous    = 0;
@@ -419,8 +427,8 @@
    glyph->;pos.x = 0;
    glyph->;pos.y = 0;
    glyph->;image = NULL;

–    glyph->;index = FT_Get_Char_Index( face, letter );
+ // 字符隻轉換
+    glyph->;index = FT_Get_Char_Index( face, w_text[n]);
 
    /* compute glyph origin */
    if ( use_kerning && previous && glyph->;index ) {
@@ -495,6 +503,8 @@
  } */
  string->;height = string->;bbox.yMax – string->;bbox.yMin;
 
+  free(w_text);
+
  return string;
}
 
diff -u rrdtool-1.2.8/src/rrd_graph.c rrdtool-1.2.8-big5/src/rrd_graph.c
— rrdtool-1.2.8/src/rrd_graph.c Fri Jun 10 16:54:58 2005
+++ rrdtool-1.2.8-big5/src/rrd_graph.c Fri Jun 10 16:36:04 2005
@@ -2793,7 +2793,9 @@
    tzset();
#endif
#ifdef HAVE_SETLOCALE
–    setlocale(LC_TIME,””);
+    //setlocale(LC_TIME,””);
+    // 可以不定 locale , 由系統自動判斷
+    setlocale(LC_ALL,”zh_CN.GB2312″);
#endif
    im->;yorigin=0;
    im->;xorigin=0;

人懒了没有做patch文件,就对这里面的一些+-直接修改了两个文件,然后编译安装,没有报错信息。

登录到cacti中,在setting->paths中设置“RRDTool Default Font Path”为/usr/share/fonts/zh_CN/TrueType/zysong.ttf,ok了。

当然我想从window中拷贝几个中文字体过去也是可以的。

搞技术,追本朔源才是根本,我都不过是井底一只蛙而已,叹。。

发表回复