[Secureideas-cvs] base-php4 base_graph_display.php,1.21,1.22
Brought to you by:
secureideas,
sinukas
From: Juergen L. <jle...@us...> - 2008-03-01 19:20:25
|
Update of /cvsroot/secureideas/base-php4 In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv6497/base-php4 Modified Files: base_graph_display.php Log Message: I've written a workaround for the font problem in safe_mode. In such a case BASE is now falling back to a default font. This font looks not too bad in my opinion, but I do not seem to be able to adjust the font size with this default font. Index: base_graph_display.php =================================================================== RCS file: /cvsroot/secureideas/base-php4/base_graph_display.php,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- base_graph_display.php 29 Feb 2008 18:59:01 -0000 1.21 +++ base_graph_display.php 1 Mar 2008 19:20:21 -0000 1.22 @@ -39,7 +39,7 @@ require_once('Image/Graph.php'); - + // One more time: A workaround for the inability of PEAR::Image_Canvas-0.3.1 // to deal with strings as x-axis labels in a proper way in the case // of a logarithmic y-axis. @@ -53,6 +53,161 @@ + function check_fontmap($font_name, $fontmap) + { + GLOBAL $debug_mode; + + + $ok = 0; + + if (file_exists($fontmap)) + // then we ASSUME, that this is the correct fontmap.txt file. Not necessarily true, though. + { + if (is_readable($fontmap)) + { + $fd = file($fontmap); + foreach($fd as $line) + { + list($map_fontname, $fontfiles_str) = explode(',', $line); + $map_fontname = trim($map_fontname); + if (strcmp($font_name, $map_fontname) == 0) + // this line of fontmap.txt countains our font + // Now is there also a corresponding font file? + { + $fontfiles_str = trim($fontfiles_str); + if ($debug_mode > 1) + { + error_log("fontfiles_str = \"" . $fontfiles_str . "\""); + } + $filenames_array = explode(',', $fontfiles_str); + foreach($filenames_array as $single_filename) + { + $single_filename = trim($single_filename); + if ($debug_mode > 0) + { + error_log("single_filename = \"" . $single_filename . "\""); + } + if (file_exists($single_filename)) + { + if (is_readable($single_filename)) + { + $ok = 1; + break; + } + } + + // trying to imitate fontMap() in Image_Canvas-0.3.1/Canvas/Tool.php in a simplified way + $image_canvas_system_font_path = "."; + if (array_key_exists("IMAGE_CANVAS_SYSTEM_FONT_PATH", $_SESSION)) + { + $image_canvas_system_font_path = $_SESSION['IMAGE_CANVAS_SYSTEM_FONT_PATH']; + } + elseif (array_key_exists("IMAGE_CANVAS_SYSTEM_FONT_PATH", $_SERVER)) + { + $image_canvas_system_font_path = $_SERVER['IMAGE_CANVAS_SYSTEM_FONT_PATH']; + } + elseif (array_key_exists("IMAGE_CANVAS_SYSTEM_FONT_PATH", $_ENV)) + { + $image_canvas_system_font_path = $_ENV['IMAGE_CANVAS_SYSTEM_FONT_PATH']; + } + + if (file_exists($image_canvas_system_font_path . '/' . $single_filename)) + { + if (is_readable($image_canvas_system_font_path . '/' . $single_filename)) + { + $ok = 1; + break; + } + } + } + + + if ($ok == 1) + { + break; + } + } // strcmp() + + if ($ok == 1) + { + if ($debug_mode > 0) + { + error_log("File for font " . $font_name . " found!"); + } + break; + } + } + } + else + { + error_log(__FILE__ . ":" . __LINE__ . ": ERROR: \"$fontmap\" does exist, but it is NOT READABLE.<BR>\n"); + return 0; + } + } + + + + if ($ok == 1) + { + if ($debug_mode > 0) + { + error_log("Found! File for font " . $font_name . " could be found!"); + } + } + return $ok; + } + + + + + function check_font($font_name) + { + GLOBAL $debug_mode; + + $ok = 0; + $php_path = ini_get('include_path'); + $php_path_array = explode(':', $php_path); + if ($debug_mode > 1) + { + error_log("Where is fontmap.txt?"); + } + foreach($php_path_array as $single_path) + { + $where_is_it = "$single_path/Image/Canvas/Fonts/fontmap.txt"; + if ($debug_mode > 1) + { + error_log($where_is_it); + } + + if (file_exists($where_is_it)) + { + if (is_readable($where_is_it)) + { + if ($debug_mode > 0) + { + error_log("fontmap is located in ". $where_is_it); + } + $rv = check_fontmap($font_name, $where_is_it); + if ($debug_mode > 0) + { + error_log("check_fontmap() returned " . $rv); + } + if ($rv == 1) + { + $ok = 1; + } + break; + } + else + { + error_log($where_is_it . " does exist, but is not readable."); + } + } + } + return $ok; + } + + $xdata = $_SESSION['xdata']; $width = ImportHTTPVar("width", VAR_DIGIT); $height = ImportHTTPVar("height", VAR_DIGIT); @@ -178,18 +333,42 @@ ); } } - - - $Font =& $Graph->addNew('font', 'Verdana'); - if (($chart_type == 15) || ($chart_type == 17)) + + + $rv = ini_get("safe_mode"); + if ($rv != 1) + // normal mode { - $Font->setSize(10); + $font_name = "Verdana"; + if (check_font($font_name)) + { + $Font =& $Graph->addNew('font', $font_name); + } + else + { + $Font =& $Graph->addNew('Image_Graph_Font'); + error_log(__FILE__ . ":" . __LINE__ . ": WARNING: ". $font_name . " could not be resolved into a readable font file. Check \"Image/Canvas/Fonts/fontmap.txt\" in your PEAR directory. This directory can be found by pear 'config-show | grep \"PEAR directory\"'. Falling back to default font without the possibility to adjust any font sizes"); + } + + if (($chart_type == 15) || ($chart_type == 17)) + // worldmap + { + $Font->setSize(8); + } + else + // all the other chart types + { + $Font->setSize(8); + } + $Graph->setFont($Font); } else + // safe_mode { - $Font->setSize(8); + $Font =& $Graph->addNew('Image_Graph_Font'); + $Font->setSize(8); // has no effect! + error_log(__FILE__ . ":" . __LINE__ . ": WARNING: safe_mode: Falling back to default font without the possibility to adjust any font sizes."); } - $Graph->setFont($Font); // Configure plotarea @@ -247,9 +426,9 @@ { $tmp = $xdata[$i][0]; $tmp_lower = strtolower($tmp); - if ($debug_mode > 0) + if ($debug_mode > 1) { - error_log("### to be looked up: '$tmp', '$tmp_lower' ###"); + error_log("to be looked up: '$tmp', '$tmp_lower' ###"); } // special case '"I0" => "private network (rfc 1918)"' and |