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

4.13.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:

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:

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

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 ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated using texi2html 1.76.