Svojstvo textBaseline
Svojstvo textBaseline postavlja vertikalno
poravnanje teksta, nacrtanog pomoću
metode fillText
ili metode strokeText.
Prihvata jednu od mogućih vrednosti: top,
hanging, middle, alphabetic (podrazumevano),
ideographic, bottom (za razumevanje vrednosti
pogledajte www.w3schools.com/tags/canvas_textbaseline.asp).
Sintaksa
kontekst.textBaseline = vrednost;
Primer
Hajde da postavimo tekstu vertikalno poravnanje po gornjoj liniji:
<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
ctx.strokeStyle = 'red';
ctx.moveTo(0, 100);
ctx.lineTo(400, 100);
ctx.stroke();
ctx.font="14px Arial";
ctx.textBaseline = 'top';
ctx.fillText('text', 80, 100);
:
Primer
A sada hajde da postavimo tekstu vertikalno poravnanje po donjoj liniji:
<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
ctx.strokeStyle = 'red';
ctx.moveTo(0, 100);
ctx.lineTo(400, 100);
ctx.stroke();
ctx.font="14px Arial";
ctx.textBaseline="bottom";
ctx.fillText('text', 80, 100);
: