@mocanvas/editor · class
declare class FontManagerLoads the typefaces the canvas actually needs, and only those.
Shapes declare their faces through their ShapeUtil; the manager loads a
face the first time something asks for it, remembers the outcome, and never
requests the same face twice. Text measured before its face arrives would be
measured against a fallback, so anything that depends on final metrics waits
on loadRequiredFontsForCurrentPage first.
Loading happens in the editor's own document (see getContainerDocument), so
a canvas inside an iframe registers its faces in the realm that paints it.
Where there is no DOM (server rendering, node tests) every request resolves
immediately and the face is recorded as ready: nothing is painted there, and
callers should not have to branch on the environment.
Methods · 9
constructor(editor: Editor)dispose(): voidForget every recorded state. In-flight loads are abandoned, not cancelled.
getFontState(face: TLFontFace): TLFontLoadState | undefinedWhat happened to a face, or undefined if it was never requested.
getRequiredFontsForCurrentPage(): TLFontFace[]Every face needed by something on the page right now, deduplicated.
getShapeFontFaces(shape: UnknownShape): readonly TLFontFace[]The faces one shape needs, as declared by its ShapeUtil.
isFontLoaded(face: TLFontFace): booleanWhether a face is loaded and safe to measure against.
loadRequiredFontsForCurrentPage(limit?: number): Promise<void>Load everything the current page needs and resolve once it is all in. Await this before any measurement whose result is written back into a shape, otherwise the first paint sizes text against a fallback face.
limit is an escape hatch for pathological pages: a page needing more
distinct faces than that is left alone rather than issuing hundreds of
requests.
requestFont(face: TLFontFace): Promise<void>Ask for one face. Resolves when it is usable, or when it failed.
requestFonts(faces: readonly TLFontFace[]): Promise<void>Ask for several faces at once. Resolves when all of them have settled.
Mentioned here
mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.