| 
 
 
 
 
 
 | 
                      
	| 發表者 | 討論內容 |  
	| 冷日 (冷日)
 | 發表時間:2011/11/29 7:47 |  
	| 
	Webmaster   
		註冊日: 2008/2/19來自: 發表數: 15773 | 
	[轉貼]dotProject 的甘特圖中文修改  雖然我是用在mantis,不過問題總算是解決了~~~原來是utf-8的問題。測試 GD 的中文支援性
 確定 PHP、GD中文運作正常
 Header( "Content-type: image/gif" );$im = imagecreate( 400, 150 );
 $black = ImageColorAllocate( $im, 0, 0, 0 );
 $white = ImageColorAllocate( $im, 255, 255, 255 );
 $fnt = "/usr/share/fonts/corefonts/fireflysung.ttf";
 $str = iconv("BIG5","UTF-8","中文");
 ImageTTFText($im, 30, 0, 50,50, $white, $fnt, $str);
 ImageGif($im);
 ImageDestroy($im);
 ?>
 如果這裡沒問題,代表 PHP、GD 沒問題了~
 
jpgraph
 更新 dotproject/lib/jpgraph到官方網站更新至新版:
 http://www.aditus.nu/jpgraph/
 
修改 jpg-config.inc.php 設定,加入中文字型 加入 DEFINE("TTF_DIR"," /usr/share/fonts/corefonts/");將 DEFINE('CHINESE_TTF_FONT','bkai00mp.ttf');改為 DEFINE('CHINESE_TTF_FONT',' fireflysung.ttf');
 
修改 jpgraph.php
 
 取消內建的 UTF-8 轉碼由於本來就是使用UTF-8,所以要把內部的自動轉換關閉。搜尋「iconv」,找到
 elseif( $aFF === FF_CHINESE ) {if( !function_exists('iconv') ) {
 JpGraphError::RaiseL(25006);
 //('Usage of FF_CHINESE (FF_BIG5) font family requires that your PHP setup has the iconv() function. By de$
 }
 return iconv('BIG5','UTF-8',$aTxt);
 )
修改為 
 elseif( $aFF === FF_CHINESE ) {return $aTxt;
 }
修改字型對應
 找到  FF_CHINESE => array(FS_NORMAL=>CHINESE_TTF_FONT, FS_BOLD=>'', FS_ITALIC=>'', FS_BOLDITALIC=>''), 修改成  FF_CHINESE => array(FS_NORMAL=>CHINESE_TTF_FONT, FS_BOLD=>CHINESE_TTF_FONT, FS_ITALIC=>CHINESE_TTF_FONT, FS_BOLDITALIC=>CHINESE_TTF_FONT ), 如果要設定粗體、斜體為不同字型,要另外設定別的字型檔給 FS_BOLD、FS_ITALIC。加入區域偵測
 應該是用來設定日期的格式的,原則上應該是要給正確的值給他,但是寫在這比較方便。找到 function Set($aLocale),在下方加入
  $query = "SELECT 'config_value' FROM 'config' WHERE 'config_name = host_locale'";$aLocale = mysql_query ($query);
 
測試設定:
 include ("../jpgraph.php");include ("../jpgraph_gantt.php");
 $bar1 = new GanttBar(0, iconv("BIG5","UTF8","中文 1"),"2001-12-21","2002-01-20");
 $bar1->SetCSIMTarget('#','Go back 1');
 $bar1->title->SetCSIMTarget('#','Go back 1 (title)');
 $bar1->title->SetFont( FF_CHINESE, FS_NORMAL, 8 );
 $bar2 = new GanttBar(1,"Activity 2","2002-01-03","2002-01-25");
 $bar2->SetCSIMTarget('#','Go back 2');
 $bar2->title->SetCSIMTarget('#','Go back 2 (title)');
 $graph = new GanttGraph(500);
 $graph->title->Set("Example with image map");
 $graph->ShowHeaders(GANTT_HYEAR | GANTT_HMONTH | GANTT_HDAY | GANTT_HWEEK);
 $graph->scale->week->SetStyle(WEEKSTYLE_FIRSTDAY);
 $graph->scale->week->SetFont(FF_FONT1);
 $graph->Add(array($bar1,$bar2));
 // And stroke
 $graph->StrokeCSIM('ganttcsimex01.php');
 ?>
 如果這裡沒問題,應該代表 jpgraph 的設定沒問題。
dotProject
 修改 dotproject/modules/projects/gantt.php
 
 取消內建的 UTF-8 轉碼由於本來就是使用UTF-8,所以要把內部的自動轉換關閉。 找到 if ( $locale_char_set=='utf-8' && function_exists("utf8_decode") ) {$name = strlen( utf8_decode($p["project_name"]) ) > 25 ? substr( utf8_decode($p["project_name"]), 0, 22 ).'...' : utf8_decode($p["project_name"]) ;
 } else {
 //while using charset different than UTF-8 we need not to use utf8_deocde
 $name = strlen( $p["project_name"] ) > 25 ? substr( $p["project_name"], 0, 22 ).'...' : $p["project_name"] ;
 }
改成  $name = strlen( $p["project_name"] ) > 25 ? substr( $p["project_name"], 0, 22 ).'...' : $p["project_name"] ;修改字型設定
 找到 //$graph->scale->actinfo->SetFont(FF_ARIAL);
 改為 $graph->scale->actinfo->SetFont(FF_CHINESE);
 
找到// Use TTF font if it exists// try commenting out the following two lines if gantt charts do not display
 if (is_file( TTF_DIR."arialbd.ttf" ))
 $graph->scale->tableTitle->SetFont(FF_ARIAL,FS_BOLD,12);
 修改為 $graph->scale->tableTitle->SetFont(FF_CHINESE,FS_BOLD,12);找到 $bar->title->SetCOlor('red');$graph->Add($bar);
 加入一行,變成  $bar->title->SetCOlor('red');$bar->title->SetFont(FF_CHINESE,FS_BOLD,8);
 $graph->Add($bar);
找到 $bar->title->SetFont(FF_FONT1,FS_NORMAL,10);改為 $bar->title->SetFont(FF_CHINESE,FS_NORMAL,10);
 
找到$bar->caption = new TextProperty($caption);
 在之後加入 $bar->caption->SetFont(FF_CHINESE,FS_NORMAL,10);
 
找到 $graph->Add($bar2);共兩處,在前面加上 $bar2->title->SetFont(FF_CHINESE,FS_NORMAL,10);
 
找到 $graph->Add($bar3);在前面加上 $bar3->title->SetFont(FF_CHINESE,FS_NORMAL,10);
 
找到 $graph->Add($vline);在前面加上 $vline->title->SetFont(FF_CHINESE,FS_BOLD,8);
 
修改 dotproject/modules/tasks/gantt.php 取消內建的UTF-8轉碼由於本來就是使用UTF-8,所以要把內部的自動轉換關閉。 找到 
 if( $local_char_set==』 utf-8' && function_exists('utf8_decode') ) {$name = utf8_decode($name);
 }
把這三行刪除。修改字型設定:
 找到if (is_file( TTF_DIR.'arialbd.ttf' )){$graph->scale->actinfo->SetFont(FF_ARIAL);
 }
修改為 $graph->scale->actinfo->SetFont(FF_CHINESE);
找到// Use TTF font if it exists// try commenting out the following two lines if gantt charts do not display
 if (is_file( TTF_DIR.'arialbd.ttf' ))
 $graph->scale->tableTitle->SetFont(FF_ARIAL,FS_BOLD,12);
 修改為 $graph->scale->tableTitle->SetFont(FF_CHINESE,FS_BOLD,12);
找到 $graph->Add($bar);共兩處,在前面加上
 $bar->title->SetFont(FF_CHINESE,FS_NORMAL,10);
 
找到if (is_file( TTF_DIR.'arialbd.ttf' )) {$vline->title->SetFont(FF_ARIAL,FS_BOLD,10);
 }
修改為 $vline->title->SetFont(FF_CHINESE,FS_BOLD,8);
 原文出處:kaowoei的自爽地: dotProject 的甘特圖中文修改
 |  
	|  |  
 討論串
 
 
                     |