Class FontLoadOptions
How a font file is read: leniently with diagnostics (the default), or strictly.
public sealed record FontLoadOptions : IEquatable<FontLoadOptions>
- Inheritance
-
FontLoadOptions
- Implements
- Inherited Members
Examples
// One face from a file; a collection takes an index. The bytes are read once and every table is parsed when first needed.
Typeface face = Typeface.FromFile(FontFile);
Console.WriteLine($"{face.FamilyName} {face.SubfamilyName}, {face.GlyphCount} glyphs, {face.UnitsPerEm} units per em");
// What a file holds, from its header alone.
FontProbe probe = FontLoader.Probe(File.ReadAllBytes(FontFile));
Console.WriteLine($"{probe.Kind}, {probe.FaceCount} face(s), {probe.Outlines} outlines");
// Damaged fonts load leniently with diagnostics; Strict throws instead.
var seen = new List<EgamiDiagnostic>();
var options = new FontLoadOptions { Context = EgamiContext.Default with { Diagnostics = seen.Add } };
Typeface lenient = Typeface.FromMemory(File.ReadAllBytes(FontFile), 0, options);
Remarks
Lenient loading needs only the tables an operation uses: glyph data ('glyf' and 'loca', or CFF) to load at all, and nothing
else. A missing or damaged name, OS/2, hhea, hmtx, post or cmap table gets a documented default and a Warning diagnostic with the
id Font.MissingTable or Font.BadTable; a glyph that cannot be read draws empty with Font.BadGlyph.
Strict turns the first such problem into a CorruptDataException.
Properties
Context
Gets the context whose diagnostics receive repairs and whose MaxTotalBytes caps the file size, or null for Default at the time of each use.
public EgamiContext? Context { get; init; }
Property Value
Default
Gets the default options: lenient, in Default.
public static FontLoadOptions Default { get; }
Property Value
Strict
Gets whether any damage throws CorruptDataException instead of being repaired. Defaults to false.
public bool Strict { get; init; }