Table of Contents

Class DefaultSystemFontProvider

Namespace
KernSmith.Font
Assembly
KernSmith.dll

Default implementation of ISystemFontProvider that scans platform-specific font directories and uses KernSmith.Font.TtfParser to extract font metadata.

public sealed class DefaultSystemFontProvider : ISystemFontProvider
Inheritance
DefaultSystemFontProvider
Implements
Inherited Members

Methods

GetInstalledFonts()

Returns a list of all installed fonts discovered on the system.

public IReadOnlyList<SystemFontInfo> GetInstalledFonts()

Returns

IReadOnlyList<SystemFontInfo>

LoadFont(string, string?)

Loads the raw font file bytes for the specified font family.

public FontLoadResult? LoadFont(string familyName, string? styleName = null)

Parameters

familyName string

The font family name to search for (case-insensitive).

styleName string

Optional style name to match (e.g., "Bold"). If null, prefers "Regular".

Returns

FontLoadResult

The font data and TTC face index, or null if no matching font was found.

Remarks

Resolves a family through four tiers, in order, each cheaper than the next fallback so the common case (a family already seen, or a well-known one) never pays for the expensive tiers at all:

  1. Cache / seed (TryGetValidCachedFont(string, out FontLoadResult), no-style requests only) — a hit against _resolvedFontCache from a prior call, a consumer-supplied hint (AddResolvedFontHint(string, string, int), exposed via HintFontLocation(string, string, int)), or a lazy one-shot attempt against KernSmith.Font.WellKnownFontSeeds's best-guess candidate paths (TryResolveFromSeed(string, out FontLoadResult)) the first time a family is requested. Every candidate — cached, hinted, or seeded — is validated identically via IsCacheEntryValidCore(SystemFontInfo, string, Func<string, byte[]>, out byte[]) before being trusted.
  2. Windows registry (TryLoadFontFromRegistry(string, string, out FontLoadResult, out bool, out SystemFontInfo)) — fast, Windows-only; no-op elsewhere. If the registry confirms the family exists but not the requested style, resolution stops here and returns null (no separate file for that style).
  3. Heuristic filename match (TryHeuristicFilenameMatch(string, string, List<string>, out FontLoadResult)) — narrows candidates by filename first (cheap directory enumeration, no parsing), then verifies with a real parse. A filename hint that fails to verify is a bounded, definitive miss (does not escalate); only a total absence of filename-narrowed candidates falls through to the next tier.
  4. Full scan (GetInstalledFonts()) — the correctness backstop: every installed font is enumerated and parsed. Always eventually finds a real, installed font regardless of whether the earlier tiers' guesses were right.

A successful no-style resolution from any of tiers 2-4 is written back into _resolvedFontCache via CacheResolvedFont(string, SystemFontInfo), so the next no-style request for that family is a pure tier-1 cache hit regardless of which tier originally resolved it.