View on GitHub

DSFML

dsfml.graphics.font



class Font;
Class for loading and manipulating character fonts.

Fonts can be loaded from a file, from memory or from a custom stream, and supports the most common types of fonts.

See the loadFromFile function for the complete list of supported formats.

Once it is loaded, a Font instance provides three types of information about the font: - Global metrics, such as the line spacing - Per-glyph metrics, such as bounding box or kerning - Pixel representation of glyphs

Authors:
Laurent Gomila, Jeremy DeHaan

See Also:


http:
//sfml-dev.org/documentation/2.0/classsf_1_1Font.php#details

this();
Defines an empty font

bool loadFromFile(string filename);
Load the font from a file.

The supported font formats are: TrueType, Type 1, CFF, OpenType, SFNT, X11 PCF, Windows FNT, BDF, PFR and Type 42. Note that this function know nothing about the standard fonts installed on the user's system, thus you can't load them directly.

Params:
string filename Path of the font file to load

Returns:
True if loading succeeded, false if it failed.

bool loadFromMemory(const(void)[] data);
Load the font from a file in memory.

The supported font formats are: TrueType, Type 1, CFF, OpenType, SFNT, X11 PCF, Windows FNT, BDF, PFR and Type 42. Warning: SFML cannot preload all the font data in this function, so the buffer pointed by data has to remain valid as long as the font is used.

Params:
const(void)[] data data holding the font file

Returns:
True if loading succeeded, false if it failed.

bool loadFromStream(InputStream stream);
Load the font from a custom stream.

The supported font formats are: TrueType, Type 1, CFF, OpenType, SFNT, X11 PCF, Windows FNT, BDF, PFR and Type 42. Warning: SFML cannot preload all the font data in this function, so the contents of stream have to remain valid as long as the font is used.

Params:
InputStream stream Source stream to read from

Returns:
True if loading succeeded, false if it failed.

const Glyph getGlyph(dchar codePoint, uint characterSize, bool bold);
Retrieve a glyph of the font.

Params:
dchar codePoint Unicode code point of the character ot get
uint characterSize Reference character size
bols Retrieve the bold version or the regular one?

Returns:
The glyph corresponding to codePoint and characterSize

const int getKerning(dchar first, dchar second, uint characterSize);
Get the kerning offset of two glyphs.

The kerning is an extra offset (negative) to apply between two glyphs when rendering them, to make the pair look more "natural". For example, the pair "AV" have a special kerning to make them closer than other characters. Most of the glyphs pairs have a kerning offset of zero, though.

Params:
dchar first Unicode code point of the first character
dchar second Unicode code point of the second character
uint characterSize Reference character size

Returns:
Kerning value for first and second, in pixels

const int getLineSpacing(uint characterSize);
Get the line spacing.

The spacing is the vertical offset to apply between consecutive lines of text.

Params:
uint characterSize Reference character size

Returns:
Line spacing, in pixels

const const(Texture) getTexture(uint characterSize);
Retrieve the texture containing the loaded glyphs of a certain size.

The contents of the returned texture changes as more glyphs are requested, thus it is not very relevant. It is mainly used internally by Text.

Params:
uint characterSize Reference character size

Returns:
Texture containing the glyphs of the requested size

const @property Font dup();
Performs a deep copy on the font.

Returns:
The duplicated font.