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
theText
String: The text string to measure.
Returns
Number: The loose width of the text in pixels.
Notice any errors or typos? Please let us know. Please feel free to edit src/type/textCore.js and open a pull request!