Has anyone had success importing a custom font for use in HTML5 canvas? I've been trying to do this by loading the font file on my computer, but all my attempts have failed so far. The canvas keeps showing the default font instead of the one I want to use. It seems like there might be a step or process that I'm missing.
Currently, I am attempting to load the font with CSS:
@font-face {
font-family: 'RifficFree-Bold';
src: local('RifficFree-Bold'), url(./fonts/RifficFree-Bold.ttf), format('truetype');
}
Then, I call the font in JavaScript like this:
function drawText(myText, ctx) {
ctx.font = "40px RifficFree-Bold";
ctx.fillStyle = "rgb(0, 0, 0, " + myText.fill + ")";
ctx.fillText(myText.text, myText.x, myText.y);
}
I can confirm that the program is recognizing the font because changing the font size value actually affects the displayed text. This leads me to believe that maybe the font file itself is not being loaded correctly. Any thoughts or suggestions?