Table of Contents

Class Font

Namespace
SixLabors.Fonts
Assembly
SixLabors.Fonts.dll

Defines a particular format for text, including font face, size, and style attributes. This class cannot be inherited.

public sealed class Font
Inheritance
Font
Inherited Members

Constructors

Font(Font, FontStyle)

Initializes a new instance of the Font class.

public Font(Font prototype, FontStyle style)

Parameters

prototype Font

The prototype.

style FontStyle

The font style.

Font(Font, params FontVariation[])

Initializes a new instance of the Font class with the specified variation axis settings.

public Font(Font prototype, params FontVariation[] variations)

Parameters

prototype Font

The prototype font providing family, size, and style.

variations FontVariation[]

The variation axis settings to apply.

Font(Font, float)

Initializes a new instance of the Font class.

public Font(Font prototype, float size)

Parameters

prototype Font

The prototype.

size float

The size of the font in PT units.

Font(Font, float, FontStyle)

Initializes a new instance of the Font class.

public Font(Font prototype, float size, FontStyle style)

Parameters

prototype Font

The prototype.

size float

The size of the font in PT units.

style FontStyle

The font style.

Font(FontFamily, float)

Initializes a new instance of the Font class.

public Font(FontFamily family, float size)

Parameters

family FontFamily

The font family.

size float

The size of the font in PT units.

Font(FontFamily, float, FontStyle)

Initializes a new instance of the Font class.

public Font(FontFamily family, float size, FontStyle style)

Parameters

family FontFamily

The font family.

size float

The size of the font in PT units.

style FontStyle

The font style.

Properties

Family

Gets the family.

public FontFamily Family { get; }

Property Value

FontFamily

FontMetrics

Gets the font metrics.

public FontMetrics FontMetrics { get; }

Property Value

FontMetrics

Exceptions

FontException

Font instance not found.

IsBold

Gets a value indicating whether this Font is bold.

public bool IsBold { get; }

Property Value

bool

IsItalic

Gets a value indicating whether this Font is italic.

public bool IsItalic { get; }

Property Value

bool

Name

Gets the name.

public string Name { get; }

Property Value

string

Size

Gets the size of the font in PT units.

public float Size { get; }

Property Value

float

Variations

Gets the variation axis settings applied to this font.

public ReadOnlySpan<FontVariation> Variations { get; }

Property Value

ReadOnlySpan<FontVariation>

Methods

TryGetGlyph(CodePoint, TextAttributes, LayoutMode, ColorFontSupport, out Glyph?)

Gets the glyph for the given codepoint.

public bool TryGetGlyph(CodePoint codePoint, TextAttributes textAttributes, LayoutMode layoutMode, ColorFontSupport support, out Glyph? glyph)

Parameters

codePoint CodePoint

The code point of the character.

textAttributes TextAttributes

The text attributes to apply to the glyphs.

layoutMode LayoutMode

The layout mode to apply to the glyphs.

support ColorFontSupport

Options for enabling color font support during layout and rendering.

glyph Glyph?

When this method returns, contains the glyph for the given codepoint, attributes, and color support if the glyph is found; otherwise the default value. This parameter is passed uninitialized.

Returns

bool

true if the face contains glyphs for the specified codepoint; otherwise, false.

TryGetGlyph(CodePoint, TextAttributes, TextDecorations, LayoutMode, ColorFontSupport, out Glyph?)

Gets the glyph for the given codepoint.

public bool TryGetGlyph(CodePoint codePoint, TextAttributes textAttributes, TextDecorations textDecorations, LayoutMode layoutMode, ColorFontSupport support, out Glyph? glyph)

Parameters

codePoint CodePoint

The code point of the character.

textAttributes TextAttributes

The text attributes to apply to the glyphs.

textDecorations TextDecorations

The text decorations to apply to the glyphs.

layoutMode LayoutMode

The layout mode to apply to the glyphs.

support ColorFontSupport

Options for enabling color font support during layout and rendering.

glyph Glyph?

When this method returns, contains the glyph for the given codepoint, attributes, and color support if the glyph is found; otherwise the default value. This parameter is passed uninitialized.

Returns

bool

true if the face contains glyphs for the specified codepoint; otherwise, false.

TryGetGlyphs(CodePoint, ColorFontSupport, out Glyph?)

Gets the glyph for the given codepoint.

public bool TryGetGlyphs(CodePoint codePoint, ColorFontSupport support, out Glyph? glyph)

Parameters

codePoint CodePoint

The code point of the character.

support ColorFontSupport

Options for enabling color font support during layout and rendering.

glyph Glyph?

When this method returns, contains the glyphs for the given codepoint and color support if the glyph is found; otherwise the default value. This parameter is passed uninitialized.

Returns

bool

true if the face contains glyphs for the specified codepoint; otherwise, false.

TryGetGlyphs(CodePoint, TextAttributes, ColorFontSupport, out Glyph?)

Gets the glyph for the given codepoint.

public bool TryGetGlyphs(CodePoint codePoint, TextAttributes textAttributes, ColorFontSupport support, out Glyph? glyph)

Parameters

codePoint CodePoint

The code point of the character.

textAttributes TextAttributes

The text attributes to apply to the glyphs.

support ColorFontSupport

Options for enabling color font support during layout and rendering.

glyph Glyph?

When this method returns, contains the glyph for the given codepoint, attributes, and color support if the glyph is found; otherwise the default value. This parameter is passed uninitialized.

Returns

bool

true if the face contains glyphs for the specified codepoint; otherwise, false.

TryGetGlyphs(CodePoint, out Glyph?)

Gets the glyph for the given codepoint.

public bool TryGetGlyphs(CodePoint codePoint, out Glyph? glyph)

Parameters

codePoint CodePoint

The code point of the character.

glyph Glyph?

When this method returns, contains the glyph for the given codepoint if the glyph is found; otherwise the default value. This parameter is passed uninitialized.

Returns

bool

true if the face contains glyphs for the specified codepoint; otherwise, false.

TryGetKerningOffset(Glyph, Glyph, float, out Vector2)

Gets the amount, in px units, the current glyph should be offset if it is followed by the next glyph.

public bool TryGetKerningOffset(Glyph current, Glyph next, float dpi, out Vector2 vector)

Parameters

current Glyph

The current glyph.

next Glyph

The next glyph.

dpi float

The DPI (Dots Per Inch) to render/measure the kerning offset at.

vector Vector2

When this method returns, contains the offset, in font units, that should be applied to the current glyph, if the offset is found; otherwise the default vector value. This parameter is passed uninitialized.

Returns

bool

true if the face contains and offset for the glyph combination; otherwise, false.

TryGetPath(out string?)

Gets the filesystem path to the font family source.

public bool TryGetPath(out string? path)

Parameters

path string

When this method returns, contains the filesystem path to the font family source, if the path exists; otherwise, the default value for the type of the path parameter. This parameter is passed uninitialized.

Returns

bool

true if the Font was created via a filesystem path; otherwise, false.