API Reference
FontRegistry
Font faces an application registers once from files, bytes, or streams and then names by family everywhere raster text is drawn: chart, grid, topology, and visual block themes, FontSpec.FromFamily text, VisualCanvas themes, and SVG font-family in SvgRasterizer.
Inheritance
- Object
- FontRegistry
Remarks
A registered family takes precedence over an installed family of the same name, and its faces are chosen by the same weight and slant matching; installed faces of that family are not mixed in. Registering a generic family name (sans-serif, serif, monospace) sets the face that stacks ending in that keyword fall back to, and a registered sans-serif is also the last resort on a host with no usable fonts, such as a bare Linux container. TrueType and CFF outlines and colour-only emoji faces are supported (.ttf, .otf, .ttc, .otc). All members are thread-safe.
Methods
public static Void Clear() #VoidRemoves every registered face, so families resolve to installed fonts again.
public static Void Register(String family, String path, Int32 weight = 400, Boolean italic = false, Int32? collectionIndex = null) #VoidRegisters one face of a font file under a family name.
Parameters
- family System.String
- The family name stacks will use, such as Inter or sans-serif.
- path System.String
- The OpenType font or collection file (.ttf, .otf, .ttc, .otc).
- weight System.Int32 = 400
- The CSS weight of this face, 1 through 1000.
- italic System.Boolean = false
- True when this face is the italic of the family.
- collectionIndex System.Int32? = null
- The face within a .ttc or .otc collection; the first usable text or colour face when omitted.
Exceptions
ArgumentException– The family is empty or the file is not a readable OpenType text or colour font.
public static Void Register(String family, Byte[] data, Int32 weight = 400, Boolean italic = false, Int32? collectionIndex = null) #VoidRegisters one OpenType face from bytes under a family name, without filesystem access.
Parameters
- family System.String
- The family name used by font stacks, including generic names such as sans-serif.
- data System.Byte[]
- The complete TrueType, CFF, or OpenType collection data. Registration retains its own copy.
- weight System.Int32 = 400
- The CSS weight of this face, 1 through 1000.
- italic System.Boolean = false
- True when this face is the italic of the family.
- collectionIndex System.Int32? = null
- The collection face index; the first usable text or colour face when omitted.
Exceptions
ArgumentNullException– data is null.ArgumentException– The family is empty or the data is not a readable OpenType text or colour font.ArgumentOutOfRangeException– The weight is outside 1 through 1000.
public static Void Register(String family, Stream stream, Int32 weight = 400, Boolean italic = false, Int32? collectionIndex = null) #VoidRegisters one OpenType face from a readable stream, without filesystem access.
Parameters
- family System.String
- The family name used by font stacks, including generic names such as sans-serif.
- stream System.IO.Stream
- A readable stream containing a complete font from its current position to its end. It need not support seeking.
- weight System.Int32 = 400
- The CSS weight of this face, 1 through 1000.
- italic System.Boolean = false
- True when this face is the italic of the family.
- collectionIndex System.Int32? = null
- The collection face index; the first usable text or colour face when omitted.
Exceptions
ArgumentNullException– stream is null.ArgumentException– The family is empty, the stream is unreadable, or its remaining data is not a readable OpenType text or colour font.ArgumentOutOfRangeException– The weight is outside 1 through 1000.IOException– Reading the stream fails.
public static Int32 RegisterDirectory(String directory) #Int32Registers every readable .ttf, .otf, .ttc, and .otc face in a folder and its subfolders under their own family names.
Parameters
- directory System.String
Returns
The number of faces registered; files that are not readable OpenType text fonts are skipped.
public static Int32 RegisterFile(String path) #Int32Registers every face of a font file under the family, weight, and slant the file itself declares.
Parameters
- path System.String
Returns
The number of faces registered.
Exceptions
ArgumentException– The file declares no readable OpenType face.
Inherited Methods
public virtual Boolean Equals(Object? obj) #BooleanParameters
- obj Object?
Properties
public static IReadOnlyCollection<String> Families { get; } #Gets the registered family names.