OperatingSystemFont

Represents a font loaded off the operating system or the X server.

More...

Constructors

this
this(string name, int size, FontWeight weight, bool italic)

Constructs the class and immediately calls load.

this
this()

Constructs the object, but does nothing. Call one of load or loadDefault to populate the object.

Destructor

A destructor is present on this object, but not explicitly documented in the source.

Members

Functions

ascent
int ascent()

Max ascent above the baseline.

averageWidth
int averageWidth()

Returns the average width of the font, conventionally defined as the width of the lowercase 'x' character.

descent
int descent()

Max descent below the baseline.

height
int height()

Returns the height of the font.

isMonospace
bool isMonospace()
isNull
bool isNull()
load
bool load(string name, int size, FontWeight weight, bool italic)

name is a font name, but it can also be a more complicated string parsed in an OS-specific way.

loadCoreX
bool loadCoreX(string name, int size, FontWeight weight, bool italic)

Loads specifically a Core X font - rendered on the X server without antialiasing. Best performance.

loadDefault
OperatingSystemFont loadDefault()

Loads the default font used by ScreenPainter if none others are loaded.

loadWin32
bool loadWin32(string name, int size, FontWeight weight, bool italic, HDC hdc)

Loads a Windows font. You probably want to use load instead to be more generic.

loadXft
bool loadXft(string name, int size, FontWeight weight, bool italic)

Loads specifically with the Xft library - a freetype font from a fontconfig string.

prepareContext
void prepareContext(SimpleWindow window)
releaseContext
void releaseContext()

stringWidth can be slow. This helps speed it up if you are doing a lot of calculations. Just prepareContext when you start this work and releaseContext when you are done. Important to release before too long though as it can be a scarce system resource.

stringWidth
int stringWidth(const(char)[] s, SimpleWindow window)
int stringWidth(const(wchar)[] s, SimpleWindow window)

Returns the width of the string as drawn on the specified window, or the default screen if the window is null.

unload
void unload()

Static functions

listFonts
void listFonts(string pattern, bool delegate(in char[] name) handler)

Lists available fonts from the system that match the given pattern, finding names that are suitable for passing to OperatingSystemFont's constructor.

Detailed Description

While the api here is unified cross platform, the fonts are not necessarily available, even across machines of the same platform, so be sure to always check for null (using isNull) and have a fallback plan.

When you have a font you like, use ScreenPainter.setFont to load it for drawing.

Worst case, a null font will automatically fall back to the default font loaded for your system.

Suggestion Box / Bug Report