FontStack Class
The fonts of a text, by order of preference: a primary font, then the fonts that are used for the characters the ones before them do not have.
public sealed class FontStackRemarks
Each character, with the marks and the selectors that follow it, is drawn with the first font of the stack that has all of it; a character no font has is drawn with the missing glyph of the primary font. The metrics of a line come from the fonts that are used on it.
The fonts installed on the machine are never used by themselves: a stack only has the fonts it is given, and draws the same text the same way on every machine. FontStack.WithInstalledFallback gives a stack that also looks for the characters its fonts do not have among the installed fonts.
A stack is immutable and can be used by several threads at the same time. A Font converts implicitly to a stack of one font.
Constructors
| Name | Description |
|---|---|
| FontStack(Font) | Initializes a stack of one font. |
| FontStack(Font, ReadOnlySpan<Font>) | Initializes a stack of fonts. |
FontStack overloads
FontStack(Font)
FontStack.csInitializes a stack of one font.
public FontStack(Font primary)FontStack(Font, ReadOnlySpan<Font>)
FontStack.csInitializes a stack of fonts.
public FontStack(Font primary, params scoped ReadOnlySpan<Font> fallbacks)Parameters
primaryFont- The font used first, whose missing glyph is drawn for a character no font has.
fallbacksReadOnlySpan<Font>- The fonts used, in order, for the characters the fonts before them do not have.
Exceptions
ArgumentNullExceptionprimaryor one offallbacksisnull.ArgumentException- There are more than 64 fonts.
Properties
| Name | Description |
|---|---|
| Fonts | Gets the fonts, by order of preference; the first one is FontStack.Primary. |
| HasInstalledFallback | Gets a value indicating whether the characters the fonts of the stack do not have are looked for among installed fonts. |
| Primary | Gets the font used first. |
Fonts
FontStack.csGets the fonts, by order of preference; the first one is FontStack.Primary.
public IReadOnlyList<Font> Fonts { get; }Property value
HasInstalledFallback
FontStack.csGets a value indicating whether the characters the fonts of the stack do not have are looked for among installed fonts.
public bool HasInstalledFallback { get; }Primary
FontStack.csMethods
| Name | Description |
|---|---|
| FromFont(Font) | Creates a stack of one font. |
| WithInstalledFallback(SystemFontCollection?, InstalledFontFallbackOptions?) | Creates a stack of the same fonts that, for a character none of them has, looks for a font among the installed fonts. |
FromFont(Font)
FontStack.csCreates a stack of one font.
Parameters
fontFont- The font.
Returns
FontStack A stack whose primary font is font.
Exceptions
ArgumentNullExceptionfontisnull.
WithInstalledFallback(SystemFontCollection?, InstalledFontFallbackOptions?)
FontStack.csCreates a stack of the same fonts that, for a character none of them has, looks for a font among the installed fonts.
public FontStack WithInstalledFallback(SystemFontCollection? fonts = null, InstalledFontFallbackOptions? options = null)Parameters
fontsSystemFontCollection?- The fonts to look in, or
nullforSystemFontCollection.Default, the fonts installed on the machine. optionsInstalledFontFallbackOptions?- The options, or
nullforInstalledFontFallbackOptions.Default.
Returns
FontStack A stack with the fonts of this one, then the installed fonts.
Remarks
The fonts of the stack are used first, as without fallback. A character, with the marks and the selectors that follow it, that none of them has is looked for among the installed fonts, in this order: the families of InstalledFontFallbackOptions.PreferredFamilies; for an emoji presented with colors (Unicode Technical Standard #51), the color emoji fonts (Segoe UI Emoji, Apple Color Emoji, Noto Color Emoji); the families the platforms usually use for the script of the character (and, for the Han ideographs, the language of the text), and the fonts of symbols; then every family that has the character, those whose closest face has the weight and the italic of the primary font first, by family name and by file. In a family, the face is the one closest to the style of the primary font, at the instance of that style when it is a variable font (Font.LoadInstalled). A character no font has is drawn with the missing glyph of the primary font.
The Han ideographs have different forms in Chinese, Japanese and Korean: their families are chosen by the language of the text (TextStyle.Language): Microsoft YaHei, PingFang SC or Noto Sans CJK SC for Simplified Chinese and a text without a language, Microsoft JhengHei, PingFang TC or Noto Sans CJK TC for Traditional Chinese, PingFang HK or Noto Sans CJK HK for Hong Kong, Yu Gothic, Hiragino Sans or Noto Sans CJK JP for Japanese, Malgun Gothic, Apple SD Gothic Neo or Noto Sans CJK KR for Korean, then those of Simplified Chinese. The fonts found are kept for each language. InstalledFontFallbackOptions.PreferredFamilies still come first, whatever the language.
The installed fonts differ from one machine to another, and so does a text drawn with this stack: use it when the text matters more than the exact pixels. The characters of a face are read from its file the first time the fallback needs them (SystemFontDescriptor.Covers); a file that cannot be loaded is skipped. The font found for a character is kept by the stack, which its layouts share: each font is loaded once, the same character always gets the same font, and the fonts it loaded live as long as the stack.
Operators
| Name | Description |
|---|---|
| implicit operator FontStack(Font) | Creates a stack of one font. |
implicit operator FontStack(Font)
FontStack.csCreates a stack of one font.