Fonts
-----
-This directory contains fonts that are used when creating
-images with text.
+GD font operations need unicode capable font to do the server-side
+rendering of text. Default font lib/default.ttf (FreeSans Medium
+revision 1.76 from http://savannah.nongnu.org/projects/freefont/)
+is suitable for most languages.
-The only one used currently is default.ttf
+Unsupported languages may add special font
+lang/xx_utf8/fonts/default.ttf, it will be used for that language
+only.
-If a language doesn't have the font here then the one in
-/lang/en/fonts/default.ttf is used instead.
-
-Multibyte strings will need decoding, because the Truetype
-routines expect ISO fonts or Unicode strings. If there is a
-file here called lang_decode.php, containing a function
-called lang_decode(), then it will be used on each string.
+If you want to override the default font dirroot/lib/default.ttf,
+save another one as dataroot/lang/default.ttf - it will
+be used for all site languages without it's font file.
+The list of suitable TrueType fonts can be found at:
+* http://en.wikipedia.org/wiki/Unicode_fonts
+* http://www.alanwood.net/unicode/fonts.html#general
-<?php
+<?php // $Id$
/*
Graph Class. PHP Class to draw line, point, bar, and area graphs, including numeric x-axis and double y-axis.
global $CFG;
/// A default.ttf is searched for in this order:
+ /// dataroot/lang/xx_local/fonts
/// dataroot/lang/xx/fonts
/// dirroot/lang/xx/fonts
+ /// dataroot/lang
/// lib/
$currlang = current_language();
- if (file_exists("$CFG->dataroot/lang/$currlang/fonts/default.ttf")) {
+ if (file_exists("$CFG->dataroot/lang/".$currlang."_local/fonts/default.ttf")) {
+ $fontpath = "$CFG->dataroot/lang/".$currlang."_local/fonts/";
+ } else if (file_exists("$CFG->dataroot/lang/$currlang/fonts/default.ttf")) {
$fontpath = "$CFG->dataroot/lang/$currlang/fonts/";
} else if (file_exists("$CFG->dirroot/lang/$currlang/fonts/default.ttf")) {
$fontpath = "$CFG->dirroot/lang/$currlang/fonts/";
+ } else if (file_exists("$CFG->dataroot/lang/default.ttf")) {
+ $fontpath = "$CFG->dataroot/lang/";
} else {
$fontpath = "$CFG->libdir/";
}
$this->parameter['path_to_fonts'] = $fontpath;
- if (file_exists("$fontpath"."lang_decode.php")) {
- $this->parameter['lang_decode'] = "$fontpath"."lang_decode.php";
- } else {
- $this->parameter['lang_decode'] = "";
- }
-
- $this->parameter['lang_transcode'] = ''; /// by default
-
- $charset = strtolower(current_charset());
-
- if ($charset != 'iso-8859-1' and $charset != 'utf-8') {
- $this->parameter['lang_transcode'] = $charset;
- }
-
/// End Moodle mods
$x = 0;
break;
}
- if ($this->parameter['lang_decode']) { // Moodle addition
- include_once($this->parameter['lang_decode']);
- $text = lang_decode($text);
-
- } else if ($this->parameter['lang_transcode']) {
- $text = iconv($this->parameter['lang_transcode'], 'UTF-8', $text);
- }
+ // start of Moodle addition
+ $textlib = textlib_get_instance();
+ $text = $textlib->convert($text, current_charset(), 'UTF-8');
+ $text = $textlib->utf8_to_entities($text, true, true); //does not work with hex entities!
+ // end of Moodle addition
ImageTTFText($this->image, $points, $angle, $x, $y, $colour, $font, $text);
}
}
// get boundary box and offsets for printing at an angle
- if ($this->parameter['lang_decode']) { // Moodle addition
- include_once($this->parameter['lang_decode']);
- $text = lang_decode($text);
-
- } else if ($this->parameter['lang_transcode']) {
- $text = iconv($this->parameter['lang_transcode'], 'UTF-8', $text);
- }
+ // start of Moodle addition
+ $textlib = textlib_get_instance();
+ $text = $textlib->convert($text, current_charset(), 'UTF-8');
+ $text = $textlib->utf8_to_entities($text, true, true); //gd does not work with hex entities!
+ // end of Moodle addition
$bounds = ImageTTFBBox($points, $angle, $font, $text);
if ($angle < 0) {
return $encoded;
}
+
+ /**
+ * Converts all Unicode chars > 127 to numeric entities &#nnnn; or &#xnnn;.
+ *
+ * @param string input string
+ * @param boolean output decadic only number entities
+ * @param boolean remove all nonumeric entities
+ * @return string converted string
+ */
+ function utf8_to_entities($str, $dec=false, $nonnum=false) {
+ /// Avoid some notices from Typo3 code
+ $oldlevel = error_reporting(E_PARSE);
+ if ($nonnum) {
+ $str = $this->typo3cs->entities_to_utf8($str, true);
+ }
+ $result = $this->typo3cs->utf8_to_entities($str);
+ if ($dec) {
+ $result = preg_replace('/&#x([0-9a-f]+);/ie', "'&#'.hexdec('$1').';'", $result);
+ }
+ /// Restore original debug level
+ error_reporting($oldlevel);
+ return $result;
+ }
+
}
?>