Struct Font
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
fontSizeNFloatfontFamilystringfontWeightFontWeight?fontStyleFontStyle?fontStretchFontStretch?lineHeightNFloat?
Fields
Black
public static readonly FontWeight Black
Field Value
Bold
public static readonly FontWeight Bold
Field Value
Condensed
public static readonly FontStretch Condensed
Field Value
Expanded
public static readonly FontStretch Expanded
Field Value
ExtraBold
public static readonly FontWeight ExtraBold
Field Value
ExtraCondensed
public static readonly FontStretch ExtraCondensed
Field Value
ExtraExpanded
public static readonly FontStretch ExtraExpanded
Field Value
ExtraLight
public static readonly FontWeight ExtraLight
Field Value
Italic
public static readonly FontStyle Italic
Field Value
Light
public static readonly FontWeight Light
Field Value
Medium
public static readonly FontWeight Medium
Field Value
Oblique
public static readonly FontStyle Oblique
Field Value
SemiBold
public static readonly FontWeight SemiBold
Field Value
SemiCondensed
public static readonly FontStretch SemiCondensed
Field Value
SemiExpanded
public static readonly FontStretch SemiExpanded
Field Value
Thin
public static readonly FontWeight Thin
Field Value
UltraCondensed
public static readonly FontStretch UltraCondensed
Field Value
UltraExpanded
public static readonly FontStretch UltraExpanded
Field Value
Properties
FontFamily
The one selected font family name.
public string FontFamily { get; init; }
Property Value
FontSize
The font size in user-space units.
public NFloat FontSize { get; init; }
Property Value
FontStretch
The font stretch.
public FontStretch FontStretch { get; init; }
Property Value
FontStyle
The font style.
public FontStyle FontStyle { get; init; }
Property Value
FontWeight
The numeric font weight.
public FontWeight FontWeight { get; init; }
Property Value
LineHeight
The requested line height. Layout will own line-spacing semantics.
public NFloat LineHeight { get; init; }
Property Value
Methods
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand 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
otherFontAn object to compare with this object.
Returns
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
Returns
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
sizefloatThe font size in user-space units (e.g., pixels).
Returns
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
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
Returns
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
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
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
Returns
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
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
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
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
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
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
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
Returns
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
operator !=(Font, Font)
Returns whether two font descriptions differ.
public static bool operator !=(Font left, Font right)