CanvasContext.measureText

Measure the size of the text, current only the witch is returned, and it is a synchronous interface

Parameters

It is Object type.

PropertyType

Required

Description
textStringYesThe text that needs to be measured.

Return Value

PropertyTypeDescription
widthNumberThe width of the text.

Sample Code

copy
//.js
const ctx = my.createCanvasContext('awesomeCanvas')
ctx.font = 'italic bold 50px cursive'
const { width } = ctx.measureText('hello world')
console.log(width)