Returns the loose width of a text string based on the current font.
The fontWidth()
function measures the width of the provided text string using the font's default measurement (i.e., the width property from the text metrics returned by the browser). Unlike textWidth()
, which calculates the tight pixel boundaries of the text glyphs, fontWidth()
uses the font's intrinsic spacing, which may include additional space for character spacing and kerning. This makes it useful for scenarios where an approximate width is sufficient for layout and positioning.
Examples
Syntax
fontWidth(theText)
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.