egroupware1.6.003亂碼問題解決【供參考】

edited 十月 2013 in egroupware
首先謝謝kiang和這個網站提供的幫助,
上次說要寫一份相關文檔的了,拖了這麼久,實在不好意思

1 bug描述
egroupware的專案管理系統裡的甘特圖模組存在亂碼問題。
Contents
2 原因
1. egroupware處理中文時,會進行編 碼 轉換,把文字從big-5轉換為utf-8(iconv(‘big-5’,’utf-8’,$txt)), 對於伺服器環境本身為utf-8,這一部顯然是多餘的
2. php的畫圖函式程式庫jpgraph處理中文時不正確的設置
3. 伺服器上中文字體庫未被找到

Contents
3 相關說明
1. Egroupware使用的jpgraph是1.5.2(而最新版的是3.0.7),如果egroupware檢測不到新版jpgraph(if(file_exists(EGW_SERVER_ROOT . '/../jpgraph/src/jpgraph.php'))), 則使用1.5.2(egroupware\projectmanager\inc\jpgraph-1.5.2目錄下)
2. 可以通過專案管理->網站配置,修改甘特圖的部分設置(字型、字元集字型、風格),其中字型可以修改為BIG5(編號31,對應jpgraph裡的31,即FF_CHINESE)和Simsun(編好30,對應jpgraph的30,即FF_BIG5)
3. uming.ttf這個字體可以改為其它中 文字體,並放到相應目錄下(我這裡是放到egroupware的D:\zjustu\專案\內部工作系統\pear\egroupware\projectmanager\inc\ttf-bitstream-vera-1.10下,故jpgraph的字體目錄也設置為這個)
4 具體方法
4.1 直接手動設置字體相關設置
修改egroupware下的projectmanager\inc\class.projectmanager_ganttchart.inc.php:

將if(file_exists(EGW_SERVER_ROOT . '/../jpgraph/src/jpgraph.php'))
{
$GLOBALS = config::read('projectmanager');

foreach(array(
'TTF_DIR' => '',
'LANGUAGE_CHARSET' => 'iso-8859-1',
'GANTT_FONT' => 15, //FF_ARIAL
'GANTT_FONT_FILE' => 'arial.ttf',
'GANTT_STYLE' => 9002, //FS_BOLD,
'GANTT_CHAR_ENCODE'=> false,
) as $name => $default)
{
if (isset($GLOBALS[$name]))
{
define($name,$GLOBALS[$name]);
}
elseif($name == 'TTF_DIR')
{
if (!($font_file = $GLOBALS)) $font_file = 'arial.ttf';
// using the OS font dir if we can find it, otherwise fall back to our bundled Vera font
foreach(array(
'/usr/X11R6/lib/X11/fonts/truetype/', // linux / *nix default
'/usr/share/fonts/ja/TrueType/', // japanese fonts
'/usr/share/fonts/msttcorefonts/', // to install this fonts see http://www.aditus.nu/jpgraph/jpdownload.php
'C:/windows/fonts/', // windows default
// add your location here or to egw_config.config_value for config_app='projectmanger' AND config_name='TTF_DIR'
EGW_SERVER_ROOT.'/projectmanager/inc/ttf-bitstream-vera-1.10/', // our bundled Vera font
) as $dir)
{
if (@is_dir($dir) && (is_readable($dir.$font_file) || is_readable($dir.'Vera.ttf')))
{
define('TTF_DIR',$GLOBALS[$name]=$dir);
if (!is_readable($dir.$font_file)) // fallback to our bundled Vera font
{
$GLOBALS = 18; // FF_VERA
$GLOBALS = 'Vera.ttf';
}
break;
}
}
}
elseif($default)
{
define($name,$GLOBALS[$name]=$default);
}
}
//_debug_array($GLOBALS);
if (!defined('MBTTF_DIR')) define('MBTTF_DIR',TTF_DIR);

include(EGW_SERVER_ROOT . '/../jpgraph/src/jpgraph.php');
include(EGW_SERVER_ROOT . '/../jpgraph/src/jpgraph_gantt.php');
}
else
{
include(EGW_SERVER_ROOT . '/projectmanager/inc/jpgraph-1.5.2/src/jpgraph.php');
include(EGW_SERVER_ROOT . '/projectmanager/inc/jpgraph-1.5.2/src/jpgraph_gantt.php');
define('TTF_DIR',EGW_SERVER_ROOT.'/projectmanager/inc/ttf-bitstream-vera-1.10/');
define('GANTT_FONT',FF_VERA);
define('GANTT_STYLE',FS_BOLD);
define('LANGUAGE_CHARSET','iso-8859-1');
define('GANTT_CHAR_ENCODE',true);
}
替換為
if(file_exists(EGW_SERVER_ROOT . '/../jpgraph/src/jpgraph.php'))
{


foreach(array(
'TTF_DIR' => '/var/www/html/egroupware/projectmanager/inc/ttf-bitstream-vera-1.10/',
'LANGUAGE_CHARSET' => 'utf-8',//iso-8859-1
'GANTT_FONT' => 31, //FF_CHINESE
'GANTT_FONT_FILE' => 'uming.ttf',
'GANTT_STYLE' => 9001, //FS_BOLD,
'GANTT_CHAR_ENCODE'=> false,
) as $name => $default)

{
define($name,$GLOBALS[$name]=$default);
}

//_debug_array($GLOBALS);
if (!defined('MBTTF_DIR')) define('MBTTF_DIR',TTF_DIR);

include(EGW_SERVER_ROOT . '/../jpgraph/src/jpgraph.php');
include(EGW_SERVER_ROOT . '/../jpgraph/src/jpgraph_gantt.php');
}
else
{
include(EGW_SERVER_ROOT . '/projectmanager/inc/jpgraph-1.5.2/src/jpgraph.php');
include(EGW_SERVER_ROOT . '/projectmanager/inc/jpgraph-1.5.2/src/jpgraph_gantt.php');
define('TTF_DIR',EGW_SERVER_ROOT.'/projectmanager/inc/ttf-bitstream-vera-1.10/');
define('GANTT_FONT',FF_VERA);
define('GANTT_STYLE',FS_BOLD);
define('LANGUAGE_CHARSET','utf-8');
define('GANTT_CHAR_ENCODE',true);
}

4.1.1 修改字元集
define('LANGUAGE_CHARSET','iso-8859-1');
替換為
define('LANGUAGE_CHARSET','utf-8');

4.1.2 去掉編碼轉換
function text_encode($text)
{
// convert to the charset used for the gantchart
$text = $GLOBALS->translation->convert($text,$this->charset,$this->gantt_charset);

// convert everything above ascii to nummeric html entities
// not sure if this is necessary for non iso-8859-1 charsets, try to comment it out if you have problems
if ($this->gantt_char_encode) $text = preg_replace('/[^\x00-\x7F]/e', '"&#".ord("$0").";"',$text);

return $text;
}
改為
function text_encode($text)
{


// convert to the charset used for the gantchart
$text = $GLOBALS->translation->convert($text,$this->charset,$this->gantt_charset);
return $text;
}
4.2 修 改jpgraph中的字體設置
修改jpg-config.inc.php:
最開始加入
define('CSIMCACHE_DIR','csimcache/');
define('CSIMCACHE_HTTP_DIR','csimcache/');
define('TTF_DIR', '/var/www/html/egroupware/projectmanager/inc/ttf-bitstream-vera-1.10/');
define('CHINESE_TTF_FONT', 'uming.ttf');




原始討論: http://twpug.net/x/modules/newbb/viewtopic.php?topic_id=5166

評論

Sign In or Register to comment.