# 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…

 Class  

`ChartForgeX.Typography`

**Namespace**

`ChartForgeX.Typography`

**Assembly**

`ChartForgeX`

**Source**

[FontRegistry.cs:43](https://github.com/EvotecIT/ChartForgeX/blob/main/ChartForgeX/Typography/FontRegistry.cs#L43)

**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](/api/chartforgex-typography-fontspec/) 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.

 Filter members   

    Show inherited   

 

## Methods

 `public static void Clear()` [#](#method-clear) 

[FontRegistry.cs:128](https://github.com/EvotecIT/ChartForgeX/blob/main/ChartForgeX/Typography/FontRegistry.cs#L128)

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)` [#](#method-register-string-string-int32-boolean-nullable-system-int32) 

[FontRegistry.cs:43](https://github.com/EvotecIT/ChartForgeX/blob/main/ChartForgeX/Typography/FontRegistry.cs#L43)

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)` [#](#method-register-string-byte-int32-boolean-nullable-system-int32) 

[FontRegistry.cs:62](https://github.com/EvotecIT/ChartForgeX/blob/main/ChartForgeX/Typography/FontRegistry.cs#L62)

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)` [#](#method-register-string-io-stream-int32-boolean-nullable-system-int32) 

[FontRegistry.cs:79](https://github.com/EvotecIT/ChartForgeX/blob/main/ChartForgeX/Typography/FontRegistry.cs#L79)

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)` [#](#method-registerdirectory-string) 

[FontRegistry.cs:113](https://github.com/EvotecIT/ChartForgeX/blob/main/ChartForgeX/Typography/FontRegistry.cs#L113)

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)` [#](#method-registerfile-string) 

[FontRegistry.cs:102](https://github.com/EvotecIT/ChartForgeX/blob/main/ChartForgeX/Typography/FontRegistry.cs#L102)

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.

## Inherited Methods

 `public virtual bool Equals(object? obj)` [#](#method-equals-object) 

Inherited from object

Parameters

**obj object? required**

Returns

 `bool` 

 `public virtual int GetHashCode()` [#](#method-gethashcode) 

Inherited from object

Returns

 `int` 

 `public Type GetType()` [#](#method-gettype) 

Inherited from object

Returns

 `Type` 

 `public virtual string? ToString()` [#](#method-tostring) 

Inherited from object

Returns

 `string?` 

## Properties

 `public static IReadOnlyCollection<string> Families { get; }` [#](#property-families) 

[FontRegistry.cs:28](https://github.com/EvotecIT/ChartForgeX/blob/main/ChartForgeX/Typography/FontRegistry.cs#L28)

Gets the registered family names.

<!-- PowerForge markdown artifact sha256:5AE5B4D23E93EA52AD2FEECBE61E18AB852FC47D0E59FF18633FFC238EB39154 -->
