Table of Contents

Interface IFontSource

Namespace
KernSmith.Font
Assembly
KernSmith.dll

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

family string

Font family name (e.g., "Roboto").

weight int

Font weight (100–900, where 400 is regular and 700 is bold).

style FontStyle

Font style (normal or italic).

subset string

Unicode subset to request (e.g., "latin", "cyrillic", "greek").

cancellationToken CancellationToken

Token to cancel the operation.

Returns

Task<byte[]>

The raw font file bytes (TTF/OTF/WOFF).

ListFamiliesAsync(CancellationToken)

Lists available font families from this source.

Task<IReadOnlyList<string>> ListFamiliesAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Token to cancel the operation.

Returns

Task<IReadOnlyList<string>>

The available font family names.