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

javascriptkontext.strokeRect(text, x, y);

Příklad

Nakresleme na canvas text pomocí fillText, nastavme mu velikost na 30px a typ Arial:

html<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
javascriptlet 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