SystemFontCollection Class
The fonts installed on the machine, or the fonts of chosen directories: an index of their faces by family and by name, read without loading the fonts.
public sealed class SystemFontCollectionRemarks
A collection is immutable and can be used by several threads at the same time. It is a snapshot of the files when it is created: a font installed or removed later is not seen. Creating it reads the names and the styles of the faces, not their characters: SystemFontDescriptor.Covers reads them when they are first asked for, and the collection keeps them within a bounded amount of memory.
The installed fonts are found in the font directories of the operating system:
- Windows: the fonts directory of Windows, the fonts installed for the current user, and the files the registry lists.
- macOS: the
Library/Fontsdirectories of the user, of the computer, of the network and of the system, and the fonts the system downloads on demand. - Linux and the other systems: the directories of the configuration of fontconfig, and the font directories of the XDG Base Directory Specification.
Properties
| Name | Description |
|---|---|
| Default | Gets the fonts installed on the machine, scanned when the property is first read. |
| Fonts | Gets the faces, ordered by family, then by file, then by index in the file. |
Default
SystemFontCollection.csGets the fonts installed on the machine, scanned when the property is first read.
public static SystemFontCollection Default { get; }Property value
Remarks
The scan reads the directories of the fonts of the operating system once per process; a font installed later is not seen.
Gets the faces, ordered by family, then by file, then by index in the file.
public IReadOnlyList<SystemFontDescriptor> Fonts { get; }Property value
Methods
| Name | Description |
|---|---|
| Create(IEnumerable<string>) | Creates the collection of the fonts of directories and of font files. |
| FindByName(string) | Finds a face by its full name or its PostScript name, as the local() function of CSS does. |
| GetFamily(string) | Gets the faces of a family. |
| Match(string, int, bool) | Finds the face of a family that is the closest to a style, with the font matching of CSS (CSS Fonts Module Level 4, §5.2): the normal width first, then the style, then the weight. |
Create(IEnumerable<string>)
SystemFontCollection.csCreates the collection of the fonts of directories and of font files.
public static SystemFontCollection Create(IEnumerable<string> paths)Parameters
pathsIEnumerable<string>- The directories, whose subdirectories are scanned too, and the font files. A path that does not exist is ignored.
Returns
SystemFontCollection The faces of the .ttf, .otf, .ttc, .otc, .woff and .woff2 files the font code loads; the other files are ignored.
Exceptions
ArgumentNullExceptionpathsisnull.
FindByName(string)
SystemFontCollection.csFinds a face by its full name or its PostScript name, as the local() function of CSS does.
public SystemFontDescriptor? FindByName(string name)Parameters
namestring- The full name or the PostScript name, compared without case.
Returns
SystemFontDescriptor? The first face of SystemFontCollection.Fonts with the name, or null.
Exceptions
ArgumentNullExceptionnameisnull.
GetFamily(string)
SystemFontCollection.csGets the faces of a family.
public IReadOnlyList<SystemFontDescriptor> GetFamily(string familyName)Parameters
familyNamestring- A typographic family name or a family name, in any language of the fonts, compared without case.
Returns
IReadOnlyList<SystemFontDescriptor> The faces of the family, in the order of SystemFontCollection.Fonts; empty when no font has the family.
Exceptions
ArgumentNullExceptionfamilyNameisnull.
Match(string, int, bool)
SystemFontCollection.csFinds the face of a family that is the closest to a style, with the font matching of CSS (CSS Fonts Module Level 4, §5.2): the normal width first, then the style, then the weight.
public SystemFontDescriptor? Match(string familyName, int weight = 400, bool isItalic = false)Parameters
familyNamestring- A typographic family name or a family name, in any language of the fonts, compared without case.
weightint- The weight, from 1 to 1000: 400 is normal, 700 is bold.
isItalicbool- Whether an italic face is preferred; an oblique face, then an upright face, are used when the family has none.
Returns
SystemFontDescriptor? The face, or null when no font has the family.
Exceptions
ArgumentNullExceptionfamilyNameisnull.ArgumentOutOfRangeExceptionweightis not between 1 and 1000.
Remarks
A variable font matches the weights and the widths of its wght and wdth axes, and the italic of its ital axis. Selecting the instance of the variable font is left to the caller.