FontLoader Class
Reads a font file into memory, within the limits of an environment, and creates its faces.
public static class FontLoaderRemarks
The whole file is read: the tables of a font are a graph of offsets, and the font keeps its bytes to read them in place. The bytes read are bounded by FontResourceLimits.MaxEncodedBytes, and the bytes the font keeps by FontResourceLimits.MaxFontBytes, and the faces of a collection by FontResourceLimits.MaxCollectionFaces.
A PostScript Type 1 font (a PFB or a PFA file) is converted to an OpenType font with CFF outlines when it is loaded: FontData.Bytes are the bytes of that font. FontLoader.LoadType1 adds the metrics of its AFM file.
Methods
| Name | Description |
|---|---|
| Load(Stream, FontEnvironment, bool) | Reads the faces of a font file from a stream. |
| Load(ReadOnlySpan<byte>, FontEnvironment, bool) | |
| LoadAsync(Stream, FontEnvironment, bool, CancellationToken) | Reads the faces of a font file from a stream, asynchronously. |
| LoadType1(ReadOnlySpan<byte>, AfmFontMetrics?, FontEnvironment) | Reads a PostScript Type 1 font (a PFB or a PFA file) and the metrics of its AFM file. |
Load overloads
Load(Stream, FontEnvironment, bool)
FontLoader.csReads the faces of a font file from a stream.
public static FontFace[] Load(Stream stream, FontEnvironment environment, bool useEmbeddedBitmaps = false)Parameters
streamStream- The stream of the font file, read to its end.
environmentFontEnvironment- The limits and the storage of the font code.
useEmbeddedBitmapsbool- Whether the bitmaps without colors of the font replace its outlines at the sizes they are made for.
Returns
FontFace[] The faces of the file: one for a font, one per font of a collection.
Load(ReadOnlySpan<byte>, FontEnvironment, bool)
FontLoader.cspublic static FontFace[] Load(ReadOnlySpan<byte> data, FontEnvironment environment, bool useEmbeddedBitmaps = false)Parameters
dataReadOnlySpan<byte>- The bytes of the font file.
environmentFontEnvironment- The limits and the storage of the font code.
useEmbeddedBitmapsbool- Whether the bitmaps without colors of the font replace its outlines at the sizes they are made for.
Returns
FontFace[]
LoadAsync(Stream, FontEnvironment, bool, CancellationToken)
FontLoader.csReads the faces of a font file from a stream, asynchronously.
net10.0
public static Task<FontFace[]> LoadAsync(Stream stream, FontEnvironment environment, bool useEmbeddedBitmaps, CancellationToken cancellationToken)net11.0
public static Task<FontFace[]> LoadAsync(Stream stream, FontEnvironment environment, bool useEmbeddedBitmaps, CancellationToken cancellationToken)Parameters
streamStream- The stream of the font file, read to its end.
environmentFontEnvironment- The limits and the storage of the font code.
useEmbeddedBitmapsbool- Whether the bitmaps without colors of the font replace its outlines at the sizes they are made for.
cancellationTokenCancellationToken- The token to monitor for cancellation requests.
Returns
Task<FontFace[]> The faces of the file: one for a font, one per font of a collection.
LoadType1(ReadOnlySpan<byte>, AfmFontMetrics?, FontEnvironment)
FontLoader.csReads a PostScript Type 1 font (a PFB or a PFA file) and the metrics of its AFM file.
public static FontFace LoadType1(ReadOnlySpan<byte> data, AfmFontMetrics? metrics, FontEnvironment environment)Parameters
dataReadOnlySpan<byte>- The bytes of the PFB or PFA file.
metricsAfmFontMetrics?- The metrics of the font, read from its AFM file, or
null: their kerning pairs become the kerning of the font, and their ascender, descender, cap height and x-height replace the values computed from the font program. The advance widths are always the ones of the font program. environmentFontEnvironment- The limits and the storage of the font code.
Returns
FontFace The face of the font.
Exceptions
UnknownFontFormatException- The data is not a PFB or a PFA file.
InvalidFontException- The font program is malformed.
UnsupportedFontFeatureException- The font is a multiple master, CID-keyed or stroked font.
FontResourceLimitException- The font exceeds a limit of the environment.