SetFont — Select which font to use for a plot element
$plot->SetFont($elem
,$font
,$size
)
SetFont
selects the font and size to use for one plot
element (for example, the title). This functions works differently depending
on whether or not you are using TrueType fonts. If using TrueType fonts,
call either SetDefaultTTFont or SetUseTTF
before calling SetFont.
$elem
The name of the element to change the font for. Use one of the following strings: 'title', 'legend', 'generic', 'x_label', 'y_label', 'x_title', or 'y_title'. (The 'generic' font is currently used for pie chart percentage labels and error message images.)
$font
Selects the font to use. For TrueType fonts, this is the filename (without path, if the font file is in the default TrueType font directory as set with SetTTFPath, or a full pathname) of the TrueType font file. An empty string or NULL can be used to keep the same TrueType font and change the size. For built-in GD fonts, this is a number between 1 and 5 which selects one of the built-in GD fonts. Font 1 is the smallest, and font 5 is the largest.
$size
The font size in points for TrueType fonts. Ignored for built-in GD fonts. See note below.
When using built-in GD fonts, the default fonts are shown in the following table, where font 1 is the smallest font and font 5 is the biggest font.
Element | Default Built-in Font |
---|---|
generic | 2 |
legend | 2 |
title | 5 |
x_label | 1 |
y_label | 1 |
x_title | 3 |
y_title | 3 |
When using TrueType fonts, the default font sizes are shown in the following table. Use SetDefaultTTFont to set the default TrueType font.
Element | Default TrueType Font Size (points) |
---|---|
generic | 8 |
legend | 8 |
title | 14 |
x_label | 6 |
y_label | 6 |
x_title | 10 |
y_title | 10 |
Starting at PHPlot-5.0rc3, the behavior of this function changed when used with TrueType fonts. It now first tries to find the font using the supplied name. If the font is not found that way, it tries again prefixed with the default TrueType font directory as set with SetTTFPath.
Although PHP documents the TrueType font sizes as being given in points (where there are about 72 points per inch), it doesn't know the output device resolution, so it just assumes a fixed resolution of 72 pixels per inch. As a result, the TrueType font size argument actually measures the approximate font height in pixels. For example, if you use $size=18, the text will be about 18 pixels high in the user's browser. The actual size seen by the user will depend on the resolution of the user's display. On a 72 pixels per inch display, the text size will be 18 points, but at 96 pixels per inch it would only be 13.5 points.