Table of Contents

Struct Font

Namespace
Xui.Core.Canvas
Assembly
Core.dll

Describes a font used for text layout and rendering, similar to the CSS font model.

public ref struct Font
Inherited Members

Remarks

This type mirrors a simplified subset of CSS font properties as documented at: https://developer.mozilla.org/en-US/docs/Web/CSS/font

Key differences:

  • FontFamily refers to a single font name only. No fallback list or character substitution is provided.
  • FontSize and LineHeight are specified in user-space units (e.g., pixels or points).
  • Font weight is numeric and roughly corresponds to CSS values between 100–900.

Constructors

Font(NFloat, ReadOnlySpan<string>, FontWeight?, FontStyle?, FontStretch?, NFloat?)

Initializes a Font with specified size and optional styling attributes.

public Font(NFloat fontSize, ReadOnlySpan<string> fontFamily = default, FontWeight? fontWeight = null, FontStyle? fontStyle = null, FontStretch? fontStretch = null, NFloat? lineHeight = null)

Parameters

fontSize NFloat

The font size in user-space units (e.g., pixels).

fontFamily ReadOnlySpan<string>

The font family (optional; no fallback list).

fontWeight FontWeight?

The font weight (default: Normal).

fontStyle FontStyle?

The font style (default: Normal).

fontStretch FontStretch?

The font stretch (default: Normal).

lineHeight NFloat?

The line height (default: 1.2 × font size).

Fields

Black

public static readonly FontWeight Black

Field Value

FontWeight

Bold

public static readonly FontWeight Bold

Field Value

FontWeight

Condensed

public static readonly FontStretch Condensed

Field Value

FontStretch

Expanded

public static readonly FontStretch Expanded

Field Value

FontStretch

ExtraBold

public static readonly FontWeight ExtraBold

Field Value

FontWeight

ExtraCondensed

public static readonly FontStretch ExtraCondensed

Field Value

FontStretch

ExtraExpanded

public static readonly FontStretch ExtraExpanded

Field Value

FontStretch

ExtraLight

public static readonly FontWeight ExtraLight

Field Value

FontWeight

FontFamily

The primary font family name. No fallback fonts are supported.

public ReadOnlySpan<string> FontFamily

Field Value

ReadOnlySpan<string>

FontSize

The font size in user-space units.

public NFloat FontSize

Field Value

NFloat

FontStretch

The stretch or width of the font relative to its normal width (100%). Values correspond to common CSS/OpenType stretch percentages:

 50 - Ultra Condensed
 62.5 - Extra Condensed
 75 - Condensed
 87.5 - Semi Condensed
100 - Normal
112.5 - Semi Expanded
125 - Expanded
150 - Extra Expanded
200 - Ultra Expanded
public FontStretch FontStretch

Field Value

FontStretch

Remarks

Font stretch controls the horizontal expansion or compression of glyphs. A value of 100 indicates normal width. Values less than 100 indicate condensed fonts; values greater than 100 indicate expanded fonts.

FontStyle

The font style (normal, italic, oblique).

public FontStyle FontStyle

Field Value

FontStyle

FontWeight

The numeric weight of the font. Matches common web font weights:

100 - Thin
200 - Extra Light
300 - Light
400 - Normal
500 - Medium
600 - Semi Bold
700 - Bold
800 - Extra Bold
900 - Black
public FontWeight FontWeight

Field Value

FontWeight

Italic

public static readonly FontStyle Italic

Field Value

FontStyle

Light

public static readonly FontWeight Light

Field Value

FontWeight

LineHeight

The line height in user-space units. Controls vertical spacing between lines.

public NFloat LineHeight

Field Value

NFloat

Medium

public static readonly FontWeight Medium

Field Value

FontWeight

Oblique

public static readonly FontStyle Oblique

Field Value

FontStyle

SemiBold

public static readonly FontWeight SemiBold

Field Value

FontWeight

SemiCondensed

public static readonly FontStretch SemiCondensed

Field Value

FontStretch

SemiExpanded

public static readonly FontStretch SemiExpanded

Field Value

FontStretch

Thin

public static readonly FontWeight Thin

Field Value

FontWeight

UltraCondensed

public static readonly FontStretch UltraCondensed

Field Value

FontStretch

UltraExpanded

public static readonly FontStretch UltraExpanded

Field Value

FontStretch

Operators

implicit operator Font(float)

Implicitly creates a Font from a font size. Uses normal weight, normal style, normal stretch, and line height = 1.2× size.

public static implicit operator Font(float size)

Parameters

size float

The font size in user-space units (e.g., pixels).

Returns

Font

implicit operator Font((float size, float lineHeight))

Creates a Font from size and line height.

public static implicit operator Font((float size, float lineHeight) tuple)

Parameters

tuple (float size, float lineHeight)

Returns

Font

implicit operator Font((float size, FontStyle style, float lineHeight))

Creates a Font from size, style, and line height.

public static implicit operator Font((float size, FontStyle style, float lineHeight) tuple)

Parameters

tuple (float size, FontStyle style, float lineHeight)

Returns

Font

implicit operator Font((float size, FontStyle style, FontStretch stretch, float lineHeight))

Creates a Font from size, style, stretch, and line height.

public static implicit operator Font((float size, FontStyle style, FontStretch stretch, float lineHeight) tuple)

Parameters

tuple (float size, FontStyle style, FontStretch stretch, float lineHeight)

Returns

Font

implicit operator Font((float size, FontStyle style, FontStretch stretch))

Implicitly creates a Font from size, style, and stretch. Uses normal weight and line height = 1.2× size.

public static implicit operator Font((float size, FontStyle style, FontStretch stretch) tuple)

Parameters

tuple (float size, FontStyle style, FontStretch stretch)

The font size, style, and stretch percentage.

Returns

Font

implicit operator Font((float size, FontStyle style))

Implicitly creates a Font from a font size and style. Uses normal weight, normal stretch, and line height = 1.2× size.

public static implicit operator Font((float size, FontStyle style) tuple)

Parameters

tuple (float size, FontStyle style)

The font size and font style.

Returns

Font

implicit operator Font((float size, FontWeight weight, float lineHeight))

Creates a Font from size, weight, and line height.

public static implicit operator Font((float size, FontWeight weight, float lineHeight) tuple)

Parameters

tuple (float size, FontWeight weight, float lineHeight)

Returns

Font

implicit operator Font((float size, FontWeight weight, FontStretch stretch, float lineHeight))

Creates a Font from size, weight, stretch, and line height.

public static implicit operator Font((float size, FontWeight weight, FontStretch stretch, float lineHeight) tuple)

Parameters

tuple (float size, FontWeight weight, FontStretch stretch, float lineHeight)

Returns

Font

implicit operator Font((float size, FontWeight weight, FontStretch stretch))

Implicitly creates a Font from size, weight, and stretch. Uses normal style and line height = 1.2× size.

public static implicit operator Font((float size, FontWeight weight, FontStretch stretch) tuple)

Parameters

tuple (float size, FontWeight weight, FontStretch stretch)

The font size, weight, and stretch percentage.

Returns

Font

implicit operator Font((float size, FontWeight weight, FontStyle style, float lineHeight))

Creates a Font from size, weight, style, and line height.

public static implicit operator Font((float size, FontWeight weight, FontStyle style, float lineHeight) tuple)

Parameters

tuple (float size, FontWeight weight, FontStyle style, float lineHeight)

Returns

Font

implicit operator Font((float size, FontWeight weight, FontStyle style, FontStretch stretch, float lineHeight))

Creates a Font from size, weight, style, stretch, and line height.

public static implicit operator Font((float size, FontWeight weight, FontStyle style, FontStretch stretch, float lineHeight) tuple)

Parameters

tuple (float size, FontWeight weight, FontStyle style, FontStretch stretch, float lineHeight)

Returns

Font

implicit operator Font((float size, FontWeight weight, FontStyle style, FontStretch stretch))

Implicitly creates a Font from size, weight, style, and stretch. Uses line height = 1.2× size.

public static implicit operator Font((float size, FontWeight weight, FontStyle style, FontStretch stretch) tuple)

Parameters

tuple (float size, FontWeight weight, FontStyle style, FontStretch stretch)

The font size, weight, style, and stretch percentage.

Returns

Font

implicit operator Font((float size, FontWeight weight, FontStyle style))

Implicitly creates a Font from size, weight, and style. Uses normal stretch and line height = 1.2× size.

public static implicit operator Font((float size, FontWeight weight, FontStyle style) tuple)

Parameters

tuple (float size, FontWeight weight, FontStyle style)

The font size, weight, and style.

Returns

Font

implicit operator Font((float size, FontWeight weight))

Implicitly creates a Font from a font size and weight. Uses normal style, normal stretch, and line height = 1.2× size.

public static implicit operator Font((float size, FontWeight weight) tuple)

Parameters

tuple (float size, FontWeight weight)

The font size and font weight.

Returns

Font