FontCollection Class
The faces of a font file: every face of a font collection (.ttc), or the single face of another font file.
public sealed class FontCollection : IEnumerable<Font>, IReadOnlyCollection<Font>, IReadOnlyList<Font>, IEnumerableRemarks
A collection is immutable and can be used by several threads at the same time. Its faces share the bytes of the file, which stay in memory as long as one of the fonts is referenced.
Properties
| Name | Description |
|---|---|
| Count | Gets the number of faces. |
Count
FontCollection.csIndexers
| Name | Description |
|---|---|
| this[int] | Gets a face. |
this[int]
FontCollection.csGets a face.
Parameters
indexint- The index of the face, in the order of the file.
Property value
Exceptions
ArgumentOutOfRangeExceptionindexis negative, or is not less thanFontCollection.Count.
Methods
| Name | Description |
|---|---|
| GetEnumerator() | Returns an enumerator of the faces, in the order of the file. |
| Load(Stream, FontLoadOptions?) | Loads every face of a font file from a stream, read from its current position to its end. |
| Load(ReadOnlySpan<byte>, FontLoadOptions?) | Loads every face of a font file from its bytes. |
| Load(string, FontLoadOptions?) | Loads every face of a font file. |
| LoadAsync(Stream, FontLoadOptions?, CancellationToken) | Asynchronously loads every face of a font file from a stream, read from its current position to its end. |
| LoadAsync(string, FontLoadOptions?, CancellationToken) | Asynchronously loads every face of a font file, using asynchronous file I/O. |
| System.Collections.IEnumerable.GetEnumerator() | Returns an enumerator that iterates through a collection. |
GetEnumerator()
FontCollection.csReturns an enumerator of the faces, in the order of the file.
public IEnumerator<Font> GetEnumerator()Returns
IEnumerator<Font> The enumerator.
Load overloads
Load(Stream, FontLoadOptions?)
FontCollection.csLoads every face of a font file from a stream, read from its current position to its end.
public static FontCollection Load(Stream stream, FontLoadOptions? options = null)Parameters
streamStream- The readable source stream. It is left open and is not retained after the method returns.
optionsFontLoadOptions?- The options, or
nullforFontLoadOptions.Default.
Returns
FontCollection The faces of the file.
Exceptions
ArgumentNullExceptionstreamisnull.ArgumentExceptionstreamis not readable.UnknownImageFormatException- The data is not a font.
InvalidImageContentException- A font is malformed or truncated.
UnsupportedImageFeatureException- A font uses a feature that is not supported.
ImageResourceLimitException- A configured limit is exceeded.
IOException- An I/O error occurred.
Load(ReadOnlySpan<byte>, FontLoadOptions?)
FontCollection.csLoads every face of a font file from its bytes.
public static FontCollection Load(ReadOnlySpan<byte> data, FontLoadOptions? options = null)Parameters
dataReadOnlySpan<byte>- The bytes of the file. They are copied: the fonts do not refer to the span after the method returns.
optionsFontLoadOptions?- The options, or
nullforFontLoadOptions.Default.
Returns
FontCollection The faces of the file.
Exceptions
UnknownImageFormatException- The data is not a font.
InvalidImageContentException- A font is malformed or truncated.
UnsupportedImageFeatureException- A font uses a feature that is not supported.
ImageResourceLimitException- A configured limit is exceeded.
Load(string, FontLoadOptions?)
FontCollection.csLoads every face of a font file.
public static FontCollection Load(string path, FontLoadOptions? options = null)Parameters
pathstring- The path of the file. The file is closed before the method returns.
optionsFontLoadOptions?- The options, or
nullforFontLoadOptions.Default.
Returns
FontCollection The faces of the file.
Exceptions
ArgumentExceptionpathis empty.UnknownImageFormatException- The file is not a font.
InvalidImageContentException- A font is malformed or truncated.
UnsupportedImageFeatureException- A font uses a feature that is not supported.
ImageResourceLimitException- A configured limit is exceeded.
IOException- An I/O error occurred.
LoadAsync overloads
LoadAsync(Stream, FontLoadOptions?, CancellationToken)
FontCollection.csAsynchronously loads every face of a font file from a stream, read from its current position to its end.
public static Task<FontCollection> LoadAsync(Stream stream, FontLoadOptions? options = null, CancellationToken cancellationToken = default)Parameters
streamStream- The readable source stream. It is left open.
optionsFontLoadOptions?- The options, or
nullforFontLoadOptions.Default. cancellationTokenCancellationToken- The token to monitor for cancellation requests.
Returns
Task<FontCollection> The faces of the file.
Exceptions
ArgumentNullExceptionstreamisnull.ArgumentExceptionstreamis not readable.OperationCanceledException- The operation was canceled.
LoadAsync(string, FontLoadOptions?, CancellationToken)
FontCollection.csAsynchronously loads every face of a font file, using asynchronous file I/O.
public static Task<FontCollection> LoadAsync(string path, FontLoadOptions? options = null, CancellationToken cancellationToken = default)Parameters
pathstring- The path of the file.
optionsFontLoadOptions?- The options, or
nullforFontLoadOptions.Default. cancellationTokenCancellationToken- The token to monitor for cancellation requests.
Returns
Task<FontCollection> The faces of the file.
Exceptions
ArgumentExceptionpathis empty.OperationCanceledException- The operation was canceled.
System.Collections.IEnumerable.GetEnumerator()
FontCollection.csReturns an enumerator that iterates through a collection.
IEnumerator IEnumerable.GetEnumerator()Returns
IEnumerator An IEnumerator object that can be used to iterate through the collection.