Skip to content
ChartForgeX
Class

FontRegistry

ChartForgeX.Typography

Namespace
ChartForgeX.Typography
Assembly
ChartForgeX
Modifiers
static

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() #

Removes every registered face, so families resolve to installed fonts again.

Register 3 overloads
public static void Register(string family, string path, int weight = 400, bool italic = false, int? collectionIndex = null) #

Registers one face of a font file under a family name.

Parameters

family string required
The family name stacks will use, such as Inter or sans-serif.
path string required
The OpenType font or collection file (.ttf, .otf, .ttc, .otc).
weight int = 400 optional
The CSS weight of this face, 1 through 1000.
italic bool = false optional
True when this face is the italic of the family.
collectionIndex int? = null optional
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, int weight = 400, bool italic = false, int? collectionIndex = null) #

Registers one OpenType face from bytes under a family name, without filesystem access.

Parameters

family string required
The family name used by font stacks, including generic names such as sans-serif.
data byte[] required
The complete TrueType, CFF, or OpenType collection data. Registration retains its own copy.
weight int = 400 optional
The CSS weight of this face, 1 through 1000.
italic bool = false optional
True when this face is the italic of the family.
collectionIndex int? = null optional
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, int weight = 400, bool italic = false, int? collectionIndex = null) #

Registers one OpenType face from a readable stream, without filesystem access.

Parameters

family string required
The family name used by font stacks, including generic names such as sans-serif.
stream System.IO.Stream required
A readable stream containing a complete font from its current position to its end. It need not support seeking.
weight int = 400 optional
The CSS weight of this face, 1 through 1000.
italic bool = false optional
True when this face is the italic of the family.
collectionIndex int? = null optional
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 int RegisterDirectory(string directory) #

Registers every readable .ttf, .otf, .ttc, and .otc face in a folder and its subfolders under their own family names.

Parameters

directory string required

Returns

int The number of faces registered; files that are not readable OpenType text fonts are skipped.
public static int RegisterFile(string path) #

Registers every face of a font file under the family, weight, and slant the file itself declares.

Parameters

path string required

Returns

int The number of faces registered.

Exceptions

  • ArgumentException – The file declares no readable OpenType face.

Properties

public static IReadOnlyCollection<string> Families { get; } #

Gets the registered family names.