Contents Previous Next

### 3.1.4 Using non-latin based fonts with JpGraph

In addition to European font it is also possible to use non-latin based fonts such as Cyrillic, Japanese and Chinese.

In all cases a suitable TTF font that supports the non-latin based language must be available.

For Cyrillic support the define LANGUAGE_CYRILLIC in jpg-config.php must be set to true. It is then possible to use a suitable Cyrillic font as replacement for the ordinary fonts.

For Chinese character set JpGraph supports both BIG5 and GB2312 encoding. For BIG5 encoding the PHP installation must have support for the "iconv()" function. Furthermore the define CHINESE_TTF_FONT must be set to the name of the Chinese BIG5 font that is to be used. By default this is set to "bkai00mp.ttf". To use the Chinese BIG5 font in the scripts one must then specify the font family as FF_CHINESE.

To use the alternative font files "simsun.ttc" and "simhei.ttf" (which uses the GB2312 encoding) the only step needed is to install those fonts in the normal TTF font directory and then specify the font family as FF_SIMSUN, the "simhei.ttf" is used when the font style is specified as FS_BOLD.

#### 3.1.4.1 Japanese character support

Using Japanese fonts are supported by the pre-defined font families

- FF_MINCHO
- FF_PMINCHO
- FF_GOTHIC
- FF_PGOTHIC

Please note that the actual font files is not included in the library. The exact name of the font files to use for these families are defined in the the configuration file "jpg-config.inc.php.php".

Some care must be taken due to the encoding that the library expects. The library TTF handling expects the fonts to be encoded in UTF8 encoding. Since the most commonly used Japanese encoding is EUC-JP some conversion must be done. The best way to do this is by using the mbstring extension to PHP to handle the encoding. By default this module is not included and to compile PHP with support for mbstring the option "--enable-mbstring" must be given when compiling PHP. Your installation of PHP might also provide mbstring as a PHP module that is loaded at runtime.

To convert from EUC-JP the function mb_convert_encoding() is used as the following example shows.

    $utf8-encoded-text = mb_convert_encoding($eucjp-encoded-txt, 'UTF-8','EUC-JP');

By enabling the define "ASSUME_EUCJP_ENCODING" (in jpg-config.inc.php.php) this encoding is done automatically in the library when one of the Japanese fonts have been enabled. By default this automatic conversion is disabled.

If this define is false then it is up to the client to make sure that the proper utf8 encoded text is passed on to all the methods that are use to specify text in the library given that one of the Japanese fonts have been selected.

A different method also exists when it comes to Japanese font support. By compiling PHP with the option "--enable-gd-jis-conv" this will automatically convert Japanese characters to UTF8 when using the FreeType libraries. However the method with the mbstring module is preferred since the automatic conversion might on occasion fail to detect the proper encoding.

Contents Previous Next