Guides/3 min

Load the font before fillText

Canvas will happily paint fallback glyphs and never tell you.

DOM text can restyle when a webfont finishes loading. Canvas cannot. fillText rasterizes whatever face is available at that instant. If Fraunces is still in flight, you get Times or Arial burned into the PNG. There is no FOUC — there is a wrong file.

FontFace, then draw

const face = new FontFace('Fraunces', 'url(/fraunces.woff2)');
await face.load();
document.fonts.add(face);
await document.fonts.load('500 72px "Fraunces"');
ctx.font = '500 72px "Fraunces"';
ctx.fillText('CanvasFont', x, y);

Google Fonts CSS works too, but you must still await document.fonts.load(...) after the stylesheet is in the document. document.fonts.ready waits for everything currently requested, which is usually enough in a studio, and too broad in a game loop.

Custom uploads

A local TTF/OTF/WOFF can be passed straight into new FontFace(name, arrayBuffer). That does not taint the canvas, so PNG export still works. CanvasFont keeps uploads in memory for the session — they are not written to a server.