Interface IFontSource
Obtains raw font bytes (TTF/OTF/WOFF) from a source such as a web font CDN.
public interface IFontSource
Remarks
KernSmith accepts raw font bytes from any source. File loading
(ReadAllBytes(string)) and system font enumeration
(ISystemFontProvider) are already trivial, so this abstraction exists
primarily for non-trivial sources — most notably web fonts, which require fetching
and parsing CSS @font-face responses. The interface is async because the
primary use case (network fetches) is inherently asynchronous; synchronous sources
can return FromResult<TResult>(TResult).
Methods
GetFontAsync(string, int, FontStyle, string, CancellationToken)
Gets font bytes by family name.
Task<byte[]> GetFontAsync(string family, int weight = 400, FontStyle style = FontStyle.Normal, string subset = "latin", CancellationToken cancellationToken = default)
Parameters
familystringFont family name (e.g., "Roboto").
weightintFont weight (100–900, where 400 is regular and 700 is bold).
styleFontStyleFont style (normal or italic).
subsetstringUnicode subset to request (e.g., "latin", "cyrillic", "greek").
cancellationTokenCancellationTokenToken to cancel the operation.
Returns
ListFamiliesAsync(CancellationToken)
Lists available font families from this source.
Task<IReadOnlyList<string>> ListFamiliesAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenToken to cancel the operation.
Returns
- Task<IReadOnlyList<string>>
The available font family names.