თვისება textBaseline
თვისება textBaseline ადგენს ტექსტის ვერტიკალურ
სწორებას, რომელიც დახატულია
მეთოდი fillText-ის
ან მეთოდი strokeText-ის საშუალებით.
იღებს ერთ-ერთ შესაძლო მნიშვნელობას: top,
hanging, middle, alphabetic (ნაგულისხმევად),
ideographic, bottom (მნიშვნელობების გასაგებად
იხილეთ www.w3schools.com/tags/canvas_textbaseline.asp).
სინტაქსი
კონტექსტი.textBaseline = მნიშვნელობა;
მაგალითი
მოდით, ტექსტს მივანიჭოთ ვერტიკალური სწორება ზედა ხაზის მიმართ:
<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);
:
მაგალითი
ახლა კი მოდით, ტექსტს მივანიჭოთ ვერტიკალური სწორება ქვედა ხაზის მიმართ:
<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);
: