Class Font
Defines a particular format for text, including font face, size, and style attributes. This class cannot be inherited.
Inherited Members
Namespace: SixLabors.Fonts
Assembly: SixLabors.Fonts.dll
Syntax
public sealed class Font
Constructors
| Edit this page View SourceFont(Font, FontStyle)
Initializes a new instance of the Font class.
Declaration
public Font(Font prototype, FontStyle style)
Parameters
| Type | Name | Description |
|---|---|---|
| Font | prototype | The prototype. |
| FontStyle | style | The font style. |
Font(Font, float)
Initializes a new instance of the Font class.
Declaration
public Font(Font prototype, float size)
Parameters
| Type | Name | Description |
|---|---|---|
| Font | prototype | The prototype. |
| float | size | The size of the font in PT units. |
Font(Font, float, FontStyle)
Initializes a new instance of the Font class.
Declaration
public Font(Font prototype, float size, FontStyle style)
Parameters
| Type | Name | Description |
|---|---|---|
| Font | prototype | The prototype. |
| float | size | The size of the font in PT units. |
| FontStyle | style | The font style. |
Font(FontFamily, float)
Initializes a new instance of the Font class.
Declaration
public Font(FontFamily family, float size)
Parameters
| Type | Name | Description |
|---|---|---|
| FontFamily | family | The font family. |
| float | size | The size of the font in PT units. |
Font(FontFamily, float, FontStyle)
Initializes a new instance of the Font class.
Declaration
public Font(FontFamily family, float size, FontStyle style)
Parameters
| Type | Name | Description |
|---|---|---|
| FontFamily | family | The font family. |
| float | size | The size of the font in PT units. |
| FontStyle | style | The font style. |
Properties
| Edit this page View SourceFamily
Gets the family.
Declaration
public FontFamily Family { get; }
Property Value
| Type | Description |
|---|---|
| FontFamily |
FontMetrics
Gets the font metrics.
Declaration
public FontMetrics FontMetrics { get; }
Property Value
| Type | Description |
|---|---|
| FontMetrics |
Exceptions
| Type | Condition |
|---|---|
| FontException | Font instance not found. |
IsBold
Gets a value indicating whether this Font is bold.
Declaration
public bool IsBold { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsItalic
Gets a value indicating whether this Font is italic.
Declaration
public bool IsItalic { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Name
Gets the name.
Declaration
public string Name { get; }
Property Value
| Type | Description |
|---|---|
| string |
Size
Gets the size of the font in PT units.
Declaration
public float Size { get; }
Property Value
| Type | Description |
|---|---|
| float |
Methods
| Edit this page View SourceTryGetGlyphs(CodePoint, ColorFontSupport, out IReadOnlyList<Glyph>?)
Gets the glyphs for the given codepoint.
Declaration
public bool TryGetGlyphs(CodePoint codePoint, ColorFontSupport support, out IReadOnlyList<Glyph>? glyphs)
Parameters
| Type | Name | Description |
|---|---|---|
| CodePoint | codePoint | The code point of the character. |
| ColorFontSupport | support | Options for enabling color font support during layout and rendering. |
| IReadOnlyList<Glyph> | glyphs | When this method returns, contains the glyphs for the given codepoint and color support if the glyphs are found; otherwise the default value. This parameter is passed uninitialized. |
Returns
| Type | Description |
|---|---|
| bool | true if the face contains glyphs for the specified codepoint; otherwise, false. |
TryGetGlyphs(CodePoint, TextAttributes, ColorFontSupport, out IReadOnlyList<Glyph>?)
Gets the glyphs for the given codepoint.
Declaration
public bool TryGetGlyphs(CodePoint codePoint, TextAttributes textAttributes, ColorFontSupport support, out IReadOnlyList<Glyph>? glyphs)
Parameters
| Type | Name | Description |
|---|---|---|
| CodePoint | codePoint | The code point of the character. |
| TextAttributes | textAttributes | The text attributes to apply to the glyphs. |
| ColorFontSupport | support | Options for enabling color font support during layout and rendering. |
| IReadOnlyList<Glyph> | glyphs | When this method returns, contains the glyphs for the given codepoint, attributes, and color support if the glyphs are found; otherwise the default value. This parameter is passed uninitialized. |
Returns
| Type | Description |
|---|---|
| bool | true if the face contains glyphs for the specified codepoint; otherwise, false. |
TryGetGlyphs(CodePoint, TextAttributes, LayoutMode, ColorFontSupport, out IReadOnlyList<Glyph>?)
Gets the glyphs for the given codepoint.
Declaration
public bool TryGetGlyphs(CodePoint codePoint, TextAttributes textAttributes, LayoutMode layoutMode, ColorFontSupport support, out IReadOnlyList<Glyph>? glyphs)
Parameters
| Type | Name | Description |
|---|---|---|
| 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. |
| ColorFontSupport | support | Options for enabling color font support during layout and rendering. |
| IReadOnlyList<Glyph> | glyphs | When this method returns, contains the glyphs for the given codepoint, attributes, and color support if the glyphs are found; otherwise the default value. This parameter is passed uninitialized. |
Returns
| Type | Description |
|---|---|
| bool | true if the face contains glyphs for the specified codepoint; otherwise, false. |
TryGetGlyphs(CodePoint, TextAttributes, TextDecorations, LayoutMode, ColorFontSupport, out IReadOnlyList<Glyph>?)
Gets the glyphs for the given codepoint.
Declaration
public bool TryGetGlyphs(CodePoint codePoint, TextAttributes textAttributes, TextDecorations textDecorations, LayoutMode layoutMode, ColorFontSupport support, out IReadOnlyList<Glyph>? glyphs)
Parameters
| Type | Name | Description |
|---|---|---|
| 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. |
| ColorFontSupport | support | Options for enabling color font support during layout and rendering. |
| IReadOnlyList<Glyph> | glyphs | When this method returns, contains the glyphs for the given codepoint, attributes, and color support if the glyphs are found; otherwise the default value. This parameter is passed uninitialized. |
Returns
| Type | Description |
|---|---|
| bool | true if the face contains glyphs for the specified codepoint; otherwise, false. |
TryGetGlyphs(CodePoint, out IReadOnlyList<Glyph>?)
Gets the glyphs for the given codepoint.
Declaration
public bool TryGetGlyphs(CodePoint codePoint, out IReadOnlyList<Glyph>? glyphs)
Parameters
| Type | Name | Description |
|---|---|---|
| CodePoint | codePoint | The code point of the character. |
| IReadOnlyList<Glyph> | glyphs | When this method returns, contains the glyphs for the given codepoint if the glyphs are found; otherwise the default value. This parameter is passed uninitialized. |
Returns
| Type | Description |
|---|---|
| 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.
Declaration
public bool TryGetKerningOffset(Glyph current, Glyph next, float dpi, out Vector2 vector)
Parameters
| Type | Name | Description |
|---|---|---|
| Glyph | current | The current glyph. |
| Glyph | next | The next glyph. |
| float | dpi | The DPI (Dots Per Inch) to render/measure the kerning offset at. |
| Vector2 | vector | When this method returns, contains the offset, in font units, that should be applied to the
|
Returns
| Type | Description |
|---|---|
| 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.
Declaration
public bool TryGetPath(out string? path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | 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
| Type | Description |
|---|---|
| bool | true if the Font was created via a filesystem path; otherwise, false. |