video.font

Font class.

class FontException: object.Exception;

Exception thrown at font related errors.

struct Glyph;

Immutable font glyph structure.

Texture texture;

Texture handle of the glyph.

uint freetypeIndex;

Freetype glyph index.

Vector2s offset;

Offset from the pen to the bottom-left corner of glyph image.

short advance;

Pixels to advance the pen after drawing this glyph.

class Font;

Stores one font with one size (e.g. Inconsolata size 16 and 18 will be two Font objects).

this(FT_LibraryRec* freetypeLib, ubyte[] fontData, const(immutable(char)[]) name, const(uint) size, const(uint) fastGlyphs, const(bool) antialiasing);

Construct a font.

Parameters:
FT_LibraryRec* freetypeLib Handle to the freetype library used to work with fonts.
ubyte[] fontData Font data (loaded from a font file).
const(immutable(char)[]) name Name of the font.
const(uint) size Size of the font in points.
const(uint) fastGlyphs Number of glyphs to store in fast access array, from glyph 0. E.g. 128 means 0-127, i.e. ASCII.
const(bool) antialiasing Should the font be antialiased?
Throws:
FontException if the font could not be loaded.
const pure @property uint size();

Get size of the font in pixels.

const pure @property uint height();

Get height of the font in pixels (currently the same as size).

const pure @property string name();

Get name of the font.

const pure @property bool kerning();

Does the font support kerning?

pure @property FT_Face fontFace();

Get FreeType font face of the font.

void unloadTextures(VideoDriver driver);

Delete glyph textures.

Textures have to be reloaded before any further glyph rendering with the font.

Parameters:
VideoDriver driver Video driver to delete textures from.
void reloadTextures(VideoDriver driver);

Load glyph textures back to video driver.

Can only be used after textures were unloaded.

Parameters:
VideoDriver driver Video driver to load textures to.
Throws:
TextureException if the glyph textures could not be reloaded.
package uint textWidth(const string str, const bool useKerning);

Returns width of text as it would be drawn.

Parameters:
string str Text to measure.
bool useKerning Should kerning be used? Should only be true if the font supports kerning.
Returns:
Width of the text in pixels.
package const const(Glyph*) getGlyph(const dchar c);

Access glyph of a (UTF-32) character.

The glyph has to be loaded, otherwise a call to getGlyph() will result in undefined behavior.

Parameters:
dchar c Character to get glyph for.
Returns:
Pointer to glyph corresponding to the character.
package const bool hasGlyph(const dchar c);

Determines if the glyph of a character is loaded.

Parameters:
dchar c Character to check for.
Returns:
True if the glyph is loaded, false otherwise.
package void loadGlyph(VideoDriver driver, const dchar c);

Load glyph of a character.

Parameters:
VideoDriver driver Video driver to use for texture creation.
dchar c Character to load glyph for.
Throws:
TextureException if the glyph texture could not be created.