Computes a generic (non-tight) bounding box for a block of text.
The fontBounds() function calculates the bounding box for the text based on the font's intrinsic metrics (such as fontBoundingBoxAscent and fontBoundingBoxDescent). Unlike textBounds(), which measures the exact pixel boundaries of the rendered text, fontBounds() provides a looser measurement derived from the font’s default spacing. This measurement is useful for layout purposes where a consistent approximation of the text's dimensions is desired.
Examples
Syntax
fontBounds(str, x, y, [width], [height])
Parameters
Returns
x, y, w, and h representing the loose bounding box of the text based on the font's intrinsic metrics.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.