SceneFontCollection Class

The fonts of a scene: the faces of one or more families. The layout measures each text with them (FontFaceTextMeasurer), and the renderers draw it with them (Scene.Fonts), so each text is measured and drawn with the same font.

public sealed class SceneFontCollection

Remarks

The family of a text is SceneFont.Family, or the family of the scene when it is null. It is a CSS font-family value: the first family of the list the collection has is used, and SceneFontCollection.DefaultFamily when it has none of them. Within the family, the face closest to the style of the text is used: the same slant first, then the nearest weight (SceneFont.Weight).

The characters the face of the text does not have are drawn with the other families of the collection, in the order they were added: each grapheme cluster uses the first face that has all its characters.

A collection is immutable and can be used by several threads at the same time.

Constructors

NameDescription
SceneFontCollection(IEnumerable<SceneFontFace>)Initializes a new instance of the SceneFontCollection class. The default family is the family of the first face.
SceneFontCollection(IEnumerable<SceneFontFace>, string?)Initializes a new instance of the SceneFontCollection class.

SceneFontCollection overloads

SceneFontCollection(IEnumerable<SceneFontFace>)

SceneFontCollection.cs

Initializes a new instance of the SceneFontCollection class. The default family is the family of the first face.

public SceneFontCollection(params IEnumerable<SceneFontFace> faces)
Parameters
faces IEnumerable<SceneFontFace>
The faces, in order of preference for the characters a family does not have.
Exceptions
ArgumentException
faces is empty or contains null.

SceneFontCollection(IEnumerable<SceneFontFace>, string?)

SceneFontCollection.cs

Initializes a new instance of the SceneFontCollection class.

public SceneFontCollection(IEnumerable<SceneFontFace> faces, string? defaultFamily)
Parameters
faces IEnumerable<SceneFontFace>
The faces, in order of preference for the characters a family does not have.
defaultFamily string?
The family of the texts that name no family of the collection, or null for the family of the first face.
Exceptions
ArgumentException
faces is empty or contains null, or no face is of defaultFamily.

Properties

NameDescription
DefaultFamilyGets the family of the texts that name no family of the collection.
FacesGets the faces, in the order they were added.
FamiliesGets the families of the faces, in the order they were added.
FontFamilyGets the families as a CSS font-family value: SceneFontCollection.DefaultFamily, then the other families, quoted when needed.

Gets the family of the texts that name no family of the collection.

public string DefaultFamily { get; }

Property value

string

Gets the faces, in the order they were added.

public IReadOnlyList<SceneFontFace> Faces { get; }

Gets the families of the faces, in the order they were added.

public IReadOnlyList<string> Families { get; }

Property value

IReadOnlyList<string>

Gets the families as a CSS font-family value: SceneFontCollection.DefaultFamily, then the other families, quoted when needed.

public string FontFamily { get; }

Property value

string

Remarks

The measurers that use the collection have this family (ITextMeasurer.FontFamily), so it is the family of their scenes.

Methods

NameDescription
ContainsFamily(string)Indicates whether the collection has a face of a family.
GetFace(SceneFont, string?)Gets the face that draws a text.
GetFaces(SceneFont, string?)Gets the faces that draw a text: the face of its family and style, then the faces of the other families, closest to the style, for the characters it does not have.
GetRuns(string, SceneFont, string?)Splits a text into the runs that one face draws: the characters the face of its family does not have are drawn with the faces of the other families.
Load(IEnumerable<string>)Loads the faces of font files into a collection. The default family is the family of the first face.

ContainsFamily(string)

SceneFontCollection.cs

Indicates whether the collection has a face of a family.

public bool ContainsFamily(string family)

Parameters

family string
The name of the family, compared ignoring the case of ASCII letters.

Returns

bool true when a face is of the family.

GetFace(SceneFont, string?)

SceneFontCollection.cs

Gets the face that draws a text.

public SceneFontFace GetFace(SceneFont font, string? defaultFamily = null)

Parameters

font SceneFont
The font of the text.
defaultFamily string?
The family of the text when SceneFont.Family is null, usually Scene.FontFamily, or null for SceneFontCollection.DefaultFamily.

Returns

SceneFontFace The face.

GetFaces(SceneFont, string?)

SceneFontCollection.cs

Gets the faces that draw a text: the face of its family and style, then the faces of the other families, closest to the style, for the characters it does not have.

public IReadOnlyList<SceneFontFace> GetFaces(SceneFont font, string? defaultFamily = null)

Parameters

font SceneFont
The font of the text.
defaultFamily string?
The family of the text when SceneFont.Family is null, usually Scene.FontFamily, or null for SceneFontCollection.DefaultFamily.

Returns

IReadOnlyList<SceneFontFace> The faces, by order of preference.

GetRuns(string, SceneFont, string?)

SceneFontCollection.cs

Splits a text into the runs that one face draws: the characters the face of its family does not have are drawn with the faces of the other families.

public IReadOnlyList<SceneFontRun> GetRuns(string text, SceneFont font, string? defaultFamily = null)

Parameters

text string
The text.
font SceneFont
The font of the text.
defaultFamily string?
The family of the text when SceneFont.Family is null, usually Scene.FontFamily, or null for SceneFontCollection.DefaultFamily.

Returns

IReadOnlyList<SceneFontRun> The runs, in the order of the text: none for an empty text.

Remarks

Each grapheme cluster uses the first face of SceneFontCollection.GetFaces that has all its characters, and the first face when none has them. The adjacent clusters of a face are one run.

Load(IEnumerable<string>)

SceneFontCollection.cs

Loads the faces of font files into a collection. The default family is the family of the first face.

public static SceneFontCollection Load(params IEnumerable<string> paths)

Parameters

paths IEnumerable<string>
The paths of the files.

Returns

SceneFontCollection The collection.

Exceptions

ArgumentException
paths is empty.
FontException
A file is not a font, or a font is malformed, uses a feature that is not supported, or exceeds a limit.
IOException
An I/O error occurred.