Veturia textBaseline

Veturia textBaseline vendos rreshtimin vertikal të tekstit, të vizatuar duke përdorur metodën fillText ose metodën strokeText. Pranon një nga vlerat e mundshme: top, hanging, middle, alphabetic (si parazgjedhje), ideographic, bottom (për të kuptuar vlerat shiko www.w3schools.com/tags/canvas_textbaseline.asp).

Sintaksa

javascriptkonteksti.textBaseline = vlera;

Shembull

Le t'i caktojmë tekstit rreshtimin vertikal sipas vijës së sipërme:

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

Результат:

Shembull

Tani le t'i caktojmë tekstit rreshtimin vertikal sipas vijës së poshtme:

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

Результат:

Shihni gjithashtu

  • veturia textAlign,
    e cila rreshton tekstin horizontalisht
  • veturia font,
    e cila cakton madhësinë dhe llojin e shkronjave