LynxFont
Load a font at runtime and track its loading state with signals. import { LynxFont, type LynxFontFaceConfig, type LynxFontStatus, type LynxFontEntry } from '@blotch/angular-lynx';
For fonts you know at build time, use CSS @font-face instead. See Custom fonts.
Usage
API
LynxFont
A registry of the fonts you add at runtime.
Lynx adds fonts only from the background thread. On the main thread, which runs your event handlers and draws the UI, addFont() rejects and the signals below don't change. A constructor runs on both threads, so the call in Usage reaches Lynx from the background copy. See Threads.
LynxFont.addFont()
Registers a font family with Lynx and resolves when it has loaded.
- Already loaded: resolves at once.
- Already loading: returns the same promise, so Lynx loads it only once.
- Failed: rejects and sets the family's status to
'error'. Calling again retries. - Outside Lynx: rejects, such as in unit tests.
LynxFont.fonts
Every family you've added, keyed by family name.
LynxFont.loadedFamilies
The names of the families that have loaded.
LynxFont.isLoaded()
Returns true when the family has loaded. It reads fonts, so it's reactive in templates and computed().
LynxFont.getStatus()
Returns the family's status, or 'idle' when you haven't added it.
Types
LynxFontFaceConfig
Android accepts TTF, OTF and TTC files. iOS accepts TTF, OTF, WOFF and WOFF2.
LynxFontStatus
LynxFontEntry
error is set when status is 'error'.
Related
- Custom fonts:
@font-faceand runtime loading. - Text measurement: measuring ignores custom fonts.
- Threads
