[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 4.12.1 Using a Custom Font

This section describes how to use a custom font within Crystal Space.

Crystal Space has a plugin that specifies the font server to use. The font server that almost all applications use is the font multiplexer, together with the FreeType2 and the default font server. The SCF class names of these modules are:

- `crystalspace.font.server.multiplexer`
- `crystalspace.font.server.freetype2`
- `crystalspace.font.server.default`

The font multiplexer not only searches both the FreeType2 and default font server for a font, but also can search multiple fonts for a glyph. This is especially important if you plan to internationalize your applications; it reduces the worry that a particular font supports the glyphs for a specific language. (Crystal Space ships with the GNU Unifont, which is used as a fallback, so it already has pretty good support for internationalization out-of-the-box.)

#### Standard Fonts

Every font server is expected to return a font given the following strings:

- `CSFONT_LARGE "*large"`
- `CSFONT_ITALIC "*italic"`
- `CSFONT_COURIER "*courier"`
- `CSFONT_SMALL "*small"`

The default font server has these 4 fonts built in. They are as follows:

- `CSFONT_LARGE police`
- `CSFONT_ITALIC italic`
- `CSFONT_COURIER courier`
- `CSFONT_SMALL tiny`

To use these fonts simply use the LoadFont method and pass the font desired.

    Font = G2D->GetFontServer()->LoadFont (CSFONT_LARGE);

#### Loadable Fonts

The font plexer will also look for a file in the virtual file system with the name specified. The font can be a TrueType font or in the custom CSF format.

To specify an alternate font simply use the LoadFont method with the file name (and optionally a size) such as:

    Font = G2D->GetFontServer()->LoadFont ("/fonts/ttf/Vera.ttf", 12);

The CSF format is a pretty simple binary format for non-scalable fonts that supports individual characters with different widths and optionally an alpha component to provide anti-aliasing.

However, using a TrueType font is usually more flexible and results in a higher quality than a CSF font.

#### Creating CSF Fonts

The easiest way to is to use the ``csfgen'` util that comes with CS. It converts a True Type font to the CSF format.

Once the CSF file is created it can be included in the application no matter what platforms are targeted. The base font does not have to be on that system. This is useful if you do not want or can not distribute a font with your program and can not rely upon it already being present on the target machine.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ]

This document was generated using texi2html 1.76.