For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /api/angular-lynx/fonts.md.

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

src/app/headline.ts
import { Component, inject } from '@angular/core';
import { LYNX_ELEMENTS, LynxFont } from '@blotch/angular-lynx';

@Component({
  selector: 'app-headline',
  imports: [LYNX_ELEMENTS],
  template: `<text style="font-family: Brand">Welcome</text>`,
})
export class Headline {
  readonly #fonts = inject(LynxFont);

  constructor() {
    this.#fonts
      .addFont({
        fontFamily: 'Brand',
        src: 'url("https://example.com/brand.ttf")',
      })
      .catch(() => {
        // Not available on this thread, or the download failed.
      });
  }
}

API

LynxFont

@Injectable({ providedIn: 'root' })
class LynxFont {}

A registry of the fonts you add at runtime.

Lynx adds fonts only on the background thread. Your app runs on the main thread, so each call is sent there for you, and the signals below update when it's done. See Threads.

LynxFont.addFont()

addFont(config: LynxFontFaceConfig): Promise<void>;

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

readonly fonts: Signal<ReadonlyMap<string, LynxFontEntry>>;

Every family you've added, keyed by family name.

LynxFont.loadedFamilies

readonly loadedFamilies: Signal<ReadonlySet<string>>;

The names of the families that have loaded.

LynxFont.isLoaded()

isLoaded(fontFamily: string): boolean;

Returns true when the family has loaded. It reads fonts, so it's reactive in templates and computed().

LynxFont.getStatus()

getStatus(fontFamily: string): LynxFontStatus;

Returns the family's status, or 'idle' when you haven't added it.

Types

LynxFontFaceConfig

type LynxFontFaceConfig = {
  fontFamily: string;
  src: string;
};
FieldDescription
fontFamilyThe name to use in CSS font-family.
srcWhere to load the font from, passed to Lynx as a font face src. Lynx's own docs use url("…").

Android accepts TTF, OTF and TTC files. iOS accepts TTF, OTF, WOFF and WOFF2.

LynxFontStatus

type LynxFontStatus = 'idle' | 'loading' | 'loaded' | 'error';

LynxFontEntry

type LynxFontEntry = {
  fontFamily: string;
  src: string;
  status: LynxFontStatus;
  error?: Error;
};

error is set when status is 'error'.