Calculates the width of the given text string in pixels.
The textWidth()
function processes the provided text string to determine its tight bounding box based on the current text properties such as font, textSize, and textStyle. Internally, it splits the text into individual lines (if line breaks are present) and computes the bounding box for each line using the renderer’s measurement functions. The final width is determined as the maximum width among all these lines.
For example, if the text contains multiple lines due to wrapping or explicit line breaks, textWidth() will return the width of the longest line.
Examples
Syntax
textWidth(text)
Parameters
Returns
Related References
textToContours
Returns an array of arrays of points outlining a string of text written using the font.
textToModel
Converts text into a 3D model that can be rendered in WebGL mode.
textToPaths
Returns a flat array of path commands that describe the outlines of a string of text.
textToPoints
Returns an array of points outlining a string of text written using the font.