In many of the example you can see examples of both TrueType and BitMap fonts.
There are a number of subtle differences in the way builtin fonts and TrueType fonts are rendered to the screen. However, JpGraph, abstracts away 99.9% of the differences so it will be, for the user, completely transparent to switch between the different fonts.
DEFINE("TTF_DIR","/usr/local/fonts/ttf/");
Since JpGraph must be able to tell the difference between the italic and bold versions of the same font family a standard naming convention is used to name the files. The available fonts are also defined by DEFINES and hence you can't just copy your own TTF files to the directory and expect it to work. At the moment there is no "easy" way to add new fonts but to make some (small) mods to the code. However this is expected to change in future version of JpGraph.
DEFINE("TTF_DIR","/usr/X11R6/lib/X11/fonts/truetype/");
$im = imagecreatetruecolor (400, 100);
$black = imagecolorallocate ($im, 0, 0, 0);
$white = imagecolorallocate ($im, 255, 255, 255);
imagerectangle($im,0,0,399,99,$black);
imagefilledrectangle($im,0,0,399,99,$white);
imagettftext ($im, 30, 0, 10, 40, $black, TTF_DIR."arial.ttf",
"Hello World!");
header ("Content-type: image/png");
imagepng ($im);
The above script assumes you have the GD2 library and will create an image with the classical "Hello World!" text printed in black.
Font family | Type | Note |
FF_FONT0 | Builtin font | A very small font, only one style |
FF_FONT1 | Builtin font | A medium sized font |
FF_FONT2 | Builtin font | The largest bit mapped font |
FF_ARIAL | TTF font | Arial font |
FF_VERDANA | TTF font | Verdana font |
FF_COURIER | TTF font | Fix pitched courier |
FF_BOOK | TTF font | Bookman |
FF_COMIC | TTF font | Comic sans |
FF_TIMES | TTF font | Times New Roman |
FF_GEORGIA | TTF font | Georgia |
FF_TREBUCHE | TTF font | Trebuche |
FF_VERA | TTF font | Gnome Vera font, Available from http://www.gnome.org/fonts/ |
FF_VERAMONO | TTF font | Gnome Vera Mono font, Available from http://www.gnome.org/fonts/ | FF_VERASERIF | TTF font | Gnome Vera Serif font, Available from http://www.gnome.org/fonts/ |
FF_CHINESE | TTF font | Installed chinese font |
FF_SIMSUN | TTF font | Installed chinese font |
FF_BIG5 | TTF font | Installed chinese BIG5 font (needs iconv()) |
Please note that not all font families support all styles. The figure below illustrates each of the available font families and what styles you may use.
We finally show some example of valid font specifications
$graph->title->SetFont(FF_FONT2);
$graph->title->SetFont(FF_FONT2,FS_BOLD);
$graph->title->SetFont(FF_ARIAL);
$graph->title->SetFont(FF_ARIAL,FS_BOLD,24);
In order to add you favorite fonts there are three steps you need to follow :
Text is added to a graph with the creation of a Text() object. And the alignment is specified with Text::Align() Text alignment might actually be a misguiding name. What you specify is rather the anchor point for the text, i.e. when you specify that a text should be positioned at position (x,y) how is that coordinate to be interpretated.
The image below shows a text string aligned in the 9 possible combinations. In the image the red crosses indicate what coordinate that text string was positioned at. The alignment used for each of the cases is shown below.