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);
: