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.

this
this(OperatingSystemFont font)

Constructs a copy of the given font 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.

getTtfBytes
ubyte[] getTtfBytes()

Returns the raw content of the ttf file, if possible. This allows you to use OperatingSystemFont to look up fonts that you then pass to things like arsd.ttf.OpenGlLimitedFont or arsd.nanovega.

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.

Inherited Members

From MeasurableFont

isMonospace
bool isMonospace()

Returns true if it is a monospace font, meaning each of the glyphs (at least the ascii characters) have matching width and no kerning, so you can determine the display width of some strings by simply multiplying the string width by averageWidth.

averageWidth
int averageWidth()

The average width of glyphs in the font, traditionally equal to the width of the lowercase x. Can be used to estimate bounding boxes, especially if the font isMonospace.

height
int height()

The height of the bounding box of a line.

ascent
int ascent()

The maximum ascent of a glyph above the baseline.

descent
int descent()

The maximum descent of a glyph below the baseline. For example, how low the g might go.

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

The display width of the given string, and if you provide a window, it will use it to make the pixel count on screen more accurate too, but this shouldn't generally be necessary.

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.

Meta