Metoda fillText
Metoda fillText kreslí na canvas zadaný
text. Prvním parametrem přijímá samotný
text, druhým a třetím - souřadnice bodu,
ve kterém má být tento text umístěn.
Velikost a typ písma jsou nastaveny pomocí vlastnosti
font.
Syntaxe
kontext.strokeRect(text, x, y);
Příklad
Nakresleme na canvas text pomocí
fillText, nastavme mu velikost na 30px
a typ Arial:
<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
let canvas = document.querySelector('#canvas');
let ctx = canvas.getContext('2d');
ctx.font = '30px Arial';
ctx.fillText('Hello world', 30, 50);
:
Viz také
-
metoda
strokeText,
která kreslí na canvas obrys zadaného textu -
vlastnost
font,
která nastavuje velikost a typ písma