CanvasContext.setTextAlign

Align is a property of the Canvas 2D API that describes the alignment of text when it is drawn. The alignment is based on the x value of CanvasRenderingContext2D.FillText method. If textAlign="center", the text will be drawn at 'x-50%*width'.

Parameters

It is Object type.

PropertyTypeDescription
textAlignStringleft, right, center, start, end.

Sample Code

copy
const ctx = my.createCanvasContext('awesomeCanvas');
ctx.setStrokeStyle('red')
ctx.moveTo(150, 20)
ctx.lineTo(150, 170)
ctx.stroke()

ctx.setFontSize(15)
ctx.setTextAlign('left')
ctx.fillText('textAlign=left', 150, 60)

ctx.setTextAlign('center')
ctx.fillText('textAlign=center', 150, 80)

ctx.setTextAlign('right')
ctx.fillText('textAlign=right', 150, 100)

ctx.draw()