Font families and font styles
| Chapter 8. Text and font handling |

## Font families and font styles

### Default TrueType Font

Prior to ver. 3.5, bitmap fonts are used by default which can specified from `FF_FONT0` to `FF_FONT2`. From version 3.5, default fonts are now set to one of the open-source TrueType DejaVu font (`FF_DV_SANSSERIF`, DejaVuSans.ttf). This TrueType font is included in JpGraph source code (src/fonts), and there is no need to specify font for this one.

You can change default font family by changing `FF_DEFAULT` defined in `jpgraph_ttf.inc.php`. You have to prepare your own font file as well in order to use another font.

If Freetype library is not usable in your PHP configuration, original BITMAP font will be used for compatibility.

All graph objects that uses text allows you to specify the font to be used by calling a `SetFont()` method and specifying three parameters.

1. The font family. This could for example be "Arial", "Times roman" for TTF fonts or "Bitmap font medium size" when using bit-mapped fonts. The font family is specified by using a symbolic constant that starts with the prefix "`FF_`" (for Font Family). A list of all supported font families are shown in Table 8.2. Supported Latin Font family specifiers.

2. The font style. This specifies if the font should be emphasized as italic, bold, or bold-italic. By default all fonts are rendered with the "normal" style. The fonts style is specified with a symbolic constant that starts with the prefix "`FS_`" (for Font Style). The supported font styles are:

   Table 8.1. Supported Font Styles

   Font style specifier | Description
   --- | ---
   FS_NORMAL | Normal font style
   FS_BOLD | Bold font style
   FS_ITALIC | Italic font style
   FS_BOLDITALIC | Bold + Italic style for font families that support this

   Please note that not all font families support all available styles.

3. The font size. This is specified as an integer and depicts the size of the font given in typographic points (pt).

Table 8.2. Supported Latin Font family specifiers

Font family name | Type | Comment | Bold | Italic | BI
--- | --- | --- | --- | --- | ---
FF_FONT0 | Bitmap | A very small font |  |  |
FF_FONT1 | Bitmap | A medium sized font |  |  |
FF_FONT2 | Bitmap | The largest bit mapped font |  |  |
FF_ARIAL | TTF | Arial font |  |  |
FF_VERDANA | TTF | Verdana font |  |  |
FF_COURIER | TTF | Fixed pitched Courier new font |  |  |
FF_BOOK | TTF | Bookman |  |  |
FF_COMIC | TTF | Comic sans |  |  |
FF_TIMES | TTF | Times New Roman |  |  |
FF_GEORGIA | TTF | Georgia |  |  |
FF_TREBUCHE | TTF | Trebuche |  |  |
FF_VERA | TTF | Gnome Vera font. All Vera family fonts are available from `http://www.gnome.org/fonts/` |  |  |
FF_VERAMONO | TTF | Gnome Vera Mono font |  |  |
FF_VERASERIF | TTF | Gnome Vera Serif font |  |  |
FF_DV_SANSSERIF | TTF | DejaVu Font family. The DejaVu fonts are modifications of the Bitstream Vera fonts designed to extend this original for greater coverage of Unicode, as well as providing more styles. These fonts are available from `http://dejavu-fonts.org/` |  |  |
FF_DV_SANSSERIFMONO | TTF | DejaVu Font family. |  |  |
FF_DV_SANSSERIFCOND | TTF | DejaVu Font family. |  |  |
FF_DV_SERIF | TTF | DejaVu Font family. |  |  |
FF_DV_SERIFCOND | TTF | DejaVu Font family. |  |  |
FF_CHINESE, FF_BIG5 | TTF | Chinese font (both symbolic names can be used). The actual font file name used for the Chinese font is "`bkai00mp.ttf`". The name of this file can be changed in the define `CHINESE_TTF_FONT` available in the library file `jpgraph_ttf.inc.php` |  |  |
FF_SIMSUN | TTF | Chinese font. The actual font file name is "`simsun.ttc`" |  |  |
FF_MINCHO | TTF | Japanese font. The actual font file name is "`ipam.ttf`" |  |  |
FF_PMINCHO | TTF | Japanese font. The actual font file name is "`ipamp.ttf`" |  |  |
FF_GOTHIC | TTF | Japanese font. The actual font file name is "`ipag.ttf`" |  |  |
FF_PGOTHIC | TTF | Japanese font. The actual font file name is "`ipagp.ttf`" |  |  |
FF_DAVID | TTF | Hebrew font. The actual font file name is "`DAVIDNEW.TTF`" |  |  |
FF_MIRIAM | TTF | Hebrew font. The actual font file name is "`MRIAMY.TTF`" |  |  |
FF_AHRON | TTF | Hebrew font. The actual font file name is "`ahronbd.ttf`" |  |  |

### Note

Depending on what versions of the DejaVu fonts are installed on the system there are two naming conventions for the font files in common practice. The library will try both naming convention to see if it can find the font files.

In Figure 8.1. List of all latin TTF fonts. `(`listfontsex1.php`)` all latin fonts are shown.

Figure 8.1. List of all latin TTF fonts. `(`listfontsex1.php`)`

| Up |
| Home |