meo-skia-canvas
    Preparing search index...

    Interface FontLibrary

    The process-wide font registry: what a draw can match by name, and how to add faces that are not installed on the system.

    Its state is global rather than per-canvas, so a family registered here is visible to every canvas, window and paragraph in the process.

    🧪 Not in the HTML Canvas standard.

    interface FontLibrary {
        families: readonly string[];
        family(name: string): FontFamily | undefined;
        has(familyName: string): boolean;
        reset(): void;
        use(familyName: string, fontPaths?: string | readonly string[]): Font[];
        use(
            familyName: string,
            fontData: ArrayBuffer | Buffer<ArrayBufferLike>,
        ): Font[];
        use(
            familyName: string,
            fontData: readonly (ArrayBuffer | Buffer<ArrayBufferLike>)[],
        ): Font[];
        use(fontPaths: readonly string[]): Font[];
        use(
            families: Record<string, readonly string[] | string>,
        ): Record<string, Font[]>;
    }
    Index
    families: readonly string[]

    Every family a draw can match, sorted and de-duplicated -- the platform's own plus anything FontLibrary.use has added.

    • The weights, widths and styles available under name, or undefined when nothing resolves under it.

      Parameters

      • name: string

      Returns FontFamily | undefined

    • Forget every face registered with FontLibrary.use and drop the cached font collections. System fonts are unaffected.

      Returns void

    • Register one or more font files, optionally under an alias of your own.

      Naming an alias files every face given under that family name, whatever the file itself declares, which is how a face is reached from ctx.font by a name of your choosing. Without one, each face keeps the family name it declares.

      Paths, Buffers and ArrayBuffers are all accepted, as is an object mapping several aliases to their files in one call. The return value describes the faces that were read -- an empty array means the file held no usable font.

      FontLibrary.use("Colorfont", "./fonts/Colorfont-Regular.ttf")
      FontLibrary.use(["./fonts/Inter-Regular.ttf", "./fonts/Inter-Bold.ttf"])
      FontLibrary.use({ Headline: "./fonts/Playfair.ttf" })

      Parameters

      • familyName: string
      • OptionalfontPaths: string | readonly string[]

      Returns Font[]

    • As above, from font data already in memory rather than a path.

      Parameters

      • familyName: string
      • fontData: ArrayBuffer | Buffer<ArrayBufferLike>

      Returns Font[]

    • As above, filing several in-memory faces under one alias -- the weights and styles of a single family, typically.

      Parameters

      • familyName: string
      • fontData: readonly (ArrayBuffer | Buffer<ArrayBufferLike>)[]

      Returns Font[]

    • As above, with no alias: each face keeps the family name its file declares.

      Parameters

      • fontPaths: readonly string[]

      Returns Font[]

    • As above, registering several aliases at once. The result maps each alias to the faces read for it, so a family that contributed nothing is visible as an empty array.

      Parameters

      • families: Record<string, readonly string[] | string>

      Returns Record<string, Font[]>