Ominaisuus textBaseline
Ominaisuus textBaseline asettaa pystysuuntaisen
tasauksen fillText-
tai strokeText-
metodilla piirretylle tekstille.
Se hyväksyy yhden mahdollisista arvoista: top,
hanging, middle, alphabetic (oletusarvo),
ideographic, bottom (arvojen ymmärtämiseksi
ks. www.w3schools.com/tags/canvas_textbaseline.asp).
Syntaksi
konteksti.textBaseline = arvo;
Esimerkki
Asetetaan tekstille pystysuuntainen tasaus ylälinjaan:
<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);
:
Esimerkki
Asetetaan nyt tekstille pystysuuntainen tasaus ala linjaan:
<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);
: