Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program API drawing measureText


May 19, 2021 WeChat Mini Program Development Document


Table of contents


canvasContext.measureText


Base library 1.9.90 starts to support, and low versions need to be compatible

Defined

Measure text size information and currently only return text width. Synchronize the interface.

Parameters

Parameters Type Description
text String The text to measure

Return

Returns the TextMetrics object, structured as follows:

Parameters Type Description
width Number The width of the text

Example

const ctx = wx.createCanvasContext('myCanvas')
ctx.font = 'italic bold 20px cursive'
const metrics = ctx.measureText('Hello World')
console.log(metrics.width)