Computes the tight bounding box for a block of text.
The textBounds()
function calculates the precise pixel boundaries that enclose the rendered text based on the current text properties (such as font, textSize, textStyle, and alignment). If the text spans multiple lines (due to line breaks or wrapping), the function measures each line individually and then aggregates these measurements into a single bounding box. The resulting object contains the x and y coordinates along with the width (w) and height (h) of the text block.
Examples
Syntax
textBounds(str, x, y, [width], [height])
Parameters
Returns
x
, y
, w
, and h
that represent the tight bounding box of the rendered text.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.