Canvas text draws in fallback font before custom web font loads
A developer found that the first fillText call on a canvas draws with the fallback system font even when a custom web font is declared with @font-face. Tests across Chromium, Chrome, Firefox and WebKit showed no errors, and the font request is only sent when the draw happens, so the text ignores the font still in transit. Redraws after 50 ms or more used the correct font, with the delay depending on network timing. A control test confirmed the font was not requested before the first draw, meaning canvas does not wait for it. The reported fix is to await document.fonts.load() with the font string and text before drawing, which worked in all four browsers.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in