Module dcanvas.graphics.fonts

Base fonts access interface and common implementation.

Font - base class for fonts.

FontManager - base class for font managers - provides access to available fonts.

Actual implementation is:

dcanvas.graphics.ftfonts - FreeType based font manager.

dcanvas.platforms.windows.w32fonts - Win32 API based font manager.

To enable OpenGL support, build with version(USE_OPENGL);

See Also

dcanvas.graphics.drawbuf, DrawBuf, drawbuf, drawbuf.html

Synopsis

import dcanvas.graphics.fonts;

// find suitable font of size 25, normal, preferrable Arial, or, if not available, any SansSerif font
FontRef font = FontManager.instance.getFont(25, FontWeight.Normal, false, FontFamily.SansSerif, "Arial");

dstring sampleText = "Sample text to draw"d;
// measure text string width and height (one line)
Point sz = font.textSize(sampleText);
// draw red text at center of DrawBuf buf
font.drawText(buf, buf.width / 2 - sz.x/2, buf.height / 2 - sz.y / 2, sampleText, 0xFF0000);

Functions

NameDescription
getReplacementChar(code) find some suitable replacement for important characters missing in font
glyphDestroyCallback() get glyph destroy callback (to cleanup OpenGL caches)
glyphDestroyCallback(callback) Set glyph destroy callback (to cleanup OpenGL caches) This callback is used to tell OpenGL glyph cache that glyph is not more used - to let OpenGL glyph cache delete texture if all glyphs in it are no longer used.
nextGlyphId() ID generator for glyphs

Classes

NameDescription
Font Instance of font with specific size, weight, face, etc.
FontManager Access points to fonts.
glyph_gamma_table

Structs

NameDescription
CustomCharProps custom character properties - for char-by-char drawing of text string with different character color and style
FontFaceProps font face properties item
FontList font instance collection - utility class, for font manager implementations
GlyphCache Glyph image cache
SimpleTextFormatter helper to split text into several lines and draw it

Enums

NameDescription
FontFamily font families enum
FontWeight font weight constants (0..1000)
HintingMode Hinting mode (currently supported for FreeType only)

Manifest constants

NameTypeDescription
MAX_WIDTH_UNSPECIFIED constant for measureText maxWidth paramenter - to tell that all characters of text string should be measured.
UNICODE_HYPHEN
UNICODE_NB_HYPHEN
UNICODE_NO_BREAK_SPACE
UNICODE_SOFT_HYPHEN_CODE
UNICODE_ZERO_WIDTH_SPACE

Global variables

NameTypeDescription
_gamma256 glyph_gamma_table!(256)
_gamma65 glyph_gamma_table!(65)
DEF_MIN_ANTIALIASED_FONT_SIZE const(int) default min font size for antialiased fonts (e.g. if 16 is set, for 16+ sizes antialiasing will be used, for sizes <=15 - antialiasing will be off)

Aliases

NameTypeDescription
FontRef Ref!(dcanvas.graphics.fonts.Font)