Inserting Unicode entities
| Chapter 8. Text and font handling |

## Inserting Unicode entities

One reason for using TTF fonts is the possibility to inserting unicode character/entities. With this we mean characters from the extended range that are not normally available on West european keyboards. This could for example be classical Greek characters often used in mathematics, for example the symbol for "pi". In order to make these and other commonly used "special" characters more accessible the library provides a utility class that makes it easy to use these characters without having to look up the corresponding unicode entities every time.

In order to specify characters not available on the keyboard the normal way is to specify there unicode code and included it in the text string with the prefix "&#". For example the unicode for the character "pi" is "03C0" in hex so to include this character in a text string you would have to write "This is pi &#0960;" note that the code should be given in decimal encoding in the string and always use 4 digits (pre-padded with 0:s as necessary). Since it is very tedious to lookup and encode special characters the library offers a simpler way. The `SymChar` class.

### Note

This section can be skipped at first reading without loss of continuity.

### The utility class "SymChar"

As described above it is tedious to have to lookup all the character codes. To simplify this the SymChar class allows you to find these characters with the english common name of these symbols instead. For example to create a string with the Greek character "pi" one would have to write the code as shown in.

Example 8.2. Using the SymChar class to display the Greek letter "pi"

    1
    2
    3
    4
    5
    6
    <?php
    // ...
    $pi = SymChar::Get('pi');
    $graph->title->Set('Test is pi'.$pi);
    // ...
    ?>

All supported entities with there symbolic names are listed in Table 8.3. Supported character entities in class SymChar. The first argument to the static method `SymChar::Get()` should be the name of the entity and if the second optional argument is true then the capital version (if it exists) of the symbol should be returned.

Table 8.3. Supported character entities in class SymChar

Name | Unicode | Unicode capital | Comment
--- | --- | --- | ---
"alpha" | 03B1 | 0391 | Greek character
"beta" | 03B2 | 0392 | Greek character
"gamma" | 03B3 | 0393 | Greek character
"delta" | 03B4 | 0394 | Greek character
"epsilon" | 03B5 | 0395 | Greek character
"zeta" | 03B6 | 0396 | Greek character
"ny" | 03B7 | 0397 | Greek character
"eta" | 03B8 | 0398 | Greek character
"theta" | 03B8 | 0398 | Greek character
"iota" | 03B9 | 0399 | Greek character
"kappa" | 03BA | 039A | Greek character
"lambda" | 03BB | 039B | Greek character
"mu" | 03BC | 039C | Greek character
"nu" | 03BD | 039D | Greek character
"xi" | 03BE | 039E | Greek character
"omicron" | 03BF | 039F | Greek character
"pi" | 03C0 | 03A0 | Greek character
"rho" | 03C1 | 03A1 | Greek character
"sigma" | 03C3 | 03A3 | Greek character
"tau" | 03C4 | 03A4 | Greek character
"upsilon" | 03C5 | 03A5 | Greek character
"phi" | 03C6 | 03A6 | Greek character
"chi" | 03C7 | 03A7 | Greek character
"psi" | 03C8 | 03A8 | Greek character
"omega" | 03C9 | 03A9 | Greek character
"euro" | 20AC |  | Monetary symbol
"yen" | 00A5 |  | Monetary symbol
"pound" | 20A4 |  | Monetary symbol
"approx" | 2248 |  | Mathematical
"neq" | 2260 |  | Mathematical
"not" | 2310 |  | Mathematical
"def" | 2261 |  | Mathematical
"inf" | 221E |  | Mathematical
"sqrt" | 221A |  | Mathematical
"int" | 222B |  | Mathematical
"copy" | 00A9 |  | Misc symbols
"para" | 00A7 |  | Misc symbols
"tm" | 2122 |  | Misc symbols
"rtm" | 00AE |  | Misc symbols

Figure 8.6. Rendered symbol characters corresponding to and Figure 8.7. Rendered capital symbol characters corresponding to Table 8.3. Supported character entities in class SymChar. shows how these symbol look when they are rendered with the TTF font Times Roman 14pt. The symbols are in the same order as in the table above and are visually grouped by there category as specified in the column "Comment" in the table above.

Figure 8.6. Rendered symbol characters corresponding to

Figure 8.7. Rendered capital symbol characters corresponding to Table 8.3. Supported character entities in class SymChar.

### Graph example with Greek labels

In Figure 8.8. Specifying manual ticks as fraction of Pi. `(`manualtickex2.php`)` we have used the previous discussed `SymChar` class to more readily insert "π" characters in the X-axis label. We highlight some functionality that we haven't yet discussed in detail

1. We use a utility class (`FuncGenerator` available in "`jpgraph_utils.inc.php`") to help create plot values from a mathematical expression. This will help create a set of (x,y) points that can later on be used as the base for a data series.

2. The x-axis labels and the position of the tick marks on the x-axis are manually positioned and specified to be positioned at "even" fractions of π.

Figure 8.8. Specifying manual ticks as fraction of Pi. `(`manualtickex2.php`)`

| Up |
| Home |