FontLoader Class

Reads a font file into memory, within the limits of an environment, and creates its faces.

public static class FontLoader

Remarks

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

NameDescription
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.cs

Reads the faces of a font file from a stream.

public static FontFace[] Load(Stream stream, FontEnvironment environment, bool useEmbeddedBitmaps = false)
Parameters
stream Stream
The stream of the font file, read to its end.
environment FontEnvironment
The limits and the storage of the font code.
useEmbeddedBitmaps bool
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.cs
public static FontFace[] Load(ReadOnlySpan<byte> data, FontEnvironment environment, bool useEmbeddedBitmaps = false)
Parameters
data ReadOnlySpan<byte>
The bytes of the font file.
environment FontEnvironment
The limits and the storage of the font code.
useEmbeddedBitmaps bool
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.cs

Reads 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

stream Stream
The stream of the font file, read to its end.
environment FontEnvironment
The limits and the storage of the font code.
useEmbeddedBitmaps bool
Whether the bitmaps without colors of the font replace its outlines at the sizes they are made for.
cancellationToken CancellationToken
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.cs

Reads 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

data ReadOnlySpan<byte>
The bytes of the PFB or PFA file.
metrics AfmFontMetrics?
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.
environment FontEnvironment
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.