Struct Font
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
NFloatThe 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
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
FontFamily
The primary font family name. No fallback fonts are supported.
public ReadOnlySpan<string> FontFamily
Field Value
FontSize
The font size in user-space units.
public NFloat FontSize
Field Value
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
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
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
Italic
public static readonly FontStyle Italic
Field Value
Light
public static readonly FontWeight Light
Field Value
LineHeight
The line height in user-space units. Controls vertical spacing between lines.
public NFloat LineHeight
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
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
floatThe 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.