Table of Contents

Struct Font

Namespace
Xui.Core.Canvas
Assembly
Xui.Core.dll

Immutable description of one font face used for canvas text measurement and rendering.

public readonly struct Font : IEquatable<Font>
Implements
Inherited Members

Remarks

Xui currently selects one named family. Font fallback and per-run font selection are not supported by this value and must bypass font-metric caches when introduced in the future.

Constructors

Font()

Initializes the default Inter text font.

public Font()

Font(NFloat, string, FontWeight?, FontStyle?, FontStretch?, NFloat?)

Initializes a font face.

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

Parameters

fontSize NFloat
fontFamily string
fontWeight FontWeight?
fontStyle FontStyle?
fontStretch FontStretch?
lineHeight NFloat?

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

Italic

public static readonly FontStyle Italic

Field Value

FontStyle

Light

public static readonly FontWeight Light

Field Value

FontWeight

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

Properties

FontFamily

The one selected font family name.

public string FontFamily { get; init; }

Property Value

string

FontSize

The font size in user-space units.

public NFloat FontSize { get; init; }

Property Value

NFloat

FontStretch

The font stretch.

public FontStretch FontStretch { get; init; }

Property Value

FontStretch

FontStyle

The font style.

public FontStyle FontStyle { get; init; }

Property Value

FontStyle

FontWeight

The numeric font weight.

public FontWeight FontWeight { get; init; }

Property Value

FontWeight

LineHeight

The requested line height. Layout will own line-spacing semantics.

public NFloat LineHeight { get; init; }

Property Value

NFloat

Methods

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

Equals(Font)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(Font other)

Parameters

other Font

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

Operators

operator ==(Font, Font)

Returns whether two font descriptions are equal.

public static bool operator ==(Font left, Font right)

Parameters

left Font
right Font

Returns

bool

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

operator !=(Font, Font)

Returns whether two font descriptions differ.

public static bool operator !=(Font left, Font right)

Parameters

left Font
right Font

Returns

bool